if (typeof(Sys) == "undefined")
{
//	alert(window.location.pathname + " says: Registering BrowserUtil.js because my developer forgot to.");
	document.writeln("<scr" + "ipt src=\"/js/BrowserUtil.js\" type=\"text/javascript\"></script>");
}

function AssetRoller(instanceName, onChangeFunction)
{
	this.assetManager = new Array();
	this.currentAssetIndex = -1;
	this.instanceName = instanceName;
	this.timeoutId = null;
	this.containerElement = null;
	this.displayDuration = null;
	this.onChangeFunction = (onChangeFunction) ? onChangeFunction : null;
}

AssetRoller.prototype.setDisplayDuration = function(seconds)
{
	this.displayDuration = seconds;
}

AssetRoller.prototype.addAsset = function(assetObj, displayDuration)
{
	assetObj.displayDuration = (displayDuration) ? displayDuration : this.displayDuration;
	this.assetManager[this.assetManager.length] = assetObj;
	this.assetManager[assetObj.propertyName] = assetObj;//add as property
}

AssetRoller.prototype.start = function()
{
	if(this.timeoutId) clearTimeout(this.timeoutId);
	this.changeAsset(this);
	
	if (Sys.Browser.agent == Sys.Browser.InternetExplorer)
		event.returnValue = false;
	
	return false;
}

AssetRoller.prototype.stop = function()
{
	if(this.timeoutId) clearTimeout(this.timeoutId);
	
	if (Sys.Browser.agent == Sys.Browser.InternetExplorer)
		event.returnValue = false;
	
	return false;
}

AssetRoller.prototype.addToElement = function(elementId)
{
	this.containerElement = document.getElementById(elementId);
	this.anchorElement = document.createElement("A");
	this.anchorElement.href = "";
	this.anchorElement.onclick = function()
	{
		if (Sys.Browser.agent == Sys.Browser.InternetExplorer)
			event.returnValue = false;
		
		return false;
	}
	this.imageElement = document.createElement("IMG");
	this.imageElement.setAttribute("border", 0);
	this.imageElement.setAttribute("src", "");
	this.anchorElement.appendChild(this.imageElement);
	this.containerElement.appendChild(this.anchorElement);
}

AssetRoller.prototype.changeAsset = function()
{
	this.currentAssetIndex = (this.currentAssetIndex < this.assetManager.length-1) ? this.currentAssetIndex + 1 : 0;
	this.currentAsset = this.assetManager[this.currentAssetIndex];
	AssetRoller.displayAsset(this);
}

//Class Methods
AssetRoller.displayAsset = function(instanceName)
{
	var instance = instanceName;
	instance.imageElement.setAttribute("src", instance.currentAsset.image.src);
	if(instance.currentAsset.url)
	{
		instance.anchorElement.setAttribute("href", instance.currentAsset.url);
		instance.anchorElement.setAttribute("title", instance.currentAsset.propertyName);
		instance.anchorElement.style.cursor = "pointer";
		instance.anchorElement.onclick = function()
		{
			exitTracker(instance.currentAsset.url);
			
			if (Sys.Browser.agent == Sys.Browser.InternetExplorer)
				event.returnValue = false;
			
			return false;
		}
	}
	else
	{
		instance.anchorElement.setAttribute("href", "");
		instance.anchorElement.setAttribute("title", instance.currentAsset.propertyName);
		instance.anchorElement.style.cursor = "default";
		instance.anchorElement.onclick = function()
		{
			if (Sys.Browser.agent == Sys.Browser.InternetExplorer)
				event.returnValue = false;
		
			return false;
		}
	}
	if(instance.currentAsset.displayDuration)
	{
		instance.timeoutId = setTimeout(instance.instanceName + ".changeAsset()", instance.currentAsset.displayDuration * 1000);
		if(instance.onChangeFunction) instance.onChangeFunction();
	}
}


//Begin Asset object	
function Asset(propertyName)
{
	this.propertyName = propertyName;
	this.image = null;
	this.url = null;
}

Asset.prototype.setImage = function(imagePath)
{
	this.image = new Image();
	this.image.src = imagePath;
	return this.image;
}

Asset.prototype.getImage = function()
{
	return this.image;
}

Asset.prototype.setUrl = function(url)
{
	this.url = url;
}

Asset.prototype.getUrl = function()
{
	return this.url;
}
