// JavaScript Document
topAdIndex = 0;
topFeatureIndex = 0;

	function processOnloadEvents() {
		beginAdRotation();
	}

	function startTopShow() { 
		topAdIndex = showNextAd(topAdIndex,topAds); 
	}
	
	function advanceFeature() {
		topFeatureIndex = showNextFeature(topFeatureIndex,topFeatures);
	}

	function hideAllAds(adArray) {
		for (var i=0; i < adArray.length; i++) {
			document.getElementById(adArray[i][0]).style.visibility="hidden";
		}
	}

	function showActiveAd(activeIndex,adArray) {
		hideAllAds(adArray); 
		activeAdLink = adArray[activeIndex][2];
		document.getElementById(adArray[activeIndex][0]).style.visibility="visible";
	}

	function showNextFeature(activeIndex, featureArray) {
		
		link = document.getElementById("featureLink");
		image = document.getElementById("featureImage");

		link.href = featureArray[activeIndex][2];
		link.title = featureArray[activeIndex][3];
		image.src = featureArray[activeIndex][1];

		interval = featureArray[activeIndex][5] * 1000;

		activeIndex++;
		if ( activeIndex >= featureArray.length) {
			activeIndex = 0;
		}	

		if (featureArray.length > 1) {
			self.setTimeout('advanceFeature()',interval);
		}

		return activeIndex;
	}

	function showNextAd(activeIndex,adArray) {
		//window.status = "activeIndex: " + activeIndex + ", adArray.length: " + adArray.length;
		showActiveAd(activeIndex,adArray);
		activeIndex++;
		if (activeIndex >= adArray.length) {
			activeIndex = 0;
		}
		
		return activeIndex;
	}
	function processFeatureClick(featureArray,activeIndex) {
		document.location = featureArray[activeIndex][2];
	}
	function processClick(adArray,activeIndex) {
		document.location = adArray[activeIndex][2];
	}
	function beginAdRotation() {
		document.getElementById("viewerLoading").style.visibility = "hidden";
		hideAllAds(topAds);
		showActiveAd(0,topAds);
		self.setInterval('startTopShow()',6000);
		advanceFeature();
	}
	
	function drawAds() {
		for (x=0; x < topAds.length; x++) {
			document.write('<div id="topAd' + x + '"><img src="' + topAds[x][1] + '" border="0"/></div>');
		}
	}

//function processOnloadEvents() {
	//remove the loading panel from the ad rotator
//	document.getElementById("viewerLoading").style.visibility = "hidden";
	//hideAllAds(topAds);
	//showActiveAd(0,topAds);
//	beginAdRotation();
//}
