﻿var htmlFragments = new Array();
htmlFragments[0] = "/HTMLFragments/Taxi.html";
htmlFragments[1] = "/HTMLFragments/Minibus.html";
htmlFragments[2] = "/HTMLFragments/PolicyBenefits.html";
htmlFragments[3] = "/HTMLFragments/GAP.html";

var tabClicked = false;
var currentItem = 0;
var t;

$(document).ready(function () { t = setTimeout("ChangeContent()", 20000); });

function ChangeContent() {
    if (!tabClicked) {
        currentItem++;
        if (currentItem >= htmlFragments.length)
            currentItem = 0;
        ShowContent();
        t = setTimeout("ChangeContent()", 20000);
    }
}

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: 1000,
                complete: function () {
                    $('#carouselContent1').css("left", "0px");
                }
            });

            $('#carouselContent2').animate({
                left: '0px'
            }, {
                duration: 1000,
                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();
}
