﻿/// <reference path="jquery-1.4.1-vsdoc.js" />


jQuery(document).ready(function() {

    // Spotlight
    var ms = 10000;
    initSpotlight(ms);

    // Menu
    jQuery('#menu li.headlink').hover(
        function () { jQuery('ul', this).css('display', 'block') },
        function () { jQuery('ul', this).css('display', 'none'); });

});

function initSpotlight(ms) {
    showSpotlightDirect(0);
    startSpotlight(ms);
    jQuery("#SpotlightButtons div").mouseenter(function () {
        stopSpotlightTimer();
        showSpotlightDirect(jQuery(this).index());
    });
    jQuery("#SpotlightButtons div").mouseleave(function () {
        startSpotlight(ms);
    });
}

function startSpotlight(ms) {
    jQuery("#SpotlightSwapper").everyTime(ms, "SpotlightTimer", function (i) {
        fadeSpotlight();
    });
}

function stopSpotlightTimer() {
    jQuery("#SpotlightSwapper").stopTime("SpotlightTimer");
}

function fadeSpotlight() {
    var jQueryspotlightElements = jQuery("#SpotlightSpots").find(".spot");
    var jQueryvisibleSpot = jQuery("#SpotlightSpots .spot:visible");

    jQueryvisibleSpot.fadeOut();
    if (jQueryvisibleSpot.index() + 1 == jQueryspotlightElements.length) {
        showSpotlight(0);
    }
    else {
        showSpotlight(jQueryvisibleSpot.index() + 1);
    }
}

function showSpotlight(index) {
    jQuery("#SpotlightSpots .spot").each(function () {
        if (jQuery(this).index() != index) {
            jQuery(this).fadeOut();
        }
    });
    jQuery("#SpotlightSpots .spot").eq(index).fadeIn();
    jQuery("#SpotlightDescription").html(jQuery("#SpotlightSpots .spot").eq(index).find(".hiddenDescription").html());
    jQuery("#SpotlightButtons div").removeClass("activeSpot");
    jQuery("#SpotlightButtons div").eq(index).addClass("activeSpot");
}

function showSpotlightDirect(index) {
    jQuery("#SpotlightSpots .spot").each(function() {
        if (jQuery(this).index() != index) {
            jQuery(this).hide();
        }
    });
    jQuery("#SpotlightSpots .spot").eq(index).fadeIn(0);
    jQuery("#SpotlightDescription").html(jQuery("#SpotlightSpots .spot").eq(index).find(".hiddenDescription").html());
    jQuery("#SpotlightButtons div").removeClass("activeSpot");
    jQuery("#SpotlightButtons div").eq(index).addClass("activeSpot");
}
