/******************--------- TAB Nav homepage----------*************************/
helper = {
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Popup new window
	// *********************** Page popup properties ************************* //
	// Popup arguments
	// See http://www.accessify.com/features/tutorials/the-perfect-popup/ for an overall explanation
	popUpType : "standard",
	popUpWidth : "780",
	popUpHeight : "580",
	newWindow : null,
	// *********************** Page Popup properties ************************* //

	// Check to see if a popup window is available
	// http://www.accessify.com/features/tutorials/the-perfect-popup/ for an overall explanation
  	initNewWindowPopup:function()
	{
		var popups = document.getElementsByTagName("a");
		for (i=0;i<popups.length;i++)
		{
			if (popups[i].rel.indexOf("popup")!=-1)
			{
				helper.addEvent(popups[i],'click',helper.doPopUp,false);
			}
		}
	},
	
	doPopUp:function(e)
	{
		// Get rel data
		var linkElement = helper.getTarget(e);
		
		var attribs = linkElement.rel.split(" ");
		if (attribs[1]!=null) {helper.popUpType = attribs[1];}
		if (attribs[2]!=null) {helper.popUpWidth = attribs[2];}
		if (attribs[3]!=null) {helper.popUpHeight = attribs[3];}
		//calls function to close pop-up if already open, 
		//to ensure it's re-opened every time, retainining focus
		helper.closeNewWindow();
		helper.popUpType = helper.popUpType.toLowerCase();

		if (helper.popUpType == "fullscreen")
		{
			helper.popUpWidth = screen.availWidth;
			helper.popUpHeight = screen.availHeight;
		}
		var tools='';
		if (helper.popUpType == "standard"){
			tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes, width="+helper.popUpWidth+",height="+helper.popUpHeight+",top=0,left=0";
		}
		if (helper.popUpType == "console" || helper.popUpType == "fullscreen"){
			tools = "resizable,toolbar=no, location=no,scrollbars=no,width="+helper.popUpWidth+",height="+helper.popUpHeight+",left=0,top=0";
		}
		helper.newWindow = window.open(linkElement.href, 'newWin', tools);
		helper.cancelClick(e); // PLacing the canel function below 'fp.newWindow.focus();' creates an error in IE7 where the pdf loads in the popup AND the original window 
		helper.newWindow.focus();
		
	},
	closeNewWindow:function() 
	{
		if (helper.newWindow != null)
		{
			if(!helper.newWindow.closed)
			helper.newWindow.close();
		}
	},
	// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Popup new window
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////

	
	/*---------Helper------*/
	//Fix safari
	fixSafari:function(node){
//		node.onclick = function() { return false; }; // Safari
	},
	
	
/*	getTarget:function(e){
		var target = window.event ? window.event.srcElement : e ? e.target : null;
		if (!target){return false;}
		if (target.nodeName.toLowerCase() != 'a'){target = target.parentNode;}
		return target;
	},*/
	
	// New getTargetFunction (http://lists.evolt.org/archive/Week-of-Mon-20060717/183797.html)
	getTarget:function(e)
	{
		var target = window.event ? window.event.srcElement : e ? e.target : null;
		if (!target){return false;}
		while(target.nodeType!=1 && target.nodeName.toLowerCase()!='body')
		{
			target=target.parentNode;
		}
		return target;
	},
	
	addEvent: function(elm, evType, fn, useCapture){
		if (elm.addEventListener) 
		{
			elm.addEventListener(evType, fn, useCapture);
			return true;
		} else if (elm.attachEvent) {
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		} else {
			elm['on' + evType] = fn;
		}
	},
	cancelClick:function(e){
		if (window.event){
			window.event.cancelBubble = true;
			window.event.returnValue = false;
			return;
		}
		if (e){
			e.stopPropagation();
			e.preventDefault();
		}
	},
	
	// cssjs tests 
	cssjs:function(a,o,c1,c2){
		switch (a){
			case 'swap':
				o.className=!helper.cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
			break;
			case 'add':
				if(!helper.cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
			break;
			case 'remove':
				var rep=o.className.match(' '+c1)?' '+c1:c1;
				o.className=o.className.replace(rep,'');
			break;
			case 'check':
				return new RegExp("(^|\\s)" + c1 + "(\\s|$)").test(o.className)
			break;
		}
	},
	
	getElementsByClass : function(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;
	}
}
// Attach function to core Array object
// http://www.dustindiaz.com/top-ten-javascript/
Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};
// start the show.
helper.addEvent(window, 'load', helper.initNewWindowPopup, false);