/*
	Standards Compliant Rollover Script
	Author : Daniel Nolan
	http://www.bleedingego.co.uk/webdev.php

	Modifications by Daniel Bondard (bleedingegorollover at-nospam-wandforge.com): added sync image, added 3-state buttons.
	Modification for partial class matching (className.match()) by John Wright.
	Modification for the 'back button' bug, by reid http://www.reiddurbin.com/
	Modification for safe onload suggested by John Wright, from http://javascript.about.com

*/

function initRollovers() 
{
	if (!document.getElementById)
		return;
	
	var aPreLoad = new Array();
	var aPreLoadD = new Array();		// 3-state
	var aPreLoadS = new Array();		// sync 
	var aPreLoadSD = new Array();		// sync 3-state
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) 
	{
		if (aImages[i].className.match('imgover'))
		{
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_o'+ftype);		// o = over
			var dsrc = src.replace(ftype, '_d'+ftype); 		// 3-state: d = down

			aImages[i].setAttribute('hsrc', hsrc);
			aImages[i].setAttribute('dsrc', dsrc);
			aImages[i].setAttribute('imgsync', 'none'); 	// sync
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			aPreLoadD[i] = new Image(); 					// 3-state
			aPreLoadD[i].src = dsrc;

			if (aImages[i].name != '')						// sync
			{
				syncImageName = aImages[i].name + '_sync';
				syncImage = document[syncImageName];

				if (syncImage.className.match('imgsync'))
				{
					var srcSync = syncImage.getAttribute('src');
					var ftypeSync = srcSync.substring(srcSync.lastIndexOf('.'), srcSync.length);
					var hsrcSync = srcSync.replace(ftypeSync, '_o'+ftypeSync);
					var dsrcSync = srcSync.replace(ftypeSync, '_d'+ftypeSync); 	// 3-state

					aPreLoadS[i] = new Image();
					aPreLoadS[i].src = hsrcSync;
					aPreLoadSD[i] = new Image();
					aPreLoadSD[i].src = dsrcSync;

					aImages[i].setAttribute('imgsync', syncImage.name);

					syncImage.setAttribute('hsrcSync', hsrcSync);
					syncImage.setAttribute('dsrcSync', dsrcSync);
				}
			}

			aImages[i].onmouseover = function() 
			{
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));

				if (this.getAttribute('imgsync') != 'none')		// sync
				{
					syncImage = document[this.getAttribute('imgsync')];
					sTempsrcSync = syncImage.getAttribute('src');
					syncImage.setAttribute('src', syncImage.getAttribute('hsrcSync'));
				}
			}
			
			aImages[i].onmouseout = function()
			{
				if (!sTempSrc)
					sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);

				if (this.getAttribute('imgsync') != 'none')		// sync
				{
					syncImage = document[this.getAttribute('imgsync')];
					if (!sTempsrcSync)
						sTempsrcSync = syncImage.getAttribute('src').replace('_o'+ftypeSync, ftypeSync);
					syncImage.setAttribute('src', sTempsrcSync);
				}
			}

			aImages[i].onmousedown = function()  // 3-state
			{
				this.setAttribute('src', this.getAttribute('dsrc'));

				if (this.getAttribute('imgsync') != 'none')
				{
					syncImage = document[this.getAttribute('imgsync')];
					syncImage.setAttribute('src', syncImage.getAttribute('dsrcSync'));
				}
			}

			aImages[i].onmouseup = function() 	// 3-state
			{
				this.onmouseout();
			}

			aImages[i].onclick = function() 	// 'back button' bug
			{
				if (!sTempSrc)
					sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}

		}
	}
}

//window.onload = initRollovers;
SafeAddOnload(initRollovers);
SafeOnload();
