/* SVN FILE: $Id: time.js 49 2008-12-15 20:10:35Z jleveille $ */
/**
 * Retrieve and update time
 * @filesource
 * @copyright		Copyright, Video On Location.
 * @version			$Rev: 49 $
 * @modifiedby		$LastChangedBy: jleveille $
 * @lastmodified	$Date: 2008-12-15 15:10:35 -0500 (Mon, 15 Dec 2008) $
 */
var TIME = function()
{
    var milliseconds = null;
    
    return {
    
        /**
         * main init method
         * @access public
         */
        init: function()
        {
            //lazy load milliseconds
            if (!milliseconds) {
                
                $.getJSON(g_config.timeCheckFile, function(r){
                    $('#time').show();
					//ensure that we are getting the proper data
					if (r[0].zone && r[0].timestamp) {
                        $("#time .zone").html(r[0].zone);
                        milliseconds = r[0].timestamp * 1000;
                        TIME.update(new Date(milliseconds));
                        window.setInterval("TIME.init()", 1000);
                    } else {
                        $('#time').hide();
                        return;
                    }
                });
            } else {
                TIME.update(new Date(milliseconds));
            }
        },
        
        /**
         * update time
         * @param object Date
         * @access public
         */
        update: function(time)
        {
            $("#time .time").html(time.toLocaleTimeString());
            milliseconds += 1000;
        }
    };
}();
