var mastertabvar=new Object()
mastertabvar.baseopacity=0
mastertabvar.browserdetect=""

var defaultset=new Object()

var testtimeout = null;

var showingid = '';

function showsubmenu(masterid, id){
actualhide(masterid)
actualshow(masterid, id)
}

function actualshow(masterid, id)
{
if (typeof highlighting!="undefined")
clearInterval(highlighting)
submenuobject=document.getElementById(id)
mastertabvar.browserdetect=submenuobject.filters? "ie" : typeof submenuobject.style.MozOpacity=="string"? "mozilla" : ""
submenuobject.style.display="block"
showingid = id;
if (id != defaultset[masterid])
{
	instantset(mastertabvar.baseopacity)
	highlighting=setInterval("gradualfade(submenuobject)",50)
}
}

function hidesubmenus(tabid){
actualhide(tabid);
if ('' != defaultset[tabid]) actualshow(tabid, defaultset[tabid])
}

function actualhide(tabid){
if (null != testtimeout) clearTimeout(testtimeout);
testtimeout = null;
submenuarray = mastertabvar[tabid]
for (var i=0; i<submenuarray.length; i++)
document.getElementById(submenuarray[i]).style.display="none"
showingid = '';
}

function instantset(degree){
if (mastertabvar.browserdetect=="mozilla")
submenuobject.style.MozOpacity=degree/100
else if (mastertabvar.browserdetect=="ie")
submenuobject.filters.alpha.opacity=degree
}

function gradualfade(cur2){
if (mastertabvar.browserdetect=="mozilla" && cur2.style.MozOpacity<1)
cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.25, 0.99)
else if (mastertabvar.browserdetect=="ie" && cur2.filters.alpha.opacity<100)
cur2.filters.alpha.opacity+=0
else if (typeof highlighting!="undefined") //fading animation over
clearInterval(highlighting)
}

function initalizetab(tabid,def){
	defaultset[tabid] = def;
	mastertabvar[tabid]=new Array()
	var menuitems=document.getElementById(tabid).getElementsByTagName("li")
	for (var i=0; i<menuitems.length; i++){
		if (menuitems[i].getAttribute("rel")){
			menuitems[i].setAttribute("rev", tabid) //associate this submenu with main tab
			mastertabvar[tabid][mastertabvar[tabid].length]=menuitems[i].getAttribute("rel") //store ids of submenus of tab menu
			if (menuitems[i].className=="selected")
			showsubmenu(tabid, menuitems[i].getAttribute("rel"))
			menuitems[i].getElementsByTagName("a")[0].onmouseover=function(){
				if (null != testtimeout) clearTimeout(testtimeout);
				testtimeout = null;
				if (showingid != this.parentNode.getAttribute("rel"))
				showsubmenu(this.parentNode.getAttribute("rev"), this.parentNode.getAttribute("rel"))
			}
			menuitems[i].getElementsByTagName("a")[0].onmouseout=function(){
				if (null != testtimeout) clearTimeout(testtimeout);
				testtimeout = null;
				if (this.parentNode.getAttribute("rel") != defaultset[tabid])
				{
					testtimeout = setTimeout("hidesubmenus('"+tabid+"')", 200)
				}
			}

			var subitems = document.getElementById(menuitems[i].getAttribute("rel")).getElementsByTagName("li");
			for (var j=0; j<subitems.length; j++){
				subitems[j].getElementsByTagName("a")[0].onmouseover=function(){
					if (null != testtimeout) clearTimeout(testtimeout);
					testtimeout = null;
				}
				subitems[j].getElementsByTagName("a")[0].onmouseout=function(){
					if (null != testtimeout) clearTimeout(testtimeout);
					testtimeout = null;
					if (this.parentNode.parentNode.id != defaultset[tabid])
					{
						testtimeout = setTimeout("hidesubmenus('"+tabid+"')", 200)
					}
				}
			}
		}
	}
}
	function getWindowHeight() {
		var windowHeight = 0;
		if (typeof(window.innerHeight) == 'number') {
			windowHeight = window.innerHeight;
		}
		else {
			if (document.documentElement && document.documentElement.clientHeight) {
				windowHeight = document.documentElement.clientHeight;
			}
			else {
				if (document.body && document.body.clientHeight) {
					windowHeight = document.body.clientHeight;
				}
			}
		}
		return windowHeight;
	}
	function setContent() {
		if (document.getElementById) {
			var windowHeight = getWindowHeight();
			if (windowHeight > 0) {
				var contentElement = document.getElementById('theContent');
				var contentHeight = contentElement.offsetHeight;
				if (windowHeight - contentHeight > 0) {
					contentElement.style.position = 'relative';
					contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px';
				}
				else {
					contentElement.style.position = 'static';
				}
			}
			try{
				document.getElementById('theContent').style.visibility='visible';
			}catch(e){}
		}
	}
function loadjscssfile(filename, filetype){
	 if (filetype=="js"){ //if filename is a external JavaScript file
	  var fileref=document.createElement('script')
	  fileref.setAttribute("type","text/javascript")
	  fileref.setAttribute("src", filename)
	 }
	 else if (filetype=="css"){ //if filename is an external CSS file
	  var fileref=document.createElement("link")
	  fileref.setAttribute("rel", "stylesheet")
	  fileref.setAttribute("type", "text/css")
	  fileref.setAttribute("href", filename)
	 }
	 if (typeof fileref!="undefined")
	  document.getElementsByTagName("head")[0].appendChild(fileref)
}

window.onload = function() {
	//~ var bodyTag = document.getElementsByTagName('body')[0];
	//~ var container =bodyTag.getElementsByTagName('div')[0];
	//~ container.setAttribute('id','theContent');
	//~ container.setAttribute ('style', '');
	//~ container.setAttribute ('style', 'width: 1000px;');
	//~ container.style.visibility='visible';
	//loadjscssfile("custom_layout.css", "css") ////dynamically load and add this .css file
	//setContent();
}
window.onresize = function() {
	//setContent();
}

function setCustomLayout(){
	if (!document.all&&!document.layers&&!document.getElementById)
	return

	var winH=screen.height;
	if(winH <= 800 && parseInt(navigator.appVersion)>3){
		//document.getElementById('theContent').style.offsetTop ='0';
		//document.getElementById('theContent').style.marginTop ='0px';
		loadjscssfile("custom_layout.css", "css") ////dynamically load and add this .css file

	 }

}
setCustomLayout();
