var currentScrollingAd = 0;
var loadingInterval = 1;
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 shiftRight(currentDot) {
	loadingSlide = 1;
	jQuery("div.middleAdColumn").animate({marginLeft: "-866px"}, 350, function() {
		jQuery("div#slideshowNavigation > ul > li > a.activeSlide").removeClass("activeSlide");
		jQuery("div#slideshowNavigation > ul > li > a#slide"+currentDot).addClass("activeSlide");
		jQuery("div.middleAdColumn").remove();
		jQuery("div.rightAdColumn").addClass("middleAdColumn");
		jQuery("div.rightAdColumn").removeClass("rightAdColumn");
		jQuery("div.middleAdColumn").after("\n<div class=\"homeAdBlock rightAdColumn\">\n<div class=\"homeAdBlockText\">\n</div>\n<div class=\"homeAdBlockImage\">\n</div>\n<div class=\"clear\">&nbsp;</div>\n</div>");
		loadingSlide = 0;
	});
}
function shiftLeft(currentDot) {
	loadingSlide = 1;
	jQuery("div.rightAdColumn").remove();
	jQuery("div.historyCaptionRight").remove();
	jQuery("div.leftAdColumn").animate({marginLeft: "866px"}, 350, function() {
		jQuery("div#slideshowNavigation > ul > li > a.activeSlide").removeClass("activeSlide");
		jQuery("div#slideshowNavigation > ul > li > a#slide"+currentDot).addClass("activeSlide");
		jQuery("div.leftAdColumn").css("margin-left", "0");
		jQuery("div.middleAdColumn").remove();
		jQuery("div.leftAdColumn").addClass("middleAdColumn");
		jQuery("div.leftAdColumn").removeClass("leftAdColumn");
		jQuery("div.middleAdColumn").before("<div class=\"homeAdBlock leftAdColumn\">\n<div class=\"homeAdBlockText\">\n</div>\n<div class=\"homeAdBlockImage\">\n</div>\n<div class=\"clear\">&nbsp;</div>\n</div>\n");
		jQuery("div.middleAdColumn").after("\n<div class=\"homeAdBlock rightAdColumn\">\n<div class=\"homeAdBlockText\">\n</div>\n<div class=\"homeAdBlockImage\">\n</div>\n<div class=\"clear\">&nbsp;</div>\n</div>");
		loadingSlide = 0;
	});
}
function generateTab(tab) {
	largeImage = scrollingAds[tab]['slideshowImage'];
	adImage = '<img src="/imgs/slideshow/'+largeImage+'.jpg" alt="'+scrollingAds[tab]['slideshowTitle']+'" />';
	adContent = "<h2><span class=\"orangeSquare\">&nbsp;</span> "+scrollingAds[tab]['slideshowTitle']+"</h2>";
	adContent += ""+scrollingAds[tab]['slideshowText']+"";
}
function clickArrowRight() {
	if (loadingSlide == 1) { return false; }
	showLoadingGraphic();
	currentScrollingAd = currentScrollingAd + 1;
	if(currentScrollingAd == scrollingAds.length) { currentScrollingAd = 0; }
	generateTab(currentScrollingAd);
	jQuery("div.rightAdColumn").children("div.homeAdBlockImage").html(adImage);
	jQuery("div.rightAdColumn").children("div.homeAdBlockText").html(adContent);		
	var urls = [ largeImage ];
	var siteBase = location.href;
	var dotCom = siteBase.indexOf('.com');
	siteBase = siteBase.substr(0, (dotCom + 4));
	siteBase = siteBase+"/imgs/slideshow/";
	jQuery.preload( urls, {
		base: siteBase,
		ext:'.jpg',
		onComplete:function( data ) {
			var img = new Image();
			img.src = data.image;
		},
		onFinish:function() {
			shiftRight((currentScrollingAd + 1));
			jQuery("div#loadingGraphic").hide();	
		}
	});
}
function clickArrowLeft() {
	if (loadingSlide == 1) { return false; }
	showLoadingGraphic();
	currentScrollingAd = currentScrollingAd - 1;
	if(currentScrollingAd < 0) { currentScrollingAd = scrollingAds.length - 1; }
	generateTab(currentScrollingAd);
	jQuery("div.leftAdColumn").children("div.homeAdBlockImage").html(adImage);
	jQuery("div.leftAdColumn").children("div.homeAdBlockText").html(adContent);	
	var urls = [ largeImage ];
	var siteBase = location.href;
	var dotCom = siteBase.indexOf('.com');
	siteBase = siteBase.substr(0, (dotCom + 4));
	siteBase = siteBase+"/imgs/slideshow/";
	jQuery.preload( urls, {
		base: siteBase,
		ext:'.jpg',
		onComplete:function( data ) {
			var img = new Image();
			img.src = data.image;
		},
		onFinish:function() {
			shiftLeft((currentScrollingAd + 1));
			jQuery("div#loadingGraphic").hide();
		}
	});
}