/* class names used for JS events in this file are
 * 
 * roller
 * roll
 * button
 * 
 * */

var rollovers = 
{
	activatingElement : "a",
	multiples : "",
	classNames: "roller",  // comma seperated list of class names that we want to put the rollover onto.
	swapIndicator: "_on", // the name of the rollover state image should follow a convention of sorts - indicated here
						 // eg : my_image.gif -rollover-> my_image_on.gif
	swapImages : function(theImage) // accepts an image and alters the source to reflect the rollover state images src.	
		{
			var src,ftype,newsrc
			src = theImage.src
			ftype = src.substring(src.lastIndexOf('.'),src.length);
				theExp = new RegExp(this.swapIndicator);
			 if(theExp.test(src))  // test to see if the image is in a "rolled over" state
			 {
  			  newsrc = src.replace(this.swapIndicator,'');
			 }else{
			// else, add the _on to the src 
			  newsrc = src.replace(ftype, this.swapIndicator+ftype);
			 }
			 theImage.src=newsrc;
		}, 
	setrollovers : function()
		{ 
			var elems,i,classes,ii;
			elems = document.getElementsByTagName(this.activatingElement);
			classes = this.classNames.split(",");	
			for (ii=0;ii<classes.length;ii++)
			{ theExp = new RegExp("(^|\\s)" + classes[ii] + "(\\s|$)");
				for (i=0;i<elems.length;i++)
				{
				   if (theExp.test(elems[i].className))
				   {
				   if (this.multiples != "")
				   {
				   elems[i].onmouseover = function(){rollovers.swapImages(this);};
				   elems[i].onmouseout = function(){rollovers.swapImages(this);};
				   }
				   else
				   {
				   elems[i].onmouseover = function(){rollovers.swapmultiples(this);};
				   elems[i].onmouseout = function(){rollovers.swapmultiples(this);};
				   }
				   }
				}
			}
		},
	setbuttons : function()
	 {
             var classes = 'roll';
             var elems,i;
             var theExp = new RegExp("(^|\\s)" + classes + "(\\s|$)");
             elems = document.getElementsByTagName('img');
              for (i=0;i<elems.length;i++)
              {
                if (theExp.test(elems[i].className))
                {
				   elems[i].onmouseover = function(){rollovers.swapImages(this);};
				   elems[i].onmouseout = function(){rollovers.swapImages(this);};
                }
              }
             elems = document.getElementsByTagName('input');
              for (i=0;i<elems.length;i++)
              {
                if (theExp.test(elems[i].className))
                {
				   elems[i].onmouseover = function(){rollovers.swapImages(this);};
				   elems[i].onmouseout = function(){rollovers.swapImages(this);};
                }
              }
              
	 },
	swapmultiples : function(activator)
	 {
	 		// activator should be the link itself - so we're going to grab the images inside the
	 		// activating link
	 		if (activator)
	 		{ 
	 			 var the_images = activator.getElementsByTagName('img');
					for (i=0;i<the_images.length;i++)
					{
					this.swapImages(the_images[i]);
					}
	 		}
	 },
	swapButton : function () {
		 var theButton = arguments[0];
		 var theImage = theButton.firstChild;
			 ftype = theImage.src.substring(theImage.src.lastIndexOf('.'),theImage.src.length);		 
			 theExp = new RegExp(this.swapIndicator);
			 if(theExp.test(theImage.src))  // test to see if the image is in a "rolled over" state
			 {
  			  newsrc = theImage.src.replace(this.swapIndicator,'');
			 }else{
			// else, add the _on to the src 
			  newsrc = theImage.src.replace(ftype, this.swapIndicator+ftype);
			 }
			 theImage.src=newsrc;		 	 
	},
	setButtons : function()
	{ // sets rollovers on Button Elements
		var buttons = document.getElementsByTagName('button');
		for (x=0;x<buttons.length;x++)
		{
		  buttons[x].onmouseover = function(){rollovers.swapButton(this);};
		  buttons[x].onmouseout = function(){rollovers.swapButton(this);};
		  if(buttons[x].firstChild)
		  {
		  	buttons[x].firstChild.onmouseover = '';
		  	buttons[x].firstChild.onmouseout = '';
		  	buttons[x].firstChild.className = '';
		  }
		}
	}
}

// To cover IE 5.0's lack of the push method
Array.prototype.push = function(value) {
  this[this.length] = value;
}



if(typeof preRollovers == 'undefined') {
 preRollovers = window.onload ? window.onload : function(){};
 window.onload = function() {
	 preRollovers();
	 rollovers.setrollovers();
	 rollovers.setbuttons();
 }
}
