// \s*\S\s*\/\/.+\.$
// WBAdGoRound.action v3.0.4 - October, 2008
// Copyright © 1999 by Walter Blady
// All rights reserved
var AGRExposure = 0, AGRAction = null, AGRObjectArray = new Array(), AGRad;
var AGRW3C = document.getElementById ? true : false;
//var AGRisNav4 = navigator.appName.indexOf("Netscape") >= 0 && parseInt(navigator.appVersion.charAt(0)) == 4;.
//var AGRisIE4 = navigator.appVersion.indexOf("MSIE 4") >= 0;.
//var AGRisIE = navigator.appVersion.indexOf("MSIE") >= 0;.
//.........................................................................................
//Main function.
function WBAdGoRound(action) {
	if (AGRVersion()) {
		try {
			AGRSize1();
		}
		catch (errorCode) {
			var mess = "WBAdGoRound can not find the AGRAd.js file.\n";
			mess += "You must link the AGRAd.js file, inside your site folder, to this page."
			alert(mess);
			return;
		}
		AGRAction = action;
		for (var i = 1; (action[i+1] != "" || action[i+2] != "") && i <= 25; i=i+6) {
			if (action[i+1] != "") {
				//Get box object.
				var adObject = AGRGetObject(action[i+1]);
				adObject.type = "box";
			}
			//Get image object.
			else if (action[i+2] != "") {
				//Get image object for IE or W3C.
				if (window.navigator.userAgent.indexOf("MSIE") > 0 || AGRW3C) {
					var adObject = document.images[action[i+2]];
				}
				//...else get image object for NN3.
				else {
					var adObject = parseInt(navigator.appVersion.charAt(0)) > 3 ? AGRFindImageObject(action[i+2],0) : document.images[action[i+1]];
				}
				adObject.type = "image";
			}
			adObject.saction = action;
			adObject.sadGroup = action[i];
			adObject.sexposure = parseInt(action[i+3]);
			adObject.srandom = action[i+4];
			adObject.sloops = action[i+5];
			adObject.sadPointer = 1;
			//Count the number of ads.
			for (var count = 1; eval("AGRAd" + (adObject.sadGroup + 1) + "_" + count + "()").toLowerCase() != "end"; count++) { }
			count -= 1;
			adObject.snumberOfAds = count;
			adObject.isswf = false;
			//Display Function property.
			adObject.sdisplay = AGRDisplay;
			//URL Function property onmousedown.
			adObject.onmousedown = AdGoRoundLinks;
			//Generate a random ad location the first time through.
			if (adObject.srandom) {
				adObject.sadPointer = (Math.floor((Math.random() * 10000)) % (adObject.snumberOfAds));
				adObject.sadPointer = adObject.sadPointer == 0 ? adObject.snumberOfAds : adObject.sadPointer;
			}
			//If this Ad timer is not running, start it up.
			if (!adObject.srunning) {
				adObject.srunning = true;
				//Trigger this ad.
				adObject.sdisplay();
			}
		}
	}
	//If a visitor time limit for this page is set.
	if (parseInt(action[31]) > 0) var AGRlimit = setTimeout("AGRVisitorLimit()", parseInt(action[31])*1000*60);
	return;
}
//.........................................................................................
function AGRDisplay() {
	if (this.sadPointer > this.snumberOfAds) {
		this.sadPointer = 1;
	}
	//Get the next ad and URL in this ad group.
	//Trigger the default size function in this ad group.
	var size = eval("AGRSize" + (this.sadGroup + 1) + "()");
	this.sad = eval("AGRAd" + (this.sadGroup + 1) + "_" + this.sadPointer + "()");
	this.surl = AGRAdURL;
	//If there is an ad.
	if (this.sad != "") {
		//Set up the ad width and height.
		this.height = AGRHeight == 0 ? AGRdefaultHeight : AGRHeight;
		this.width = AGRWidth == 0 ? AGRdefaultWidth : AGRWidth;
		//If this is not a Flash swf file.
		if (this.type == "box") {
			if (this.sad.indexOf("swf") == -1) {
				var html = "<img src='" + this.sad + "' alt='' height='" + this.height + "' width='" + this.width + "' border='0'>";
				this.isswf = false;
			}
			//If this is a Flash swf file.
			else if (this.sad.indexOf("swf") > -1) {
				var html = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" height="' + this.height + '" width="' + this.width + '"> ';
				html +=	'<param name="movie" value="' + this.sad + '"> ';
				html +=	'<param name="quality" value="best"> ';
				html +=	'<param name="play" value="true">';
				html +=	'<embed height="' + this.height + '" width="' + this.width + '" pluginspage="http://www.macromedia.com/go/getflashplayer" src="' + this.sad + '" type="application/x-shockwave-flash" quality="best" play="true" loop="' + this.sloops + '"> ';
				html +=	'</object>';
				this.isswf = true;
			}
			//Write the new innerHTML.
			if (document.getElementById) {
				//if (AGRisIE) var delay = setTimeout("AGRDelayswf()", 300);.
				this.innerHTML = html;
			}
			//If IE4 skip past the swf files but write the image files.
			else if (document.all) {
				if (this.isswf) {
					this.sexposure = 0;
				}
				else {
					this.innerHTML = "";
					this.innerHTML = html;
					//this.innerHTML = "";.
					//this.insertAdjacentHTML("afterBegin", html);.
				}
			}
			//If NN4 skip past the swf files but write the image files.
			else if (document.layers) {
				if (this.isswf) {
					this.sexposure = 0;
				}
				else {
					this.clip.width = this.width;
					this.clip.height = this.height;				
					this.background.src = this.sad;
				}
			}
		}
		else if (this.type == "image") {
			//Display the ad.
			this.src = this.sad;
		}
		//Get the exposure time.
		if (AGRExposure > 0) {
			this.sexposure = AGRExposure;
		}
	}
	//AGRadDisplayer = "AGRNextAd" + this.adGroup + "()";.
	var t = setTimeout("AGRNextAd" + this.sadGroup + "()", this.sexposure*1000);
	//Increment the ad pointer and prepare for the next ad.
	this.sadPointer++;
	AGRObjectArray[this.sadGroup+1] = this;
	return;
}
//.........................................................................................
// Exposure for the 1st ad.
function AGRNextAd0() {
	//Re-call the main routine and start timing again for the next ad.
	AGRObjectArray[1].sdisplay();
	return;
}
// Exposure for the 2nd ad.
function AGRNextAd1() {
	//Re-call the main routine and start timing again for the next ad.
	AGRObjectArray[2].sdisplay();
	return;
}
// Exposure for the 3rd ad.
function AGRNextAd2() {
 	//Re-call the main routine and start timing again for the next ad.
	AGRObjectArray[3].sdisplay();
	return;
}
// Exposure for the 4th ad.
function AGRNextAd3() {
	//Re-call the main routine and start timing again for the next ad.
	AGRObjectArray[4].sdisplay();
	return;
}
// Exposure for the 5th ad.
function AGRNextAd4(action) {
	//Re-call the main routine and start timing again for the next ad.
	AGRObjectArray[5].sdisplay();
	return;
}
// Exposure for the 6th ad.
function AGRNextAd5(action) {
	//Re-call the main routine and start timing again for the next ad.
	AGRObjectArray[6].sdisplay();
	return;
}
// Exposure for the 7th ad.
function AGRNextAd6() {
	//Re-call the main routine and start timing again for the next ad.
	AGRObjectArray[7].sdisplay();
	return;
}
// Exposure for the 8th ad.
function AGRNextAd7() {
	//Re-call the main routine and start timing again for the next ad.
	AGRObjectArray[8].sdisplay();
	return;
}
// Exposure for the 9th ad.
function AGRNextAd8(action) {
	//Re-call the main routine and start timing again for the next ad.
	AGRObjectArray[9].sdisplay();
	return;
}
// Exposure for the 10th ad.
function AGRNextAd9(action) {
	//Re-call the main routine and start timing again for the next ad.
	AGRObjectArray[10].sdisplay();
	return;
}
//.........................................................................................
//Build the parameter string for either IE or NN.
function AGRGetObject(objName) {
	var params;
	//Get image object for IE or W3C.
	if (document.getElementById) {
		params = eval("document.getElementById('" + objName + "')");
	}
	else if (document.all) {
		params = eval("document.all." + objName);
	}
	else if (document.layers) {
		params = AGRFindLayerObject(objName, 0);
	}
	return params;
}
// Search all NN layers for the specified layer object.
function AGRFindLayerObject(layer, thisLayer) {
	if (thisLayer) {
		var thisDocument = thisLayer.document;
	}
	else {
		var thisDocument = document;
	}
	var layerObj = thisDocument[layer];
	if (layerObj) {
		return layerObj;
	}
	else {
		for (var i = 0; i < thisDocument.layers.length; i++) {
			layerObj = AGRFindLayerObject(layer, thisDocument.layers[i]); 
			if (layerObj) {
				break;
			}
		}
	}
	return layerObj;
}
//.........................................................................................
// Locate image object.
function AGRFindImageObject(baseImage, thisLayer) { 
	//Try this layer object.
	if (thisLayer) {
		var thisDocument = thisLayer.document;
	}
	else {
		var thisDocument = document;
	}
	//Is the image object on this layer.
	var imageObj = thisDocument[baseImage];
	//If not, loop through all the layer objects.
	if (imageObj) {
		return imageObj;
	}
	else {
		for (var i = 0; i < thisDocument.layers.length; i++) {
			imageObj = AGRFindImageObject(baseImage, thisDocument.layers[i]); 
			if (imageObj) {
				break;
			}
		}
	}
	return imageObj;
}
//.........................................................................................
//Time limit redirect URL.
function AGRVisitorLimit() {
	var url = AGRAction[32];
	if (url != "" && url != "#") {
		var params;
		if (AGRAction[33].length < 1) {
			window.location.href = url;
		}
		else {
			if (AGRAction[33].toLowerCase().indexOf("blank") != -1) {
				var ACNewWindow = window.open(url,"newWindow", "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,personalbar=yes,scrollbars=yes,favorites=yes,resizable=yes");
				return;
			}
			else {
				params = eval(AGRAction[33] + ".window.location");
			}
			params.href = url;
		}
	}
	return;
}
//.........................................................................................
function AdGoRoundLinks() {
	//If there is a URL.
	if (this.surl != "") {
		var params;
		//If no target, open in same window.
		if (this.saction[34] == "") {
			window.location.href = this.surl;
		}
		//else if target.
		else {
			//If new window called for.
			if (this.saction[34].toLowerCase().indexOf("blank") != -1) {
				//Prepare the window properties..
				var params = "";
				var top = "";
				var left = "";
				//If window location in top left.
				if (this.saction[46] == 1) {						
					top = this.saction[37] <= screen.availHeight ? this.saction[47] : 0;
					left = this.saction[36] <= screen.availWidth ? this.saction[48] : 0;
				}
				//If window locaton is centered.
				else if (this.saction[46] == 2) {
					top = Math.round(screen.availHeight-this.saction[47])/2;
					left = Math.round(screen.availWidth-this.saction[48])/2;
				}
				var newWidth = document.body.clientWidth;
				var newHeight = document.body.clientHeight;
				//If window size in pixels.
				if (this.saction[35] == 1) {
					var newWidth = (this.saction[36] > 0 && this.saction[36] <= screen.availWidth) ? this.saction[36] : screen.availWidth;
					var newHeight = (this.saction[37] > 0 && this.saction[37] <= screen.availHeight) ? this.saction[37] : screen.availHeight;
					//newWidth = (this.action[36] <= screen.availWidth) ? this.action[36] : screen.availWidth;.
					//newHeight = (this.action[37] <= screen.availHeight) ? this.action[37] : screen.availHeight;.
				}
				//Percentage of max screen size.
				else if (this.saction[35] == 2) {
					newWidth = (this.saction[36]*screen.availWidth/100 <= screen.availWidth) ? Math.round(this.saction[36]*screen.availWidth/100) : screen.availWidth;
					newHeight = (this.saction[37]*screen.availWidth/100 <= screen.availHeight) ? Math.round(this.saction[37]*screen.availWidth/100) : screen.availHeight;
				}
				//If window size is maximum.
				else if (this.saction[35] == 3) {
					newWidth = screen.availWidth;
					newHeight = screen.availHeight;
				}
				params += "width=" + newWidth;
				params += ",height=" + newHeight;
				params += ",toolbar=" + (this.saction[38] ? "1" : "0");
				params += ",location=" + (this.saction[39] ? "1" : "0");
				params += ",directories=" + (this.saction[40] ? "1" : "0");
				params += ",status=" + (this.saction[41] ? "1" : "0");
				params += ",menubar=" + (this.saction[42] ? "1" : "0");
				params += ",favorites=" + (this.saction[43] ? "1" : "0");
				params += ",scrollbars=" + (this.saction[44] ? "1" : "0");
				params += ",resizable=" + (this.saction[45] ? "1" : "0");
				params += (AGRW3C) ? ",top=" + top + ",left=" + left : ",screenY=" + top + ",screenX=" + left;
				var AGRLNewWindow = window.open(this.surl,"AGRNewWindow", params);
				return;
			}
			//Open in frame.
			else {
				params = eval(this.saction[34] + ".window.location");
				params.href = this.surl;
			}
		}
	}
	return;
}
//.........................................................................................
// Browser check.
function AGRVersion() {
	return true;
}
//
