
var fData = {
	//depends on slide show configuration located in franchise-navigation.vm
	makes : new Array(),
	makeIndex : 0,
	cnt : 1,
	sticky : false,
	timer : null,
	preloadImg : new Image(),
	IFcurrent : 0,
	IFlast : 0,
	vehiclePhotosPerLifestyle : 0, //number of vehicle photos per lifestyle image, set automatically in init

	vCounter : {
		IFcurrent : 0,
		IFlast : 13
	},

	init : function() {
		$('#opacityLayer').fadeIn(400,fData.preload);
		fData.vCounter.IFlast = $('ul#vehicleSlides li').length-1; //last element in vehicle set

		var franchiseCount = 0;
		for (var franchise in sites) { //add the franchises that are setup
			fData.makes.push(franchise);
			franchiseCount++;
		}
		
		fData.makes.sort(); //sort the makes so they correspond correctly with the franchise list
		//set the number of vehicle photos per franchise lifestyle
		fData.vehiclePhotosPerLifestyle = fData.vCounter.IFlast = $('ul#vehicleSlides li').length / franchiseCount;

		$($("#vehicleSlides li").get(fData.vCounter.IFlast)).load(fData.preload);
	},
	preload : function() {
		fData.next();
		$("#vehicleSlideWrap").fadeIn();
		$('#opacityLayer').html('').fadeOut(500);
	},

	next : function() {
		clearTimeout(fData.timer);
		if( fData.vCounter.IFcurrent == 12 ) { //skip preowned store
			fData.vCounter.IFcurrent+=fData.vehiclePhotosPerLifestyle;
			fData.IFcurrent++;
		}

		if (fData.sticky) {
			for(i=0;i<fData.makes.length;i++) { //handle positioning to selected make
				if(fData.makes[i] == fData.sticky) {
					fData.vCounter.IFcurrent = i*fData.vehiclePhotosPerLifestyle;
					fData.IFcurrent = i;
				}
			}
			if(fData.vCounter.IFcurrent < 0) {fData.vCounter.IFcurrent = 0;fData.IFcurrent=0;}
		}

		if(fData.vCounter.IFcurrent%fData.vehiclePhotosPerLifestyle==0)
			$.innerfade.next($("#perspectiveSlides").children(),{ speed:'normal', type:'sequence' }, fData.IFcurrent, fData.IFlast, fData);

		$.innerfade.next($("#vehicleSlides").children(),{ speed:'normal', type:'sequence' }, fData.vCounter.IFcurrent, fData.vCounter.IFlast, fData.vCounter);

		if (!fData.sticky) {
			clearTimeout(fData.timer);
			fData.timer = setTimeout(fData.next,slideShowConfiguration.delay);
		}
	}
};

$(function(){
	setTimeout(fData.init,81);
});
