﻿var clockID = 0;

var OpenDay = new Date(2008, 7, 8);
var one_day=1000*60*60*24;
var one_hour=1000*60*60;
var one_minute = 1000*60;
var one_second = 1000;


function UpdateClock ()
{
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }

   var latest;
    var curdate;
    var maxseconds = 5400;


    if (!latest) { //if not already loaded then try loading it
      latest = readHTTPHeaders("/js/BeijingClock.js?" + Math.random()*5000);
    }

    if (latest.length > 1) {
      curdate = new Date(latest);
 }
 

    var hours = curdate.getHours();
    for (i=1; i<=12; i++)
    {
    hours = hours + 1;
    if (hours==25)
    {
    hours = 1
    } }
    var minutes = curdate.getMinutes()
    var seconds = curdate.getSeconds()
    var timeValue = "" + ((hours > 12) ? hours - 12 : hours)
    timeValue  += ((minutes < 10) ? ":0" : ":") + minutes
//*    timeValue  += ((seconds < 10) ? ":0" : ":") + seconds *//
    timeValue  += (hours >= 12 && hours < 24) ? " P.M." : " A.M."
    document.getElementById("clock").firstChild.nodeValue = timeValue;
today=new Date();
	var millis = (OpenDay.getTime()-today.getTime());
    var olydays = Math.floor(millis/one_day);
    var olyhours = Math.floor((millis-(olydays*one_day))/one_hour)
//    alert(olyhours);

     if(olyhours > 15) {olydays=olydays+1;}

//    var Daydiff = "Countdown to the 2008 Beijing Olympics: " + olydays + " days";
    var Daydiff = "Congratulations to our athletes.";
    
        
    document.getElementById("countdown").firstChild.nodeValue = Daydiff;
}



var oldonload = window.onload
    if (typeof window.onload != 'function') {
    window.onload = function() {
    UpdateClock()
    setInterval('UpdateClock()', 15000 )
    }
    } else {
    window.onload = function() {
   UpdateClock()
   setInterval('UpdateClock()', 15000 )
    oldonload()
    }

}



      