/*	
	Countdown to the Date object passed in via _xCountdown.init()
*/

_xCountdown = {
	_xTargetDate: {},
	_nTodayTime: {},
	_sCountdownDivId: '',
	_aMonths: ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],
	_bLeadingZeroes: true,
	
	init:function(p_xTargetDate, p_nTodayTime, p_sDivId, p_bThankYou){
		if(p_bThankYou == true){
			this.displayThankYouMessage();	
		}
		else{
			this.setTargetDate(p_xTargetDate);
			this.setTodayTime(p_nTodayTime);
			this.setCountdownDivId(p_sDivId);
			setInterval("_xCountdown.updateCountdown()",1000)
		}
	},
	
	updateCountdown:function(){
		var l_xToday = new Date(this._nTodayTime);
		
		var l_nTodayYear = l_xToday.getYear();
		var l_nTargetYear = this._xTargetDate.getYear();
		
		if (l_nTodayYear < 1000)
			l_nTodayYear+=1900;
			
		if (l_nTargetYear < 1000)
			l_nTargetYear+=1900;
		
		
		var l_sTodayString = this._aMonths[l_xToday.getMonth()]+' '+l_xToday.getDate()+', '+l_nTodayYear+' '+l_xToday.getHours()+':'+l_xToday.getMinutes()+':'+l_xToday.getSeconds();
		var l_sFutureString = this._aMonths[this._xTargetDate.getMonth()]+' '+this._xTargetDate.getDate()+', '+l_nTargetYear + ' 18:00:00';

		var dd=Date.parse(l_sFutureString)-Date.parse(l_sTodayString);
		var dday=Math.floor(dd/(60*60*1000*24)*1);
		var dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
		var dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
		var dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
	
		if(this._bLeadingZeroes == true){
			if(dday<10){ dday = "0"+dday; }
			if(dhour<10){ dhour = "0"+dhour; }
			if(dmin<10){ dmin = "0"+dmin; }
			if(dsec<10){ dsec = "0"+dsec; }
		}
		
		if(dday==0&&dhour==0&&dmin==0&&dsec==1){
			this.setTargetDate(new Date('September 11, 2010'));
			//$('#'+this._sCountdownDivId+'_module').hide();
			return;
		}
		else{
			$('#'+this._sCountdownDivId+'_days').html(dday);
			$('#'+this._sCountdownDivId+'_hours').html(dhour);
			$('#'+this._sCountdownDivId+'_minutes').html(dmin);
			$('#'+this._sCountdownDivId+'_seconds').html(dsec);
		}
		
		this._nTodayTime += 1000;
	},
	
	setTargetDate:function(p_xDate){
		this._xTargetDate = p_xDate;	
	},
	setTodayTime:function(p_nTime){
		this._nTodayTime = p_nTime*1000;
	},
	
	setCountdownDivId:function(p_sDivId){
		this._sCountdownDivId = p_sDivId;	
	},
	
	displayThankYouMessage:function(){
		setTimeout(function(){
			$('#countdown_module').html('<img src="/image/thankyou.gif" />').css('border', '0'); 
		}, 1000)
	}
}
