/*************************************************************
     TEMPLATE BASED WEBSITE DESIGNED AND DEVELOPED BY
           VEBRA GRAPHICS (VEBRA SOLUTIONS LTD.)
                      COPYRIGHT 2006

      AUTHOR: DAVID SWALLOW (david.swallow@vebra.com)
                        21/04/2006

                      www.vebra.info
/*************************************************************/ 

//*************************
//     RE-USABLE FUNCTIONS
//*************************

//A means of adding multiple events to the onload event handler
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

//A means of adding multiple events to the onunload event handler
function addUnloadEvent(func) {
	var oldonunload = window.onunload;
	if (typeof window.onunload != 'function') {
		window.onunload = func;
	} else {
		window.onunload = function() {
			oldonunload();
			func();
		}
	}
}

//A function to get elements by class (does what it says on the tin) - (http://www.dustindiaz.com/getelementsbyclass)
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

//*************************
//     SITE-SPECIFIC FUNCTIONS
//*************************

//Creates a drop-down navigation menu, where poorer browsers struggle with css hover. 
function dropDown() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
 				}
  				node.onmouseout=function() {
  					this.className=this.className.replace(" over", "");
   				}
			}
		}
	}
}
addLoadEvent(dropDown);

function popUp() {
	if(!getElementsByClass("popup")){return false;}
	var theLinks = getElementsByClass("popup");
	for (i=0; i<theLinks.length; i++){
		var url = theLinks[i].getAttribute('href');
		var target = '_blank';
		var features = 'location=0, statusbar=0, menubar=0, scrollbars=1, width=500, height=400, top=100, left=300';
		theLinks[i].onclick = function() {
		 var theWindow =  window.open(url, target, features);
		 theWindow.focus();
		 return false;
		}
	}
}
addLoadEvent(popUp);