﻿var recentPress = new Array();
var currentPressRelease = 0;
var recentPressIntervalID = 0;

$(document).ready(function() {
    LoadRecentPressReleases();
});

function LoadRecentPressReleases() {
    $.ajax({
        type: "POST",
        url: "/library/services.asmx/GetRecentPressReleases2011",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(pressReleaseArray) {
            StartPressReleases(pressReleaseArray);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            ErrorPressReleases(XMLHttpRequest);
        }
    });
}
function StartPressReleases(pressReleaseArray) {
    if (pressReleaseArray != null) {
        if (pressReleaseArray.d != null) {
            recentPress = pressReleaseArray.d;
            if (recentPress.length > 0) {
                var dt = new Date();
                $("#whatsNewDate").text(recentPress[currentPressRelease].ReleaseDateDisplay);
                $("#whatsNewText").text(recentPress[currentPressRelease].TitleDisplay);
                $("#whatsNew").attr("title", recentPress[currentPressRelease].Title);
                $("#whatsNew").click(function() {
                    window.location = recentPress[currentPressRelease].Link;
                });
                if (recentPress.length > 1) {
                    $("#whatsNew").mouseover(function() {
                        clearInterval(recentPressIntervalID);
                    });
                    $("#whatsNew").mouseout(function() {
                        recentPressIntervalID = setInterval("TogglePressRelease()", 5000);
                    });
                    recentPressIntervalID = setInterval("TogglePressRelease()", 5000);
                }
            }
        }
    }
}
function ErrorPressReleases(XMLHttpRequest) {

}
function TogglePressRelease() {
    currentPressRelease++;
    if (currentPressRelease >= recentPress.length) {
        currentPressRelease = 0;
    }
    $("#whatsNew").slideUp(function() {
        $("#whatsNewText").text(recentPress[currentPressRelease].TitleDisplay);
        $("#whatsNewDate").text(recentPress[currentPressRelease].ReleaseDateDisplay);
        $("#whatsNew").attr("title", recentPress[currentPressRelease].Title);
        $("#whatsNew").click(function() {
            window.location = recentPress[currentPressRelease].Link;
        });
        $("#whatsNew").slideDown();
    });
}

