﻿///<reference path="/_js/jQuery/1.4.1/jquery-1.4.1-vsdoc.js"/>
var s_currentSpot = 1;
var s_transitionDelay = 5; //how long between slide transitions
var s_currentTimeout = 5;
var s_interval;

j$(document).ready(function () {

    //we can randomize the fading time
    //this will use a min and max
    var min = 5;
    var max = 8;
    r_transitionDelay = Math.floor(Math.random() * (max - (min + 1))) + min;
    r_currentTimeout = r_transitionDelay;

    j$("div.spotlightWrapper").hover(function () {
        //while over
        clearInterval(s_interval);
    }, function () {
        //when gone
        s_currentTimeout = s_transitionDelay;
        s_interval = setInterval("updateSpotlightTimeout()", 1000);
    });

    s_interval = setInterval("updateSpotlightTimeout()", 1000);
});

function updateSpotlightTimeout() {
    if (s_currentTimeout > 0)
        s_currentTimeout--;
    else {
        s_currentTimeout = s_transitionDelay;
        nextSpotlight();
    }
}

function updateSpotlight(sender, position) {
    //update the buttons
    j$("div.spotlightWrapper div.buttons a").removeClass("scrollerButtonSelected");
    j$(sender).addClass("scrollerButtonSelected");

    //images
    j$("div.spotlightWrapper div.spotlightImages > div").css({ zIndex: 99 }).fadeOut("slow");
    j$("div.spotlightWrapper div.spotlightImages div.spotlightImage" + position).css({ zIndex: 90 }).fadeIn("slow");

    //content
    j$("div.spotlightWrapper div.spotlightContent > div").css({ zIndex: 99 }).fadeOut("slow");
    j$("div.spotlightWrapper div.spotlightContent div.spotlightContent" + position).css({ zIndex: 90 }).fadeIn("slow");

    s_currentSpot = position;
}

function nextSpotlight() {
    s_currentSpot++;
    var scrollers = j$("div.spotlightWrapper div.buttons a.btnJump");

    if (s_currentSpot > scrollers.size()) {
        s_currentSpot = 1;
    }

    updateSpotlight(scrollers.get(s_currentSpot - 1), s_currentSpot);
}
