//Conf -----
var imgTMFolder = "/img/menu/";
var imgTMType = ".gif";
var border = "#003366";   
var subMenuDelay = 0.5;
var fontDecoration = "none";
var statusBar = "0";
var backgClr = "#D1DBFB"; 
var backgClrOn ="#455265"; 
var textClr = "#455265";
var textClrOn = "#D1DBFB";
//leftMenu
var leftBackgClr = "#D1DBFB"; 
var leftBackgClrOn = "#455265";
var leftTextClr = "#455265";
var leftTextClrOn = "#D1DBFB";
var activeBackgClr = "#748295";
var fontFace = "arial";
var fontSize = "10px";
var fontWeight = "normal"
// Level 1 sub menu
var sVerticalOffset = 0;
var sHorizontalOffset = 0; 
var subIndicate = '/img/nav_arrow.gif';
var subIndicate_on = '/img/nav_arrow2.gif';
var sfontFace = "Arial, Helvetica, sans-serif";
var sfontSize = "11px";
var sfontWeight = "normal";
var sTransparency = "100";
//End Conf ----
function initTM(){
	Menu = new Array();
	subMenu = new Array();
	subSubMenu = new Array();
}
function preloadTM(){
	//for (x=0;x<Menu.length; x++){
	for (x in Menu){
		preloadImages(imgTMFolder+Menu[x][0]+'_over'+imgTMType);
	}
	preloadImages(subIndicate_on);
}
function addMenuImgTM(id,img,title,url,target, active){	
	//i = Menu.length;
	Menu[id] = new Array(img,title,url,target, active); 
	subMenu[id] = new Array();
}

function addSubMenuTM(id, back,backH,font,fontH,title,url,target, active){
	if(subMenu[id]){
	j = subMenu[id].length;
	subMenu[id][j] = new Array(back,backH,font,fontH,title,url,target);
	}
}
// LEFT MENU
function initLM(){
	lMenu = new Array();
}
function addLM(back,backH,font,fontH,title,url,target, active){
	j = lMenu.length;
	lMenu[j] = new Array(back,backH,font,fontH,title,url,target, active);
}
var timer; 
function showTM(){
  buildMenuImage();
  buildSubMenu();
}
function showLM(){
  buildLeftMenu();
}
function buildMenuImage(){
 var build='';
  var x=0;
  for (x in Menu){
	 build += '<div class="float" id="Menu'+x+'" >';
	 
	 if(Menu[x][4]){
		 //is active, hide submenu, hide rollover
		 build += '<a id="MenuLink'+x+'" onMouseOver="swapImgRestoreTM();clearTimer(); hideAll(\'main\'); showStatus(\'over\',\'Main\','+x+'); return true;" onMouseOut="timerHide();" href="'+Menu[x][2]+'" target="'+Menu[x][3]+'"><img  src="'+imgTMFolder+Menu[x][0]+'_on'+imgTMType+'" name="btn'+x+'" border="0" alt="" id="btn'+x+'" /></a>';
	 }else{
		 //not active
  		build += '<a id="MenuLink'+x+'" onMouseOver="swapImgRestoreTM();swapImageTM(\'btn'+x+'\',\'\',\''+imgTMFolder+Menu[x][0]+'_over'+imgTMType+'\',1); clearTimer(); hideAll(\'main\'); showSubMenu(\'Menu\','+x+'); showStatus(\'over\',\'Main\','+x+'); return true;" onMouseOut="timerHide('+x+');" href="'+Menu[x][2]+'" target="'+Menu[x][3]+'"><img  src="'+imgTMFolder+Menu[x][0]+imgTMType+'" name="btn'+x+'" border="0" alt="" id="btn'+x+'" /></a>';
	 }
	 build += '<\/div>';
  }
  document.writeln(build);
}
function buildSubMenu(){
  for (y in subMenu){
  //for(y=0; y<subMenu.length; y++){   
    buildSub = '<div id="Sub'+y+'" style="z-index:5000'+y+';position:absolute; width:152px; left:0; top:0; visibility:hidden;">';
    if(subMenu[y].length>0){ 
      buildSub += '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td><table border="0" cellpadding="0" cellspacing="0" width="100%" align="left">';
      for(z=0; z<subMenu[y].length; z++){  
        buildSub += '<tr><td nowrap="nowrap" onclick="tdMouseClick(\'SubLink'+y+z+'\')" onMouseOver="swapImage(\'subarrow'+y+z+'\',\'\',\''+subIndicate_on+'\',1);showStatus(); clearTimer(); hideAll(\'sub\'); highlightSubMenu(\'Sub\','+y+','+z+'); showStatus(\'over\',\'Sub\','+y+','+z+'); return true;" title="'+subMenu[y][z][0]+'" style="cursor:pointer"><div class="nav_sub_obj" nowrap="nowrap" id="Sub'+y+z+'" style="cursor:pointer;background-color:'+backgClr+'" onMouseOut="swapImgRestore();hideAll(\'sub\');timerHide()">';        
        buildSub += '<table border="0" cellpadding="0" cellspacing="0" width="100%" align="left"><tr>';
        buildSub += '<td nowrap="nowrap"><a id="SubLink'+y+z+'" href="'+subMenu[y][z][1]+'" target="'+subMenu[y][z][2]+'" style="margin-left:18px;font-family:'+sfontFace+';font-size:'+sfontSize+';font-weight:'+sfontWeight+';color:'+textClr+';text-decoration:'+fontDecoration+'">'+subMenu[y][z][0]+'<\/a><\/td>';
	    buildSub += '<td align="right"><img src="'+subIndicate+'" width="15" height="20" name="subarrow'+y+z+'" id="subarrow'+y+z+'" border="0" alt="" />';
        buildSub += '<\/td><\/tr><\/table><\/div><\/td><\/tr>';
      }
      buildSub += '<\/table><\/td><\/tr><\/table>';
    }
    buildSub += '<\/div>';
    document.write (buildSub)
  }
}
function buildLeftMenu(){
    if(lMenu.length>0){ 
	 buildSub = '<div class="nav_left">';
      buildSub += '<table border="0" cellpadding="0" cellspacing="0" class="nav_left_top" width="100%"><tr><td><table border="0" cellpadding="0" cellspacing="0" width="100%" align="left" class="nav_left_topline">';
      for(z=0; z<lMenu.length; z++){  
	  	 if(lMenu[z][3]){
			buildSub += '<tr><td nowrap="nowrap" onclick="tdMouseClick(\'leftLink'+z+'\')" onMouseOver="showStatus(); clearTimer(); hideAll(\'left\'); hideAll(\'sub\');return true;" title="'+lMenu[z][0]+'" style="cursor:pointer"><div class="nav_left_obj" nowrap="nowrap" id="left'+z+'" style="cursor:pointer;background-color:'+activeBackgClr+'" onMouseOut="swapImgRestore();hideAll(\'left\');hideAll(\'sub\');timerHide()">';        
			buildSub += '<table border="0" cellpadding="0" cellspacing="0" width="100%" align="left"><tr>';
			buildSub += '<td nowrap="nowrap"><a id="leftLink'+z+'" href="'+lMenu[z][1]+'" target="'+lMenu[z][2]+'" style="margin-left:18px;font-family:'+sfontFace+';font-size:'+sfontSize+';font-weight:'+sfontWeight+';color:'+textClrOn+';text-decoration:'+fontDecoration+'">'+lMenu[z][0]+'<\/a><\/td>';
			buildSub += '<td align="right" nowrap="nowrap"><img src="/img/spacer.gif" width="15" height="20" name="leftarrow'+z+'" id="subarrow'+z+'" />';

		 }else{
			buildSub += '<tr><td nowrap="nowrap" onclick="tdMouseClick(\'leftLink'+z+'\')" onMouseOver="swapImage(\'leftarrow'+z+'\',\'\',\''+subIndicate_on+'\',1);showStatus(); clearTimer(); hideAll(\'left\'); hideAll(\'sub\');highlightLeftMenu('+z+'); return true;" title="'+lMenu[z][0]+'" style="cursor:pointer"><div class="nav_left_obj" nowrap="nowrap" id="left'+z+'" style="cursor:pointer;background-color:'+leftBackgClr+'" onMouseOut="swapImgRestore();hideAll(\'left\');hideAll(\'sub\');timerHide()">';        
			buildSub += '<table border="0" cellpadding="0" cellspacing="0" width="100%" align="left"><tr>';
			buildSub += '<td nowrap="nowrap"><a id="leftLink'+z+'" href="'+lMenu[z][1]+'" target="'+lMenu[z][2]+'" style="margin-left:18px;font-family:'+sfontFace+';font-size:'+sfontSize+';font-weight:'+sfontWeight+';color:'+leftTextClr+';text-decoration:'+fontDecoration+'">'+lMenu[z][0]+'<\/a><\/td>';
			buildSub += '<td align="right" nowrap="nowrap"><img src="'+subIndicate+'" width="15" height="20" name="leftarrow'+z+'" id="subarrow'+z+'" border="0" alt="" />';
		 }
	   buildSub += '<\/td><\/tr><\/table><\/div><\/td><\/tr>';
      }
      buildSub += '<\/table><\/td><\/tr><\/table><\/div>';
	   document.write (buildSub)
    }
}
function showSubMenu(obj,id){
  //
  getOffset(eval('document.getElementById("'+obj+id+'")'),"left");
  getOffset(eval('document.getElementById("'+obj+id+'")'),"top");
  getOffset(eval('document.getElementById("'+obj+id+'")'),"height");
  getOffset(eval('document.getElementById("'+obj+id+'")'),"width");
  vOff=0;
  hOff=0;
  document.getElementById("Sub"+id).style.left=oLeft+sHorizontalOffset+vOff+"px";
  document.getElementById("Sub"+id).style.top=oTop+oHeight+sVerticalOffset-hOff+"px";
  document.getElementById("Sub"+id).style.visibility="visible";
}
function highlightSubMenu(obj,id, subid){
	document.getElementById(obj+id+subid).style.backgroundColor=backgClrOn;
	document.getElementById(obj+"Link"+id+subid).style.color=textClrOn;	
}
function highlightLeftMenu(id){
	hideAll();
	swapImgRestoreTM();
	document.getElementById("left"+id).style.backgroundColor=leftBackgClrOn;
    document.getElementById("leftLink"+id).style.color=leftTextClrOn;
}
function timerHide(){
	var a=timerHide.arguments;
 	timer = setTimeout("hideAll();swapImgRestoreTM();",(subMenuDelay*1000));
	if(a.length){
		 if(subMenu[a[0]].length==0){ 
			 clearTimer();
			 swapImgRestoreTM();
		 }
	}
}
function clearTimer(){
  if(timer){clearTimeout(timer)}
}
function hideAll(level){
	showStatus('out');
	switch(level){
		case "left":
			for(x=0;x<lMenu.length; x++){
				if(level!="sub"&&level!="subsub"){
					 if(!lMenu[x][3]) {
						 document.getElementById("left"+x).style.backgroundColor=leftBackgClr;
						 document.getElementById("leftLink"+x).style.color=leftTextClr;
					 }
				}
			}
		break;
		default:
			for (x in Menu){
				for(y=0;y<subMenu[x].length; y++){
					if(level!="subsub") document.getElementById("Sub"+x+y).style.backgroundColor=backgClr;document.getElementById("SubLink"+x+y).style.color=textClr;
				}
				if(level!="sub"&&level!="subsub") document.getElementById("Sub"+x).style.visibility="hidden";
			}
		break;
		}
}
function getOffset(obj, dim) {
  if(dim=="left") 
  {     
    oLeft = obj.offsetLeft;  
    while(obj.offsetParent!=null) 
    {    
      oParent = obj.offsetParent     
      oLeft += oParent.offsetLeft 
      obj = oParent 	
    }
    return oLeft
  }
  else if(dim=="top")
  {
    oTop = obj.offsetTop;
    while(obj.offsetParent!=null) 
    {
      oParent = obj.offsetParent
      oTop += oParent.offsetTop
      obj = oParent 	
    }
    return oTop
  }
  else if(dim=="width")
  {
    oWidth = obj.offsetWidth
    return oWidth
  }  
  else if(dim=="height")
  {
    oHeight = obj.offsetHeight
    return oHeight
  }    
  else
  {
    alert("Error: invalid offset dimension '" + dim + "' in getOffset()")
    return false;
  }
}
function showStatus(state,level,id,subid,subsubid){
  if(statusBar==0){msg=5}
  else if(statusBar==1){msg=4}
  else {msg=0}
    
  if(state=="over"){
    if(level=="Main" && msg>0){displayStatus=Menu[id][2]}
    else if(level=="Sub" && msg>0){displayStatus=subMenu[id][subid][msg]}
    else if(level=="SubSub" && msg>0){displayStatus=subSubMenu[id][subid][subsubid][msg]}
    else{displayStatus=statusBar;}
  }
  else{displayStatus="";}
  window.status=displayStatus
}
function tdMouseClick(theElement){
   var x,t;
   if ((x=findObj(theElement))!=null){location.href=x;}
}
function swapImgRestore() { 
  var i,x,a=document.sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function preloadImages() { 
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}
function findObj(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function swapImage() { 
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; 
   if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function swapImgRestoreTM(){
  var i,x,a=document.st; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.tSrc;i++){
	  x.src=x.tSrc
  };
}
function swapImageTM() { 
  var i,j=0,x,a=swapImageTM.arguments; document.st=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.st[j++]=x; 
   if(!x.tSrc) x.tSrc=x.src; x.src=a[i+2];}
}
////////// PAGE IMG  SWAP ////////////////
function swapPageImgRestore(){ 
  var i,x,a=document.sp; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.pSrc;i++){
	  x.src=x.pSrc
  };
}
function swapPageImg() { 
  var i,j=0,x,a=swapPageImg.arguments; document.sp=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sp[j++]=x; 
   if(!x.pSrc) x.pSrc=x.src; x.src=a[i+2];}
}


//PAGE TAB

function tabSwapColor(id){
    document.getElementById(id).style.backgroundColor="#C7CDDD";
}
function tabRestore(id){
	 document.getElementById(id).style.backgroundColor="#FFFFFF";
}