var imgA = [{name:URL_PREFIX + "images/home/SE_1.jpg", img:null}, 
            {name:URL_PREFIX + "images/home/SE_3.jpg", img:null}, 
            {name:URL_PREFIX + "images/home/230.jpg", img:null}, 
            {name:URL_PREFIX + "images/home/tc_1.jpg", img:null}, 
            {name:URL_PREFIX + "images/home/tc_2.jpg", img:null}, 
            {name:URL_PREFIX + "images/home/236FA.jpg", img:null}, 
            {name:URL_PREFIX + "images/home/595_radiale.jpg", img:null}, 
            {name:URL_PREFIX + "images/home/207_1.jpg", img:null}, 
            {name:URL_PREFIX + "images/home/SE_2.jpg", img:null}, 
            {name:URL_PREFIX + "images/home/SE_4.jpg", img:null}, 
            {name:URL_PREFIX + "images/home/tc_3.jpg", img:null}, 
            {name:URL_PREFIX + "images/home/minibus.jpg", img:null}];

var startServerMS,
    startClientMS;


function clockUpdate() {

  // Take the current number of MS off of the startMS and add this to the start Time to get the current time.
  // Then get the current Hour and Minute and select the appropriate CSS
  var currentDate = new Date(startServerMS + ((new Date().getTime()) - startClientMS)),
      h = currentDate.getHours(),
      clsHour = "hour_" + ((h === 0) ? 12 : (h > 12) ? h - 12 : h),
      m = currentDate.getMinutes(),
      clsMin = "minute_" + m;
  
  $("#clockHour").removeClass().addClass("hour " + clsHour);
  $("#clockMinute").removeClass().addClass("minute " + clsMin);
  
  //console.log("clsHour:" + clsHour + ", clsMin:" + clsMin);
}


$(function() {
  
  new imgMove({ selWrap:" #imgHomeWrap",
            selImg: "#imgHome", 
            imgA: imgA, 
            aMove: {x:-100, y:-70, xTo:0, yTo:0}});
            
  var url = "/php/getDate.php";
    
  // Call the server for the real time
  if ($("#clockHour").size() > 0) {
    $.getJSON(url,  function(data) {
                      startServerMS = data.ms * 1000;
                      // Adjust because the server is currently 3 hours and 1 minute slow:
                      //startServerMS += (3 * 60 * 60 * 1000) + (5 * 60 * 1000);
                      //startServerMS = new Date().getTime();
                      startClientMS = new Date().getTime();       // Number of MS since 1 January 1970 00:00:00
                      clockUpdate();
                      setInterval(function() {clockUpdate();}, 5000);
                    });
  }
});