﻿var htmlFragments = new Array();
htmlFragments[3] = "/HTMLFragments/Leisure.html";
htmlFragments[2] = "/HTMLFragments/Car.html";
htmlFragments[1] = "/HTMLFragments/Home.html";
htmlFragments[0] = "/HTMLFragments/BusinessCar.html";


var tabClicked = false;
var currentItem = 0;
var t;



$(document).ready(function () {
    t = setTimeout("ChangeContent()", GetTimeOnscreen());
    
 });



function ChangeContent() {
    if (!tabClicked) {
        currentItem++;
        if (currentItem >= htmlFragments.length)
            currentItem = 0;
        ShowContent();
        t = setTimeout("ChangeContent()", GetTimeOnscreen());
    }
}

function ShowContent() {
    $('.carouselTabs li').each(function (index) {


        if (index == currentItem + 1)//adding one to account for the product label
            $(this).addClass('selected');
        else
            $(this).removeClass('selected')

        if (index == currentItem)
            $(this).removeClass('seperator')
        else if (index > 0)
            $(this).addClass('seperator')

    });

    $.ajax({
        url: htmlFragments[currentItem],
        success: function (data) {
            //load into content2 and shift left


            $('#carouselContent2').html(data);

            $('#carouselContent1').animate({
                left: '-460px'
            }, {
                duration: GetTransitionTime(),
                complete: function () {
                    $('#carouselContent1').css("left", "0px");
                }
            });

            $('#carouselContent2').animate({
                left: '0px'
            }, {
                duration: GetTransitionTime(),
                complete: function () {
                    //swap content and put the divs back ready for next change
                    $('#carouselContent1').html($('#carouselContent2').html());
                    $('#carouselContent2').css("left", "460px");
                }
            });

        }
    });
}


function TabSelected(tab) {

    currentItem = tab;
    ShowContent();
    tabClicked = true;
    ChangeContent();
}