var selectedHomeBannerID = 2;
var showingBannerIndex = 2; //for first time only.

function HomeBannerData(index, image, imgURL)
{

	this.isFaded = false;
	this.index = index;
	this.image = image;
	this.imgURL = imgURL;
	this.html = "";
	this.addLine = function(content) {
		this.html += (content + "\n");
	}
	this.writeBanner = function() {
		document.write(this.html);
	};

	this.addLine("<div id=\"flashHeader"+this.index+"\" style=\"width:465px;position:absolute;left:0px;top:0px;z-index:0;visibility:hidden;\">");
	this.addLine("<a href=\""+this.imgURL+"\"><img src="+this.image+" alt=\"\" title=\"\" /></a>");
	this.addLine("</div>");

}

function RotateBannerData(index)
{

	var data = bannerData[index];
	
	if (data != null) 
	{

		//alert("move banner from selected: "+selectedHomeBannerID+ " to index: "+index + " showing: "+showingBannerIndex);

		selectedHomeBannerID = index;
		
		var showing = $("#flashHeader"+showingBannerIndex);
		var toShow = $("#flashHeader"+index);

		//showing.css("display","none");
		toShow.css({"display":"none","z-index":"2","visibility":"visible"});
		toShow.fadeIn("normal", function() { 
			showing.css("z-index","0");
			//showing.css("display","none");
			toShow.css("z-index","1");
		});

		showingBannerIndex = index;
		
	}
}

function rotateBanner()
{
	var id = selectedHomeBannerID + 1;
	if (id >= bannerData.length) id = 0;
	RotateBannerData(id);
	resetBannerRotation();
}

function resetBannerRotation(){
	setTimeout('rotateBanner();',6000);
}

var bannerData = new Array(
	new HomeBannerData(0,"assets/images/pageHeader_homeBob.jpg","fiberHealth/index.shtml?bestLife"),
	new HomeBannerData(1,"assets/images/pageHeader_coupon2.jpg","specialOffers/index.shtml"),
	new HomeBannerData(2,"assets/images/homePromo_sticks_coupon.jpg","specialOffers/index.shtml")
	);

$(function(){
	rotateBanner();
});


