// 
//  «rollover.js»
//  
//  Created by Ben Kutil on 2008-02-29.
//  Copyright 2008 Make-Things. All rights reserved.
// 

/*
	Summary/Usage:
	--
	This javascript code finds images within an area defined and looks for their associated rollover code, so that when someone enters a link area, the image will rollover.
	
	link this file in your html <head> section.
	<script src="path/to/rollover.js" type="text/javascript"></script>
	
	make sure to have your navigation or other rollover items within a container that has an id. For example
	
	<ul id="nav">
		<li><a href="#link"><img src="path/image.jpg" alt="nav image 1" /></a></li>
	</ul>
	
	Your image files should be named as follows:
	
	name of image.gif // this is the "off" version
	name of image-on.gif // this is the "on" version
	
	
	depending upon what your ID is, you will have to change this line in the javascript:
	
	nav = document.getElementById('menu'); // change the 'nav' to whatever your id is.
	
*/

/* SIMPE Rollover */
function findimg()
	{
		var imgs,i;
	// Loop through all images, and check if their classes contain the class roll
		nav = document.getElementById('logicmenu');
		imgs=nav.getElementsByTagName('img');
		for(i=0;i<imgs.length;i++)
		{
			/*if(/roll/.test(imgs[i].className))
			{ */
	// add the function roll to the parent Element of the image
				imgs[i].parentNode.onmouseover=function(){roll(this);};
				imgs[i].parentNode.onmouseout=function(){roll(this);};
				imgs[i].parentNode.onfocus=function(){roll(this);};
				imgs[i].parentNode.onblur=function(){roll(this);};
			// }
		}
	}
	function roll(o)
	{
		var i,isnode,src,ftype,newsrc,nownode;
	// loop through all childNodes
		for (i=0;i<o.childNodes.length;i++)
		{
			nownode=o.childNodes[i];
	// if the node is an element and an IMG set the variable and exit the loop
			if(nownode.nodeType==1 && /img/i.test(nownode.nodeName))
			{
				isnode=i;
				break;
			}
		}
	// check src and do the rollover
		src = o.childNodes[isnode].src;
		ftype = src.substring(src.lastIndexOf('.'), src.length);
		if(/-on/.test(src))
		{
			newsrc = src.replace('-on','');
		}else{
			newsrc = src.replace(ftype, '-on'+ftype);
		}
		o.childNodes[isnode].src=newsrc;
	}
	
	window.onload=function(){
		findimg();
	}