$(document).ready(function(){
	
	// bind the click behaviour for the reverse animation
	$('#poll1-question a').bind('click',function(){
		animate_poll1_reverse();
		
		return false;
	});
});

// use window.load rather than document.ready so that we ensure the images are loaded before the animation starts
$(window).load(function(){
	// start the animation after a short delay
	setTimeout("anim_logo()",1000);
});


// animate the logo sign
function anim_logo() {
    $('#comingSoon_coverVoting').fadeIn('slow');
    $('#comingSoon_theMaggies').animate({ "top": "172px" },	1500, "swing");
    
    $('#comingSoon_chains').animate({ "top": "-12px" }, 1500, "swing", function(){
	// remove the logo from the middle stage, and display the top one, so the poll images can slide underneath
	//$('#comingSoon_theMaggies_final').css('display','block');
	$('#comingSoon_theMaggies_final').show();
	$('#comingSoon_theMaggies').hide();

	// animate the scroll
	$('#scroll').animate({ "top": "305px" }, 1000, "swing", function(){
		// add some glitter to the scroll
		$('#stage-front').addSparkleGroup(501,300,4,220,50);
	});

	anim_comingSoon();
    });
}

// drop the coming soon logo into place
function anim_comingSoon() {
    $('#comingSoon_neon_off').animate({ "top": "-10px" }, 1200, "swing");
    $('#comingSoon_neon_on').animate({ "top": "-10px" }, 1200, "swing", function(){
	changeNeonState();

	setTimeout("changeNeonState()",20);
	setTimeout("changeNeonState()",100);
	setTimeout("changeNeonState()",140);
	setTimeout("changeNeonState()",200);
	setTimeout("changeNeonState()",260);
	setTimeout("changeNeonState()",310);
	setTimeout("changeNeonState()",360);

	setTimeout("animate_poll1()",1000);
	//setTimeout("animateWinnersLink()",1000);
    });
}

function animateWinnersLink() {
    $('.winners_link').show();
    $('#winners_link_1').animate({ "left": "290px" }, 2000, "swing");
    $('#winners_link_2').animate({ "left": "270px" }, 1800, "swing");
    $('#winners_link_3').animate({ "left": "250px" }, 1600, "swing");
    $('#winners_link_4').animate({ "left": "230px" }, 1400, "swing");
    $('#winners_link_5').animate({ "left": "210px" }, 1200, "swing");
    $('#winners_link_6').animate({ "left": "190px" }, 1000, "swing", function(){
	$('#winnersSeeArchive').fadeIn('slow');
    });
}

// flicker the neon coming soon logo
function changeNeonState() {
	if ($('#comingSoon_neon_on').css('display') == 'none') {
		$('#comingSoon_neon_off').css('display','none');
		$('#comingSoon_neon_on').css('display','block');
	} else
	{
		$('#comingSoon_neon_off').css('display','block');
		$('#comingSoon_neon_on').css('display','none');
	}
}

function animate_poll1() {
	var spd = 1500;
	
	var bounce = function(){
		if (!crapBrowser) {
			$(this).effect("bounce", {
				times: 3,
				distance: 10
			}, 300);
		}
	};
	 
	$('#poll1-1').animate({ "top": "-218px" }, spd + parseInt(Math.random()*500), "linear", bounce);
	$('#poll1-2').animate({ "top": "-445px" }, spd + parseInt(Math.random()*500), "linear", bounce);
	$('#poll1-3').animate({ "top": "-295px" }, spd + parseInt(Math.random()*500), "linear", bounce);
	$('#poll1-4').animate({ "top": "-197px" }, spd + parseInt(Math.random()*500), "linear", bounce);
	$('#poll1-question').animate({ "top": "-125px" }, spd + parseInt(Math.random()*500), "linear", bounce);
}

function animate_poll1_reverse() {
	var spd = 1500;
	
	$('#poll1-1').animate({ "top": "-800px" }, spd);
	$('#poll1-2').animate({ "top": "-800px" }, spd);
	$('#poll1-3').animate({ "top": "-800px" }, spd);
	$('#poll1-4').animate({ "top": "-800px" }, spd);
	$('#poll1-question').animate({ "top": "-800px" }, spd, function(){
		$('#comingSoon_theMaggies_final').hide();
		$('#comingSoon_theMaggies').show();
		$('#scroll').animate({ "top": "-80px" }, 1000, "swing");
		$('#comingSoon_theMaggies').animate({ top: "-171px" }, 1500);
		$('#comingSoon_chains').animate({ top: "-355px" }, 1500);
		$('#comingSoon_neon_on').animate({ "top": "-275px" }, spd);
		$('#comingSoon_coverVoting').fadeOut('slow',function(){
			// when finished, load the next page
			window.location="/poll/who-is-your-favourite-wag/";
		});
	});
}

