﻿/*!

*/
var itemHeight = 0;
var clockUpdater = setInterval("updateTimes()", 60000);
var animationDelay = null;

jQuery(document).ready(function () {

    //Get Time Zone Height
    itemHeight = jQuery(".zone").outerHeight();
    if (itemHeight == 0)
        itemHeight = 29;



    //Striping
    jQuery(".zone:odd").addClass("alt");

    //Start Scroller
    scrollTimes();

});

function scrollTimes() {
    jQuery('.time-zones').animate({
        top: '-=' + itemHeight
    }, 600, "easeOutQuad", function () {

        //ANIMATION COMPLETE

        //Adjust Striping
        if (!jQuery(".zone:last").hasClass("alt")) {
            jQuery(".zone:first").addClass("alt");
        }
        else {
            jQuery(".zone:first").removeClass("alt");
        }

        //Adjust Position of Container
        jQuery('.time-zones').animate({
            top: '+=' + itemHeight
        }, 0);

        //Move First Zone to Last Position
        jQuery(".zone:first").insertAfter(jQuery(".zone:last"));

        //Delay then Repeat
        animationDelay = setTimeout("scrollTimes()", 2400);
    });
}

function updateTimes() {

    jQuery("span.minutes").each(function () {

        var minutes = parseInt(jQuery(this).html(), 10);
        var hour = parseInt(jQuery(this).siblings("span.hour").html(), 10);

        minutes += 1;
        if (minutes == 60) {
            hour += 1;
            minutes = 0;

            if (hour == 24) {
                hour = 0;
            }

            if (hour < 10) {
                hour = "0" + hour;
            }

            jQuery(jQuery(this).siblings("span.hour")).html(hour);
        }

        if (minutes < 10) {
            minutes = "0" + minutes;
        }

        jQuery(this).html(minutes);

    });
}
