var countdownTimer = new jCountdownTimer(jQuery('input[name=thanksgiving]').val(),jQuery('input[name=datetime]').val());

var imageAnimation = new jImageAnimation('#holidayAnimation #headline',['-250px', '0px'],['-14px','-328px','-730px','-1140px','-1530px','-1965px','-2330px']);

jQuery(function($){
	$('#holidayAnimation .CounterTicker').fadeOut(600,function(){
		$(this).remove();

		countdownTimer.container = $('#holidayAnimation #counter').fadeIn(600);
		countdownTimer.updateTime = function(element,value,force){
			var _oldValue = parseInt(element.html(),10);
			var _newValue = parseInt(value,10);
			
			function formatValue(value){ return value < 10 ? '0' + value : value.toString(); }
			
			return force
				? element.html(formatValue(_newValue)) 
				: _oldValue == _newValue 
				? element
				: element.fadeTo(600,0,function(){ element.html(formatValue(_newValue)).fadeTo(600,1) });
		};
		
		countdownTimer.start().addEventListener(function(time,id){
			countdownTimer.updateTime(countdownTimer.container.find('#seconds'),time.seconds,true);
			countdownTimer.updateTime(countdownTimer.container.find('#minutes'),time.minutes);
			countdownTimer.updateTime(countdownTimer.container.find('#hours'),time.hours);
			countdownTimer.updateTime(countdownTimer.container.find('#days'),time.days);
		});
		
		imageAnimation.start();
	});
});
