var cityTimeDays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
function showCityTime(row, t, i) {
    if (row)
        row.setStyle({ 'color': '#163979', 'backgroundColor': '#d9d9d9' });
    if (t)
        t.show();
}
function hideCityTime(row, t, i) {
    if (row)
        row.setStyle({ 'color': '#727274', 'backgroundColor': 'white' });
    if (t)
        t.hide();
}
function onCityTimeOver() {
    if (arguments[2] != cityTimeCur)
        showCityTime(this, arguments[1], arguments[2]);
}
function onCityTimeOut() {
    if (arguments[2] != cityTimeCur)
        hideCityTime(this, arguments[1], arguments[2]);
}
function onCityTimeClick() {
    if (arguments[2] != cityTimeCur) {
        hideCityTime($("cityTimeRow" + cityTimeCur), $("cityTime" + cityTimeCur), cityTimeCur);
        showCityTime(this, arguments[1], arguments[2]);
        cityTimeCur = arguments[2];
        setCookie("cityTimeCur", cityTimeCur, "/", 525600);
    }
}
function getSuffix(number) {
    if (number > 3 && number < 21)
        return "th";
    switch (number - Math.floor(number / 10) * 10) {
        case 1: return "st";
        case 2: return "nd";
        case 3: return "rd";
        default: return "th";
    }
}
function updateCityTime(with_increment) {
    for (var i = 0; i < cityTime.length; i++) {
        if (with_increment)
            cityTime[i] = new Date(cityTime[i].getTime() + 60000);
        var d = cityTime[i];
        var mins = d.getMinutes();
        var hour = d.getHours();
        //if (i == cityTimeCur)
        //{
        //    g_curM = mins;
        //    g_curH = hour;
        //}
        g_cityTimeData[i].m = mins;
        g_cityTimeData[i].h = hour;
        if (mins < 10) mins = "0" + mins;
        var sCurTime = cityTimeDays[d.getDay()] + " " + d.getDate() + getSuffix(d.getDate()) + " " + hour + ":" + mins;
        g_cityTimeData[i].s = sCurTime;
        //if (i == cityTimeCur)
        //    g_curTime = sCurTime;
        $("cityTime" + i).innerHTML = sCurTime;

    }
    if ($('clock'))
        updateClock();
}
Event.observe(window, "load", function () {
    var cur = getCookie("cityTimeCur");
    if (cur)
        cityTimeCur = cur;
    else
        setCookie("cityTimeCur", cityTimeCur, "/", 525600);
    updateCityTime();
    for (var i = 0; i < cityTime.length; i++) {
        var divRow = $("cityTimeRow" + i);
        var divTime = $("cityTime" + i);
        divRow.observe('mouseover', onCityTimeOver.bindAsEventListener(divRow, divTime, i));
        divRow.observe('mouseout', onCityTimeOut.bindAsEventListener(divRow, divTime, i));
        divRow.observe('click', onCityTimeClick.bindAsEventListener(divRow, divTime, i));

        if (i != cityTimeCur) {
            hideCityTime(divRow, divTime, i);
        } else {
            showCityTime(divRow, divTime, i);
        }
    }
    setInterval("updateCityTime(1)", 60000); // 60 sec.
});