/*

This is a very handy function written by Simon Willison:
http://simon.incutio.com/archive/2004/05/26/addLoadEvent

It allows you to queue up a whole series of events to be triggered when the document loads.

If you simply use window.onload = func, then you run the risk of overwriting existing functions that are supposed to run when the onload event is triggered.

*/

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

/*

This function will cause any link with the class 'popup' to open in a new window.

This function is triggered when the page loads.
The addLoadEvent.js file is required for this.

*/

addLoadEvent(popUps);

function popUps() {

	if (!document.getElementsByTagName) return false;
	
	var lnks = document.getElementsByTagName('a');
	
	for (var i=0;i<lnks.length;i++) {
	
		if (lnks[i].className == 'popup') {


			lnks[i].onclick = function () {
	
				window.open(this.getAttribute('href'),'popup', 'toolbar=no,scrollbars=no,resizable=no,menubar=no,status=no,directories=no,location=no,width=360,height=280');
				return false;
	
			}
	
			lnks[i].onkeypress = lnks[i].onclick;
		}
	}

}

/*

This function will cause any image with the class 'roll' to do swap images on rollover.

This function is triggered when the page loads.
The addLoadEvent.js file is required for this.

*/

function findimg()
	{
		var imgs,i;
	// Loop through all images, and check if their classes contain the class roll
		imgs=document.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();
	}