$(document).ready(function() {
    


/*  Home page - 
s, photos, news
------------------------------------------------------------------------ */

    $("#homePage .item a").click(function(){
        var flashvars = false;
        var params = {
          wmode: "transparent"
          };
        var attributes = false;
        swfobject.embedSWF( $(this).attr("href"), "sectionScreenObj" , "320", "265", "9.0.0","expressInstall.swf", flashvars, params, attributes);        
        return false;
    });

    $("#vidPage .item a").click(function(){
        var t = $(this).children("img").attr("alt");
        var flashvars = false;
        var params = {
          wmode: "transparent"
          };
        var attributes = false;
        swfobject.embedSWF( $(this).attr("href"), "sectionScreenObj" , "380", "289", "9.0.0","expressInstall.swf", flashvars, params, attributes);
        $("#nowPlaying h3").after('<h3>' + t + '</h3>').remove();
        return false;
    });

	$("#tourVidPage .item a").click(function(){
	var t = $(this).children("img").attr("alt");
	var flashvars = false;
	var params = {
	  wmode: "transparent"
	  };
	var attributes = false;
	swfobject.embedSWF( $(this).attr("href"), "sectionScreenObj" , "380", "289", "9.0.0","expressInstall.swf", flashvars, params, attributes);
	$("#nowPlaying h3").after('<h3>' + t + '</h3>').remove();
	return false;
});
/*  OLD CODE - DOESN'T WORK IN IE8
    $(".item a").click(function(){
        var ytHTML = $("#sectionScreen").html();
        $("#sectionScreen").html(ytHTML);
        var tubeURL = $(this).attr("href");
        $("#sectionScreen param:first").attr("movie", tubeURL);
        $("#sectionScreen embed").attr("src", tubeURL);
        return false;
    })
*/

    $(".scrollPane").jScrollPane({
        scrollbarWidth: 10,
        showArrows: false,
        dragMinHeight:30,
        dragMaxHeight:30
    });
    
/*  Photo Gallery
------------------------------------------------------------------------ */
    
    // Preload images
    $("#photoCarousel ul li a").each(function(){
        var preload = new Image();
        preload.src = this;
    });
    
    // Set main image when you click a thumbnail
    $("#photoCarousel ul li a").click(function(){
        var i = $(this).attr("title");
        $("#photoGallery img").attr("src", this);
         $("#photoCaption").html(i);
        return false;
    });
    
    // Scroll the thumbnails
    $("#photoCarousel").jCarouselLite({
        btnNext: "#nextPhoto",
        btnPrev: "#prevPhoto",
        scroll: 1,
        visible: 7,
        circular: false
    });
    
/*  Sittin' Artists videos
------------------------------------------------------------------------ */

    $(".sittin-vid").click(function(){
            var flashvars = false;
            var params = {
              wmode: "transparent"
              };
            var attributes = false;
            swfobject.embedSWF( $(this).attr("href"), "sectionVid" , "677", "407", "9.0.0","expressInstall.swf", flashvars, params, attributes);
            $("#sittin-popup").css({
                "top": $(window).scrollTop()+$(window).height()/2,
                "left": $(window).width()/2
            });
            $("#sittin-popup").fadeIn("fast");
            return false;
        });

    $(".sittinclose").click(function(){
        $("#sittin-popup").hide();
        $("#sectionVid").after('<div id="sectionVid"></div>').remove();
        return false;
    });


/*  Snazzify nav
------------------------------------------------------------------------ */

    $("#nav li").hover(
        function(){
            $("a",this).addClass("navSelected");
            $("ul", this).fadeIn("fast");
        },
        function(){
            $(this).removeClass("navSelected");
            $("ul", this).hide();
        }
    );

/*  Elist
------------------------------------------------------------------------ */

    $("#showElist").click(function(){
        $("#elist").fadeIn(2);
    });

	$("#showElist2").click(function(){
			$("#elist").fadeIn(2);
		});
		
	$("#showElist3").click(function(){
			$("#elist").fadeIn(2);
		});
		
		$("#showElist4").click(function(){
		$("#elist").fadeIn(2);
	});

    $("#showElistclose").click(function(){
        $("#elist").fadeOut();
    });
    
	
	
    $("#elist").submit(function(){
        var name = $("input#cname").val();
          var email = $("input#cemail").val();
          var checkboxes = $("input:checked").length;

          if ((name == "") || (email == "")) {
      		$("p#errorMsg").html("Please fill out all fields.");
      		return false;
      	}

          if (checkboxes == "0") {
      		$("p#errorMsg").html("Please select a city or tour.");
      		return false;
      	}
    });
	
    
/*  About cycle
------------------------------------------------------------------------ */

    $("#cycleAbout div").cycle();

/*  Songlist
------------------------------------------------------------------------ */

    $("#songList").click(function(){
        $("#songlist").fadeIn();
    });

    $("#songListclose").click(function(){
        $("#songlist").fadeOut();
    });


/*  Referral ticket links
------------------------------------------------------------------------ */
    function tixref(tixclass, url) {
        $(tixclass).attr("href",url);
    }

    if ( $.cookie('refersource') == null ) {
        var origin = location.hash;
        var ref = origin.split("#");
        $.cookie( 'refersource', ref[1] );
    }
    if ( $.cookie('refersource') == 'refgoog' ) {
        tixref('.ticketlink','http://www.ticketmaster.com/venueartist/24587/1153299?camefrom=CFC_NED_MDQ_GGL');
    }
    else if ( $.cookie('refersource') == 'reffb' ) {
        tixref('.ticketlink','http://www.ticketmaster.com/venueartist/24587/1153299?camefrom=CFC_NED_MDQ_FACEBOOK');
    }
    else {
        tixref('.ticketlink','http://www.ticketmaster.com/Million-Dollar-Quartet-NY-tickets/artist/1389613?camefrom=CFC_NED_MDQ_SITE');
    }
});// end ready function






/*  Window onload function - things you want to load after everything else
------------------------------------------------------------------------ */

$(window).load(function(){
    
/*  Twitter Feed
------------------------------------------------------------------------ */

    $("#twitterFeed div").getTwitter({
		userName: "milliondquartet",
		numTweets: 4,
		loaderText: "Loading tweets...",
		slideIn: false,
		//slideDuration: 750,
		showHeading: false,
		//headingText: "Latest Tweets",
		showProfileLink: false,
		showTimestamp: false
	});
	
	$("#twitterFeedVid div").getTwitter({
		userName: "milliondquartet",
		numTweets: 3,
		loaderText: "Loading tweets...",
		slideIn: false,
		//slideDuration: 750,
		showHeading: false,
		//headingText: "Latest Tweets",
		showProfileLink: false,
		showTimestamp: false
	});
	
	$("#twitterFeed2 div").getTwitter({
		userName: "milliondquartet",
		numTweets: 7,
		loaderText: "Loading tweets...",
		slideIn: false,
		//slideDuration: 750,
		showHeading: false,
		//headingText: "Latest Tweets",
		showProfileLink: false,
		showTimestamp: false
	});
	
/*  Open external links in a new window
------------------------------------------------------------------------ */

    $("a[href^='http:']").not("[href*=window.location.host]").attr('target','_blank');

/*  Hall of Fame
------------------------------------------------------------------------ */

$('#slideshow').nivoSlider({
	effect:'fold',
	slices:8,
	animSpeed:500,
	pauseTime:5000,
	startSlide:0, //Set starting Slide (0 index)
	directionNav:true, //Next & Prev
	directionNavHide: false, //Only show on hover
	controlNav:true, //1,2,3...
	controlNavThumbs:true, //Use thumbnails for Control Nav
	controlNavThumbsSearch: '.jpg', //Replace this with...
	controlNavThumbsReplace: '-thumb.jpg', //...this in thumb Image src
	keyboardNav:false, //Use left & right arrows
	pauseOnHover:true, //Stop animation while hovering
	manualAdvance:false, //Force manual transitions
	captionOpacity:0.8, //Universal caption opacity
	beforeChange: function(){},
	afterChange: function(){},
	slideshowEnd: function(){} //Triggers after all slides have been shown
});

$('#homeslide').nivoSlider({
	effect:'fold',
	slices:4,
	animSpeed:800,
	pauseTime:2500,
	startSlide:0, //Set starting Slide (0 index)
	directionNav:false, //Next & Prev
	directionNavHide: false, //Only show on hover
	controlNav:false, //1,2,3...
	controlNavThumbs:false, //Use thumbnails for Control Nav
	controlNavThumbsSearch: '.jpg', //Replace this with...
	controlNavThumbsReplace: '-thumb.jpg', //...this in thumb Image src
	keyboardNav:false, //Use left & right arrows
	pauseOnHover:true, //Stop animation while hovering
	manualAdvance:false, //Force manual transitions
	captionOpacity:0.8, //Universal caption opacity
	beforeChange: function(){},
	afterChange: function(){},
	slideshowEnd: function(){} //Triggers after all slides have been shown
});

$('#animationHome').css('cursor','pointer');
$('#animationHome').click(function(){
	window.open('halloffame.html','_self');
	});
	
}); // end window load

// place footer after tour Fact load


function footer(){

	var h1 = $("#tourFacts").height();
	
	var f = document.getElementById("footer");
	console.log(f + " is the footer");
	f.style.marginTop = h1 + 370 + "px";
	console.log(f.style.marginTop + " is the current margin");
};

