/*
	Standards Compliant Rollover Script
	Author : Daniel Nolan
	http://www.bleedingego.co.uk/webdev.php
*/

function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var hTempSrc;
	var aTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);

			// hover時の画像
			var hsrc = src.replace(ftype, '_on'+ftype);
			aImages[i].setAttribute('hsrc', hsrc);
			
			// active時の画像
			var asrc = src.replace(ftype, '_active'+ftype);
			aImages[i].setAttribute('asrc', asrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				hTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}
			
			aImages[i].onmousedown = function() {
				aTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('asrc'));
			}
			
			aImages[i].onmouseup = function() {
				if (!aTempSrc) aTempSrc = this.getAttribute('src').replace('_active'+ftype, ftype);
				this.setAttribute('src', aTempSrc);
			}
			
			aImages[i].onmouseout = function() {
				if (!hTempSrc) hTempSrc = this.getAttribute('src').replace('_on'+ftype, ftype);
				this.setAttribute('src', hTempSrc);
			}
		}
	}
}

window.onload = initRollovers;
