// JavaScript Document



$(document).ready(function(){ /* Runs code when DOM is in place */
	
	/* Determine how quickly the browser will attempt to run the animation */
	var framerate = 25;
	var delay = 1000/framerate;
	
	/* Add a class to the document body to make stylesheets display differently if JS is running */
	$("body").addClass("js");
	
	/* Detect if user is on iPhone */
	var agent=navigator.userAgent.toLowerCase();
	var is_iphone = (agent.indexOf('iphone')!=-1);
	
	/* Fix display issue with h2 being too wide on iPhone */
	if (is_iphone){
		$("h2").css("width","430px");
	}
	
	
	
	
	/* Repeating animation code */
	
	var $bird=$("#bird");
	$bird.css({
		"left":"-50px",
		"top":"100px"
	});
	
	$bird.click(function(){
		alert ("SQUAWK!");
	});
	
	var i = 0; /* increment for windmills */
	var j = 0; /* increment for bird */
	function animateAllStuff (){
		
		/* Windmills */
		i = i + 5;
		if (i >= 360){
			i = 0;
		}
		
		/* For Safari or Chrome */
		$("#windmill1, #windmill2, #windmill3").css("-webkit-transform", "rotate("+ i +"deg)");
		
		/* For Firefox (and other Mozilla browsers */
		$("#windmill1, #windmill2, #windmill3").css("-moz-transform", "rotate("+ i +"deg)");
		
		
		/* Bird */
		j = j+5;
		if (j>=$(window).width()-44){
			j=0;
		}
		$bird.css("left",j+"px");
		$bird.css("top", Math.ceil(Math.sin(j/90)*60+250)+"px");
		if (j%10 >= 4){
			$bird.toggleClass("down");
		}
		
	}	
	
	if (is_iphone != true){ /* Don't run on iPhone or iPod - causes crashes */
		var timer = setInterval(animateAllStuff,delay);
	}
	
	
	
	
	/* Text replacement */
		$("#leftCol h2").css("textTransform","uppercase");
		$("#leftCol h2 .smallwords").css("fontSize","11px");
		$("#leftCol h2 .largewords").css({
			"display":"block",
			"fontSize":"23px"
		});
		Cufon.replace('#leftCol h2, #leftCol h3, #leftCol h4, #leftCol h5');
	
	
	
	/***************** Countdown Timer *******************/
	var todaysdate = new Date (); /* Empty "Date" returns today's date info */
		
	var entriesdue = new Date (2010,1-1,8,18); /* January 8, 2010 - 6:00pm */
	
	var addygala = new Date (2010,2-1,27,18); /* February 27, 2010 - 6:00pm */
	
	
	
	if (entriesdue.getTime() > todaysdate.getTime()){ /* If it's before the entries are due */
		/* Count down until the entrires are due */
		$("#countdowncaption").html("Addy<br/> entries<br/> due:");
		$("#countdownspot").countdown({
			until: entriesdue,
			format: "DHMS",
			labels: ['yrs', 'mth', 'wks', 'days', 'hrs', 'min', 'sec'], 
			labels1: ['yr', 'mth', 'wk', 'day', 'hr', 'min', 'sec']
		});
		/*$("#countdownspot").countdown('pause');*/
	}
	
	if (entriesdue.getTime() < todaysdate.getTime() && addygala.getTime() > todaysdate.getTime()){ /* If it's between the entry date and gala date */
		/* Count down until the Addy gala */
		$("#countdowncaption").html("Addy<br/> Gala<br/> in:");
		$("#countdownspot").countdown({
			until: addygala,
			format: "DHMS",
			labels: ['yrs', 'mth', 'wks', 'days', 'hrs', 'min', 'sec'], 
			labels1: ['yr', 'mth', 'wk', 'day', 'hr', 'min', 'sec']
		});
	}
	
	if (addygala.getTime() < todaysdate.getTime()){
		$("#countdown").hide();
	}
	
	
	
});



$(window).load(function() { /* Runs code when all images, etc. are loaded */
						
	/* Animate title in */
	$("body.js #storytellers a").animate({
		"top":"-130px"
	},1200);	
	
});
