/* JS for Counter */

var openingEvent = new Date("October 03, 2010 9:00:00")
var msProMin = 1000*60;
var msProStd = msProMin*60;
var msProDay = msProStd*24;
var msProWeek= msProDay*7;

var glbPathFont = "images/";
var glbFontEnd = ".gif";



var glbWeekId1 = "timerPos_0";
var glbWeekId2 = "timerPos_1";

var glbDayId1 = "timerPos_3";
var glbDayId2 = "timerPos_4";

var glbHourId1 = "timerPos_6";
var glbHourId2 = "timerPos_7";

var glbMinId1 = "timerPos_9";
var glbMinId2 = "timerPos_10";

var glbSecId1 = "timerPos_12";
var glbSecId2 = "timerPos_13";

function initTime () {
	document.getElementById( "timerPos_2" ).src = glbPathFont + "_" + glbFontEnd;	
	document.getElementById( "timerPos_5" ).src = glbPathFont + "_" + glbFontEnd;
	document.getElementById( "timerPos_8" ).src = glbPathFont + "_" + glbFontEnd;
	document.getElementById( "timerPos_11" ).src = glbPathFont + "_" + glbFontEnd;
}

function writeTime ( _id1, _id2, _value) {
	_value = String( _value );	
	document.getElementById( _id1 ).src = glbPathFont + _value.substr(0, 1) + glbFontEnd;
   	document.getElementById( _id2 ).src = glbPathFont + _value.substr(1, 1) + glbFontEnd;
}


function showTime() {
   var today = new Date();
   var diff  = Math.max( 0, (openingEvent.getTime() - today.getTime()) );

   var weeks = Math.floor( diff / msProWeek);
   var days = Math.floor( (diff % msProWeek) / msProDay);
   var hours = Math.floor( (diff % msProDay) / msProStd );
   var mins  = Math.floor( (diff % msProStd) / msProMin );
   var secs = Math.floor( (diff % msProMin) / 1000 )

   var allweeks  = ((weeks < 10) ? "0" + weeks : weeks);
   var alldays  =  ((days  < 10) ? "0" + days  : days);
   var allhours  = ((hours < 10) ? "0" + hours : hours);
   var allmins  =  ((mins  < 10) ? "0" + mins  : mins);
   var allsecs  =  ((secs  < 10) ? "0" + secs  : secs);

  writeTime( glbWeekId1, glbWeekId2, allweeks );
  writeTime( glbDayId1, glbDayId2, alldays );
  writeTime( glbHourId1, glbHourId2, allhours );
  writeTime( glbMinId1, glbMinId2, allmins );
  writeTime( glbSecId1, glbSecId2, allsecs );



   window.setTimeout('showTime()',1000); 
    
}