﻿
var splashBoxContainer = null;
var splashBoxes = null;
var splashWidth = null;
var autoSlide = null;
var intervalHandler = null;
var autoSlideOn = false;

$(document).ready(function () {
    //
    // Init splash element variables
    //
    splashBoxes = $(".splashBox");
    splashWidth = splashBoxes.width() * splashBoxes.size();
    splashBoxContainer = $("#splashBoxContainer");
    lastClickedSlide = null;
    //
    // Go to the first slide
    //
    MoveToSplashBox($('.splash_nav_item:first').attr('href'));

    //
    // When clicked, slide to the respective splash box
    //
    splashBoxContainer.css("width", splashWidth + "px");
    $("#splash_nav_bar a").click(function () {
        clearInterval(intervalHandler);
        autoSlideOn = false;
        id = $(this).attr("href");
        fadedOut = false;
        if ((lastClickedSlide == "#splash5") && id == "#splash1") {
            splashBoxContainer.fadeOut(250, function () {
                $(this).css('filter', '');
            });
            fadedOut = true;
        }

        MoveToSplashBox(id);

        if (fadedOut)
            splashBoxContainer.fadeIn(350, function () {
                $(this).css('filter', '');
            });
        lastClickedSlide = id;
        return false;
    });

    if (autoSlide == null) {
        autoSlide = function () {
            autoSlideOn = true;
            href = $('.currentSplashNavItem').nextAll("a").first().attr('href');
            fadedOut = false;
            if (href == undefined) {
                href = $('.splash_nav_item:first').attr('href');
                splashBoxContainer.fadeOut(250, function () {
                    $(this).css('filter', '');
                });
                fadedOut = true;
            }

            MoveToSplashBox(href);

            if (fadedOut)
                splashBoxContainer.fadeIn(350, function () {
                    $(this).css('filter', '');
                });

        };
    }

    if (intervalHandler == null) {
        intervalHandler = setInterval(autoSlide, 7000);

    }
    else {

    }




    function MoveToSplashBox(id) {
        href = id;
        var splashNavItem = $('.splash_nav_item').filter('[href=' + href + ']');
        var moveBy = splashNavItem.prevAll("a").size();
        $('.currentSplashNavItem').removeClass('currentSplashNavItem');
        splashNavItem.addClass('currentSplashNavItem');
        splashBoxContainer.animate({ left: -($(href).width() * moveBy) + "px" }, 500);

        return false;
    }

    function InitSplash() {

    }
});
