var currentSlide = 0; var fadeTo = 1; var fadeSource = 'Back'; var transitionTime = 0; var loadingInterval = 1;
function shiftSlide(fadeTo, transition) {
	if(transition == 'fade') { transitionTime = 1000; }
	else if(transition == 'instant') { transitionTime = 0; }
	loadingSlide = 1;
	jQuery("#homeSlideshowFront").fadeTo(transitionTime, fadeTo+'.0', function() {
		loadingSlide = 0;
	});
}
function showLoadingGraphic() {
	jQuery("div#loadingGraphic").show();
	if(jQuery("div#loadingGraphic").is(":visible")) { setTimeout("animateLoadingGraphic()", 75); }
	else { jQuery("div#loadingGraphic").children("div").css("top", "0"); return; }
}
function animateLoadingGraphic() {
	jQuery("div#loadingGraphic").children("div").css('top', (loadingInterval * -40) + 'px');
	loadingInterval = (loadingInterval + 1) % 12;
	if(jQuery("div#loadingGraphic").is(":visible")) { showLoadingGraphic(); }
}
function generateTab(tab) {
	largeImage = slideshow[tab]['image'];
	imageAlt = slideshow[tab]['alt'];
	slideshowImage = '<img src="/imgs/home/'+largeImage+'.jpg" alt="'+imageAlt+'" />';
}
function clickArrow(direction, transition) {
	if (loadingSlide == 1) { return false; }
	showLoadingGraphic();
	if(direction == 'right') {
		currentSlide = currentSlide + 1;
		if(currentSlide == slideshow.length) { currentSlide = 0; }
	}
	else if(direction == 'left') {
		currentSlide = currentSlide - 1;
		if(currentSlide < 0) { currentSlide = slideshow.length - 1; }
	}
	generateTab(currentSlide);
	if(fadeTo == 1) { fadeTo = 0; fadeSource = 'Back'; }
	else if(fadeTo == 0) { fadeTo = 1; fadeSource = 'Front'; }
	jQuery("#homeSlideshow"+fadeSource).html(slideshowImage);
		
	var urls = [ largeImage ];
	var siteBase = location.href;
	var dotCom = siteBase.indexOf('.com');
	siteBase = siteBase.substr(0, (dotCom + 4));
	siteBase = siteBase+"/imgs/home/";
	jQuery.preload( urls, {
		base: siteBase,
		ext:'.jpg',
		onComplete:function( data ) {
			var img = new Image();
			img.src = data.image;
		},
		onFinish:function() {
			shiftSlide(fadeTo, transition);
			jQuery("div#loadingGraphic").hide();
		}
	});
}
