var vtCarouselInMotion;
var vtAutoAdvances;
var vtUserInterrupt = false;

$(document).ready(initjs);

function initjs() {

	/*carousel*/
	vtCarouselInMotion = false;
	$("#vtAdvance").click(vtUserFwd);
	$("#vtReverse").click(vtUserRev);
	vtAutoAdvances =  $("li.promogroup").length;
	setTimeout("vtAutoAdvance()",6000);
   }


function vtAutoAdvance()
{
   if (vtUserInterrupt || --vtAutoAdvances < 0) return;
   setTimeout("vtAutoAdvance()",6000);
   vtGoRoundFwd();	
}

function vtUserFwd()
{
	vtUserInterrupt = true;
	vtGoRoundFwd();
}

function vtUserRev()
{
	vtUserInterrupt = true;
	vtGoRoundRev();
}

function vtGoRoundFwd() { 
	if (vtCarouselInMotion) return;
	vtCarouselInMotion = true;	
    $("#vtCarousel ul li:first").clone().appendTo("#vtCarousel ul");
	$("#vtCarousel ul li:first").animate({ marginLeft:-960 }, 400, shiftcompleteFwd);
   }

function vtGoRoundRev() { 
	if (vtCarouselInMotion) return;
	vtCarouselInMotion = true;	
    $("#vtCarousel ul li.promogroup:last").clone().prependTo("#vtCarousel ul");
	$("#vtCarousel ul li:first").css("margin-left","-960px").animate({ marginLeft:0 }, 400, shiftcompleteRev);
   }


function shiftcompleteFwd() {
	$("#vtCarousel ul li:first").detach();
	vtCarouselInMotion = false;
   }

function shiftcompleteRev() {
	$("#vtCarousel ul li.promogroup:last").detach();
	vtCarouselInMotion = false;
   }


