// JavaScript Document

function showPopup(objLink)
{
	window.open(objLink, 'Product','left=500,top=60,scrollbars=yes,width=450px,height=500,resizable=yes');	
}

function closeWindow(objLink)
{
	window.close(objLink);
}

function anchorEvents()
{	
	if (!document.getElementsByTagName){ return; }
	var anchors = document.getElementsByTagName("a");

	// loop through all anchor tags
	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "popup"))
		{
			anchor.onclick = function () {showPopup(this); return false;}
		}
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "closeWindow"))
		{
			anchor.onclick = function () {closeWindow(this); return false;}
		}
	}
}
function disableContextMenu()
{
	// grab all images and loop through them
	// This function won't work in Opera becuase it doesn't support .oncontextmenu
	var images = document.getElementsByTagName("img");
	for(var i=0;i<images.length;i++)
	{
		// disable the context menu for this image.
		images[i].oncontextmenu=function(){return false;};
	}	
}


// Rollover JavaScript.
// Any img tag on the page with class="rollover" will be change to a rollover. Make sure you have
// a file with _over for the over state. So if you're rollover image is logo.gif make sure you have a logo_over.gif.

function findRollovers() 
{
	var imgs = document.getElementsByTagName("img");
	
	for(var i=0;i<imgs.length;i++)
	{
		if ((imgs[i].getAttribute("class")) && (imgs[i].getAttribute("class").indexOf("rollover") !== -1))
		{
			imgs[i].onmouseover=function(){this.src=this.src.replace(extension(this),"_over"+extension(this));};
			imgs[i].onmouseout=function(){this.src=this.src.replace("_over"+extension(this),extension(this));};			
			
			//preload - loads the over images. The over states must have _over before the extension. e.g. logo.jpg and logo_over.jpg//
			var overImage = new Image();
			var overImageSrc = imgs[i].src.replace(extension(imgs[i]),"_over"+extension(imgs[i]));
			overImage.src=overImageSrc;	
		}
	}
}
// finds the extention of any tag passed to this function.
function extension(tag)
{
	var extension=tag.src.split(".");
	extension="."+extension[extension.length-1];
	return extension;
}





//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
    	window.onload = func;
	} 
	else 
	{
		window.onload = function(){oldonload();func();}
	}
}
addLoadEvent(anchorEvents);	// run anchorEvents() onLoad
addLoadEvent(disableContextMenu);	// run disableContextMenu() onLoad
addLoadEvent(findRollovers); 
