
//
// +---------------------------------------------------------------------+
// | TOMWALESRUN.COM                                                     |
// +---------------------------------------------------------------------+
// | wales.js                                                            |
// | js functions                                                        |
// |                                                                     |
// | Dtek Digital Media, dtek.net                                        |
// | 2006.10.03                                                          |
// |                                                                     |
// +---------------------------------------------------------------------+
//

var W3CDOM = (document.createElement && document.getElementsByTagName);

// define images that use rollovers: image element id, over/selected state image
// all over state images must end in "_o.[suffix]"
var rollovers = new Array(
	Array('mihome','img/home_o.gif'),
	Array('miregistration','img/registration_o.gif'),
	Array('midetails','img/details_o.gif')
);

var mouseovers = new Array();
var mouseouts = new Array();

// preload over state images
if (W3CDOM)
{
	for (var i = 0; i < rollovers.length; i++)
	{
		mouseovers[i] = document.createElement('img');
		mouseovers[i].setAttribute('src',rollovers[i][1]);
	}
}

// add behaviors to the images
function init()
{
	if (!W3CDOM) return;
	for (var i=0;i<rollovers.length;i++)
	{
		var el = document.getElementById(rollovers[i][0]);
		// is this image already in the selected (over) state?
		var issel = (el && el.src.substr((el.src.lastIndexOf('.')-2),2) == '_o') ? true : false;

		// only if the element exists and it's not in the selected state
		if (el && !issel)
		{
			mouseouts[i] = document.createElement('img');
			mouseouts[i].setAttribute('src',el.getAttribute('src'));
			el.number = i;
			el.onmouseover = function() {  this.src = mouseovers[this.number].src  };
			el.onmouseout = function() {  this.src = mouseouts[this.number].src  };
		}
	}
}

window.onload = init;
