
/*
    This script will automatically attach event handlers to 
    the 'mouseover' and 'mouseout' events for image buttons
    and image hyperlinks (<a><img /></a>) given the following:
    
    1. The elements have "rollover" specified in the class name.
    2. The following naming convention is used:
       a. [[image name]]"_0.*" - default image, name must end with "_0"
       b. [[image name]]"_1.*" - hover image, name must end with "_1"
    
    NOTE: This script was enhanced from the EasyMouseOver library.
    NOTE: This script depends on getElementsByClassName from Utils.js
*/
function Rollover()
{
    var t = this;
    
	t.AttachEvents = function(tag)
	{
		var e = document.getElementsByClassName("rollover", tag);
		for (var i = 0; i < e.length; i++)
		{
			var img = (e[i].tagName.toUpperCase() == "INPUT") ? e[i] : e[i].getElementsByTagName("IMG")[0];
			if (img)
			{
				e[i].img = img;
				
				var tmp = new Image();
				tmp.src = loadImage(e[i], 0, 1);
				
				e[i].onmouseover = function() { loadImage(this, 1, 1) };
				e[i].onmouseout = function() { loadImage(this, 0, 1) };
			}
		}
	}
	
	t.Initialize = function()
	{
		t.AttachEvents('A');
		t.AttachEvents('INPUT');
	}
	
	t.Select = function(className, tag)
	{
        var e = document.getElementsByClassName(className, tag)[0];
        if (e != null)
        {
			var img = (e.tagName.toUpperCase() == "INPUT") ? e : e.getElementsByTagName("IMG")[0];
			if (img)
			{
			    var tmp = new Image();
                tmp.src = img.src.replace("_0", "_2");
                
                img.src = tmp.src;
                img.init = true;
            }
        }
	}
}


/* 
    This method will toggle two images which adhere to the
    naming conventions defined above. It is also used to preload
    the alternate images during the intialization routine.
    
    This method was removed from the main object so that 
    a reference to the client script variable would not have 
    to be incorporated into the ImageRollover object.
*/
function loadImage(obj, state, swap)
{
    if (typeof(obj.img) == 'undefined') return;
    
	var over = "_1.";
	var out = "_0.";
	
	var url = obj.img.src;
	url = (url.indexOf(over) != -1) ? url.replace(over, out) : url.replace(out, over);
	
	if (swap)
	{
		if (state == 1 || state == 0 && obj.init)
		{
			obj.img.src = url;
		}
		obj.init = true;
	}
	
	return url;
}


/* 
    Since the object is initialized here the script 
    must be added at the bottom of the page. 
*/
var rollover = new Rollover();
rollover.Initialize();