var intmoveLeft = 0;
var intmoveTop = 0;

//detect browser and set menu offset if needed
var browserName=navigator.userAgent.toLowerCase();

if (browserName.indexOf('safari') !=-1) {
	intmoveLeft = 0;
	intmoveTop = 0;
} else if (browserName=="Netscape") {
	intmoveLeft = 0;
	intmoveTop = 0;
} else {
	intmoveLeft = 0;
	intmoveTop = 0;
}

function findPosLeft(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
}

function findPosTop(obj) {
	var curtop = 0;
	var printstring = '';
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}

function findWidth(name) {
	if (document.getElementById) {
		curwidth = document.getElementById(name).offsetWidth;
	} else if (document.all) {
		curwidth = document.all[name].width;
	} else if (document.layers) {
		if (document.layers[name]) {
			curwidth = document.layers[name].width;
	   } else {
			curwidth = eval("document.layers." + name + ".layers[name].width");
	   }
	}
	return curwidth;
}

function getObj(name) {
	if (document.getElementById) {
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	} else if (document.all) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
	} else if (document.layers) {
		if (document.layers[name]) {
			this.obj = document.layers[name];
			this.style = document.layers[name];
	   } else {
			this.obj = eval("document.layers." + name + ".layers[name]");
			this.style = eval("document.layers." + name + ".layers[name]");
	   }
	}
}

var timerID = null;
var menuArray = new Array();

function openMenu(drop, parent, intModWidth, intModHeight) {
	closeMenus();
	openMenuAndParentMenu(drop, parent, intModWidth, intModHeight);
}

function openMenuAndParentMenu(drop, parent, intModX, intModY) {
	dropdown = false;
	try { // make sure submenu has been created
		dropdown = new getObj('dropdown' + drop)
		targetDD = new getObj('target' + drop);
		targetWidth = findWidth('target' + drop + 'width');
	} catch(err) {
		return false;
	}
	
	
	
	try {
		if (parent !== false) {
			dropdown.style.left = (findPosLeft(targetDD.obj) - intmoveLeft) + "px";
			dropdown.style.top  = (findPosTop(targetDD.obj) - intmoveTop) + "px";
			dropdown.style.width = targetWidth + "px";
		} else {
			dropdown.style.left = (findPosLeft(targetDD.obj) - intmoveLeft) + "px";
			dropdown.style.top  = (findPosTop(targetDD.obj) - intmoveTop) + "px";
			dropdown.style.width = targetWidth + "px";
		}
	
		dropdown.style.visibility = 'visible'; // Show the menu here to stop it blinking in the wrong place in firefox
		
		var IfrRef = new getObj('DivShim');
	    IfrRef.style.width = dropdown.obj.offsetWidth;
	    IfrRef.style.height = dropdown.obj.offsetHeight;
	    IfrRef.style.top = dropdown.style.top;
	    IfrRef.style.left = dropdown.style.left;
	    IfrRef.style.zIndex = dropdown.style.zIndex - 1;
	    IfrRef.style.visibility = dropdown.style.visibility;
	
	
		if (menuArray[drop] == undefined) {
			menuArray[drop] = parent; //store the parent menu
		}
	
		if (menuArray[drop] !== false) {
			//parent already set before, if not do not enter here again
			openMenuAndParentMenu(menuArray[drop], false);
		}
	} catch(err) {
		return false;
	}
}

function closeMenus() {
	try {
		var IfrRef = new getObj('DivShim');
	    IfrRef.style.visibility = "hidden";
		clearTimeout(timerID);
		for (x in menuArray) {
			dropdown = new getObj('dropdown' + x)
			dropdown.style.visibility = 'hidden'
		}
	} catch(err) {}
}




// Tab switcher
function tabswitcher(strTabSet, intTabID) {
	strButtons = 'tabset_' + strTabSet + '_button';
	strDivs = 'tabset_' + strTabSet + '_div';
	for (i = 1; i <= 10; i++) {
		try {	
			var objTab =   document.getElementById(strButtons + i);
			var objLayer = document.getElementById(strDivs + i);
			
			if (i == intTabID) {
				objTab.className = 'on';
				objLayer.style.display = 'block';

			} else {
				objTab.className = '';
				objLayer.style.display = 'none';
			}
		} catch(e) { i = 100; }
	}
}


/* A fix for target _blank */
function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
} 
window.onload = externalLinks;
