﻿$(function () {
    // find the div.fade elements and hook the hover event
    $('div#download').hover(function () {
        // on hovering over find the element we want to fade *up*
        var fade = $('> div', this);

        // if the element is currently being animated (to fadeOut)...
        if (fade.is(':animated')) {
            // ...stop the current animation, and fade it to 1 from current position
            fade.stop().fadeTo(250, 1);
        } else {
            fade.fadeIn(250);
        }
    }, function () {
        var fade = $('> div', this);
        if (fade.is(':animated')) {
            fade.stop().fadeTo(300, 0);
        } else {
            fade.fadeOut(300);
        }
    });
});

function formatJSONDate(jsonDate) {
    return new Date(jsonDate);
}

lastCount = 0;
function setLastCount(count) { lastCount = count; }

function updateClients() {
    $.ajaxSetup({ cache: false });
    $.getJSON("/Services/jsonStatus",
    function (data) {
        if (data.UOSA.onlineCount != lastCount) {
            $("#clients").fadeOut('fast').html(data.UOSA.onlineText).fadeIn("fast");
            lastCount = data.UOSA.onlineCount;
        }

        title = "";

        if (!data.UOSA.up)
            title = title + "Down Since: " + formatJSONDate(data.UOSA.lastOffline) + "\n";
        title = title + "Updated: " + formatJSONDate(data.UOSA.lastUpdated);


        $("#status").attr("title", title);

        //alert(data.UOSA.onlineCount + ", " + lastCount);
    });
}
