// THIS SCRIPT HANDLES ALL ROLLOVERS ON THE SITE.

// THIS DOES NOT NEED TO BE MODIFIED WHEN MAKING UPDATES TO THE SITE.



function RolloverEngine(pat)

{	if(pat && pat != null)

		this.pattern = (typeof pat == "string") ? new RegExp(pat) : pat;

	else this.pattern = null;	

	

	RolloverEngine.images = new ImageCollection();

	this.ready = false;

	this.findImages();

	this.ready = true;

					

	return this;

}



RolloverEngine.prototype.findImages = function(doc)

{	if(!doc) doc = window.document;

	

	if(doc.images.length > 0)

	{	var img, a, b;

		for(a = 0; a < doc.images.length; a++)

		{	img = doc.images[a];

			if(img.name){

				if(this.pattern == null || this.pattern.test(img.name))

					this.loadImage(img);

			}

		}

	}

	if(doc.layers && doc.layers != null)

	{	if(doc.layers.length > 0)

		{	for(b = 0; b < doc.layers.length; b++)

			{	this.findImages(doc.layers[b].document);

			}

		}

	}

}



RolloverEngine.prototype.loadImage = function(img){

	if(img && img != null && img.src)

	{	lastSlash = img.src.lastIndexOf("/");

		if(lastSlash == -1) lastSlash = 0;

	

		lastDot = img.src.lastIndexOf(".");

		if(lastDot == -1) lastDot = img.src.length;

		

		imgLoc = (lastSlash > 0) ? img.src.substring(0, lastSlash + 1) : new String("");

		baseName = img.src.substring(lastSlash + 1, lastDot);

		ext = img.src.substring(lastDot, img.src.length);



		// fix for old _off naming

		offIndex = baseName.lastIndexOf("_off");

		if(offIndex != -1) baseName = baseName.substring(0, offIndex);

		

		img.off = new Image();

		img.off.src = img.src;

		img.over = new Image();

		img.over.src = imgLoc + baseName + "_over" + ext;

		img.on = new Image();

		img.on.src = imgLoc + baseName + "_on" + ext;

							

		RolloverEngine.images.addImage(img);

	}

}



RolloverEngine.prototype.containsImage = function(strName)

{	return (strName && strName != null) ? (RolloverEngine.images[strName] && RolloverEngine.images[strName] != null) : false;

}



RolloverEngine.prototype.getImage = function(strName)

{	return (this.containsImage(strName)) ? RolloverEngine.images[strName] : null;

}



RolloverEngine.prototype.setOff = function(strName)

{	img = this.getImage(strName);

	if(img && img != null && this.ready && !img.locked) img.src = img.off.src;

}



RolloverEngine.prototype.setOver = function(strName)

{	img = this.getImage(strName);

	if(img && img != null && this.ready && !img.locked) img.src = img.over.src;

}



RolloverEngine.prototype.setOn = function(strName)

{	img = this.getImage(strName);

	if(img && img != null && this.ready && !img.locked) img.src = img.on.src;

}



RolloverEngine.prototype.setAllOff = function()

{	if(this.ready)

	{	for(a = 0; a < RolloverEngine.images.countImages(); a++)

		{	img = RolloverEngine.images.imageAt(a);

			if(!img.locked) img.src = img.off.src;

		}

	}

}



RolloverEngine.prototype.isOff = function(strName)

{	img = RolloverEngine.images[strName];

	return (img && img != null && img.src == img.off.src);

}



RolloverEngine.prototype.isOver = function(strName)

{	img = RolloverEngine.images[strName];

	return (img && img != null && img.src == img.over.src);

}



RolloverEngine.prototype.isOn = function(strName)

{	img = RolloverEngine.images[strName];

	return (img && img != null && img.src == img.on.src);

}



RolloverEngine.prototype.lock = function(strName)

{	img = RolloverEngine.images[strName];

	if(img && img != null) img.locked = true;

}



RolloverEngine.prototype.lockAll = function()

{	for(i = 0; i < RolloverEngine.images.countImages(); i++)

	{	RolloverEngine.images.imageAt(i).locked = true;

	}

}



RolloverEngine.prototype.unlock = function(strName)

{	img = RolloverEngine.images[strName];

	if(img && img != null) img.locked = false;

}



RolloverEngine.prototype.unlockAll = function()

{	for(j = 0; j < RolloverEngine.images.countImages(); j++)

	{	RolloverEngine.images.imageAt(j).locked = false;

	}

}



RolloverEngine.prototype.isLocked = function(strName)

{	img = RolloverEngine.images[strName];

	return (img && img != null && img.locked && img.locked == true);

}



RolloverEngine.prototype.setSrc = function(strName, path)

{		 img = this.getImage(strName);

		 if(img && img != null && this.ready) img.src = path;

}



RolloverEngine.prototype.getSrc = function(strName)

{		 img = this.getImage(strName);

		 return img.src;

}



RolloverEngine.prototype.toString = function()

{	return "[object RolloverEngine]";

}



function ImageCollection() 

{	this.images = new Array();

}



ImageCollection.prototype.addImage = function(img)

{	if(img && img != null && img.name)

	{	this.images[this.images.length++] = img;

		eval("this." + img.name + " = img;");

	}

}



ImageCollection.prototype.imageAt = function(index)

{	return (index >= 0 && index < this.images.length) ? this.images[index] : null;

}



ImageCollection.prototype.countImages = function()

{	return this.images.length;

}



ImageCollection.prototype.toString = function()

{	return "[object ImageCollection]";

}

