﻿

var activeItem = 1;
var t = null;
var auto = 5000;
var slide_auto = true;
var speed = 1050;



//JQuery script to dynamically resize skin DIVs to maximize browser window space
$(function () {

    //on browser resize

    $(window).resize(function () {
        //Content outer container dimensions
        var ContentMainHeight = $(window).height(); 
        var ContentMainWidth = $(window).width(); 


        var theDiff = ContentMainWidth - 970;
        var theWidth = theDiff / 2;


        var theHeight = ContentMainHeight - 546;




        $("#leftSideA").css('width', theWidth);
        // $("#leftSideA").css('height', ContentMainHeight);
         $("#leftSideB").css('width', theWidth);
        // $("#leftSideB").css('height', ContentMainHeight);

        $("#rightSideA").css('width', theWidth);
        // $("#rightSideA").css('height', ContentMainHeight);
        $("#rightSideB").css('width', theWidth);
        // $("#rightSideB").css('height', ContentMainHeight);

        $("#bottomBlackBar").css('width', ContentMainWidth);

        $("#contentTable").css('height', theHeight);
        

    });



    //On Body load


    $(document).ready(function () {
        
        //Content outer container dimensions
        var ContentMainHeight = $(window).height(); 
        var ContentMainWidth = $(window).width(); 


        var theDiff = ContentMainWidth - 970;
        var theWidth = theDiff / 2;
        var theHeight = ContentMainHeight - 546;


        $("#leftSideA").css('width', theWidth);
        // $("#leftSideA").css('height', ContentMainHeight);
        $("#leftSideB").css('width', theWidth);
        // $("#leftSideB").css('height', ContentMainHeight);

        $("#rightSideA").css('width', theWidth);
        // $("#rightSideA").css('height', ContentMainHeight);
        $("#rightSideB").css('width', theWidth);
        // $("#rightSideB").css('height', ContentMainHeight);

        $("#bottomBlackBar").css('width', ContentMainWidth);
        $("#contentTable").css('height', theHeight);




        $('.nav-controller UL LI').hover(function () {
            $(this).find('.popup').show();
        }, function () {
            $(this).find('.popup').hide();
        });

        $('.content-slider LI').css("display", "none");
        $('.content-slider LI:first').css("display", "block");

        $('.nav-controller ul li a').click(function () {
            activeItem = parseInt($(this).attr("class"));
            if ($('.nav-controller ul li a.' + activeItem).parent().hasClass('selected')) return false;
            clearTimeout(t);
            slide_auto = false;
            customSlider();
        });

        $('.nav-controller a.next').click(function () {
            clearTimeout(t);
            nextItem();
            slide_auto = false;
            customSlider();
            return false;
        });

        $('.nav-controller a.prev').click(function () {
            clearTimeout(t);
            prevItem();
            slide_auto = false;
            customSlider();
            return false;
        });
        t = setTimeout("nextItem();customSlider();", auto);



    });
});




function customSlider() {
    if (parseInt($(".content-slider").css("opacity")) < 1) return false;

    $('.content-slider').fadeTo(speed, "0", function () {
        $('.content-slider LI, .video-box .slider LI').css("display", "none");
        $('.content-slider LI').each(function (i, el) { if ((i + 1) == activeItem) $(this).css("display", "block"); });
        $('.video-box .slider LI').each(function (i, el) { if ((i + 1) == activeItem) $(this).css("display", "block"); });
        $('.nav-controller ul li').removeClass('selected');
        $('.nav-controller ul li a.' + activeItem).parent().addClass('selected');
        $('.content-slider').fadeTo(speed, "1", function () {
            if (slide_auto) { t = setTimeout("nextItem();customSlider();", auto); }
            else t = setTimeout("customSlider();", auto);
            slide_auto = true;
        });
    });
    $('.video-box .slider').fadeTo(speed, "0", function () { $('.video-box .slider').fadeTo(speed, "1"); });
    return false;
}
function prevItem() {
    if (activeItem <= 1) activeItem = $(".content-slider UL LI").length;
    else activeItem--;
}
function nextItem() {
    if (activeItem >= $(".content-slider UL LI").length) activeItem = 1;
    else activeItem++;
}
