var fc="color:#ffffff;"
var pl="padding-left:4;"
var pr="padding-right:4;"
var fs="font-size:12px;"
var fw="font-weight:bold;"
var bgc="background-color:#251B85;"
var ta="text-align:right;"
var pos="position:absolute;"
var ff="font-family:arial;"
var itemheight=20;
var standard=fc+pl+pr+fs+fw+bgc+ta+pos+ff

var toplinestyle=standard + "border-color:#0099CC;border-width:1px;border-style:solid;border-top-color:#251B85;border-bottom-color:#251B85;top:0;height:" + itemheight + ";right:"
var tablestyle=standard + "visibility:hidden;"
var mouseoverstyle="this.style.color='#251B85';this.style.backgroundColor='#F0F0F8';this.style.cursor='hand';"
var mouseoutstyle="this.style.color='#ffffff';this.style.backgroundColor='#251B85';"

//****functions for screen width***

function getwidth() //this is the width of the internal screen
{
thiswidth=document.body.clientWidth;
return thiswidth;
}

//function originalwidth()  //this is the width of the whole screen
//{
//orgwidth=document.body.offsetWidth;
//return orgwidth;
//}

var screenwidth=getwidth();
var changewidth=getwidth();



function sizeCheck(oldwidth)  //this checks if the screen size changed - reloads if did
{
var newwidth=document.body.clientWidth;
//alert(oldwidth + " " + newwidth);
if (Math.abs(oldwidth-newwidth)>25) window.location.reload();
return
}

window.setInterval("sizeCheck(changewidth)", 1000);  //checks every second

var extraspaces="";
if (screenwidth > 900)
{extraspaces=" &nbsp; ";}

//****functions to make tables****

function makevisible(ttable)
{eval(ttable).style.visibility='visible'}

function makehidden(ttable)
{eval(ttable).style.visibility='hidden'}

function hidelowertables()
{
var coll = document.getElementsByTagName("table");
for (i=0; i<coll.length; i++) {
var nameoftable=coll[i].id;
if (nameoftable.indexOf("TopMenuTable") > -1 )
{eval(nameoftable).style.visibility='hidden'}
}
return
}


function makethirdtable(arrayofinfo)
{
var thirdmenus=eval(arrayofinfo)

for (var m=1; m <= thirdmenus.length-1; m++)
{
var tcontent=eval(thirdmenus[m][0])
var thistablename=thirdmenus[m][1]
var tdthatsent=thirdmenus[m][2]
var rightoftable=thirdmenus[m][3]
var topoftable=thirdmenus[m][4]
var firsttable=thirdmenus[m][5]
var tright=rightoftable+eval(tdthatsent).clientWidth
tdindex=tdthatsent.indexOf("td")
tdlevel=tdthatsent.slice(tdindex+2)
var ttop=(itemheight*(tdlevel-1)) + topoftable
var tablethatsent=tdthatsent.slice(0,tdindex)

thistable=  "<table id=" + thistablename + " border=0 style=" + tablestyle + "top:"+ ttop + ";right:" + tright 
thistable+= " onmouseover=\"this.style.visibility='visible';" + tablethatsent +".style.visibility='visible';" + firsttable + ".style.visibility='visible';\"" 
thistable+= " onmouseout=\"this.style.visibility='visible';" + tablethatsent +".style.visibility='visible';" + firsttable + ".style.visibility='visible';\">"

for (var t=1; t <= tcontent.length-1; t++)
{
var tlink=" onclick=\"window.location.href='" + tcontent[t][1] + "'\""

	thistable+="<tr><td onmouseover=\"" + mouseoverstyle + "window.status='" + tcontent[t][1] + "'" + "\""
	thistable+=" onmouseout=\"" + mouseoutstyle + "window.status=''" + "\"" + tlink + ">"
	thistable+= tcontent[t][0] + "</td></tr>"
}//end tcontent loop

thistable+="</table>"

document.write(thistable)

if (tright + eval(thistablename).clientWidth > screenwidth)  //put menu on right side
{
pxindex=eval(tablethatsent).style.right.indexOf("px")
newright=eval(tablethatsent).style.right.slice(0,pxindex).valueOf()-eval(thistablename).clientWidth + 4
newright=newright.toString() + "px"
eval(thistablename).style.right=newright
}

}//end thirdmenus loop
}//end function


function makesecondtable(arrayofinfo)
{
var secondmenus=eval(arrayofinfo)

for (var m=1; m <= secondmenus.length-1; m++)
{
var arrayfornewtable=new Array()
var lowertablearray=new Array()
var counter=1
var tcontent=eval(secondmenus[m][0])
var thistablename=secondmenus[m][1]
var tdthatsent=secondmenus[m][2]
var rightoftable=secondmenus[m][3]
var tright=rightoftable+eval(tdthatsent).clientWidth
tdindex=tdthatsent.indexOf("td")
tdlevel=tdthatsent.slice(tdindex+2)
var ttop=(itemheight*tdlevel) 
var tablethatsent=tdthatsent.slice(0,tdindex)

thistable=  "<table id=" + thistablename + " border=0 style=" + tablestyle + "top:"+ ttop + ";right:" + tright 
thistable+= " onmouseover=\"this.style.visibility='visible';" + tablethatsent +".style.visibility='visible'\" onmouseout=\"this.style.visibility='visible';" + tablethatsent +".style.visibility='visible'\">"

for (var t=1; t <= tcontent.length-1; t++)
{
var tdname=thistablename + "td" + t;

if(tcontent[t][1].slice(0,9)=="show-menu")
{
var newtablename="TopMenuTable" + tcontent[t][1].slice(9);
var tmenuname="menu" + tcontent[t][1].slice(9);
var temparray=[tmenuname,newtablename,tdname,tright,ttop,tablethatsent];
arrayfornewtable[counter]=temparray;
var tlink="";
lowertablearray[counter]=newtablename;
counter++;
tcvisible="hidelowertables();makevisible('" + newtablename + "')";
tchidden="makehidden('" + newtablename + "')";
}
else
{
var tlink=" onclick=\"window.location.href='" + tcontent[t][1] + "'\""
tcvisible="hidelowertables();window.status='" + tcontent[t][1] + "'"
tchidden="window.status=''"
}
	thistable+="<tr><td id=" + tdname + " onmouseover=\"" + mouseoverstyle + tcvisible +   "\""
	thistable+=" onmouseout=\"" + mouseoutstyle + tchidden +  "\"" + tlink + ">"
	thistable+= tcontent[t][0] + "</td></tr>"
}//end tcontent loop

thistable+="</table>"

document.write(thistable)

if (tright + eval(thistablename).clientWidth > screenwidth)  //put menu on right side
{
pxindex=eval(tablethatsent).style.right.indexOf("px")
newright=eval(tablethatsent).style.right.slice(0,pxindex).valueOf()-eval(thistablename).clientWidth + 4
newright=newright.toString() + "px"
eval(thistablename).style.right=newright
}

if (counter>1)
{makethirdtable(arrayfornewtable);
}

}//end secondmenus loop
}//end function


function makefirsttable(ttop,tright,thismenu,thistablename,widthoftopbox)
{
var tcontent=eval(thismenu);
var arrayfornewtable=new Array()
var counter=1

thistable="<table z-index id=" + thistablename + " border=0 style=" + tablestyle + "top:"+ ttop + ";right:" + tright + " onmouseover=\"this.style.visibility='visible'\" onmouseout=\"this.style.visibility='hidden'\">"

for (var t=1; t <= tcontent.length-1; t++)
{

var tdname=thistablename + "td" + t;

if(tcontent[t][1].slice(0,9)=="show-menu")
{
var newtablename="TopMenuTable" + tcontent[t][1].slice(9);
var tlink="";
var tmenuname="menu" + tcontent[t][1].slice(9);
var temparray=[tmenuname,newtablename,tdname,tright];
arrayfornewtable[counter]=temparray;
counter++

tcvisible="hidelowertables();makevisible('" + newtablename + "')" 
tchidden="makehidden('" + newtablename + "')"

}
else
{
tcvisible="hidelowertables();window.status='" + tcontent[t][1] + "'"
tchidden="window.status=''"
var tlink=" onclick=\"window.location.href='" + tcontent[t][1] + "'\""
}
	thistable+="<tr><td id=" + tdname + " onmouseover=\"" + mouseoverstyle + tcvisible +  "\""
	thistable+=" onmouseout=\"" + mouseoutstyle + tchidden + "\"" + tlink + ">"
	thistable+= tcontent[t][0] + "</td></tr>"
}
thistable+="</table>"
document.write(thistable)
//alert(thistable)

if (tright + eval(thistablename).clientWidth > screenwidth)
{
var newright=tright-eval(thistablename).clientWidth + widthoftopbox
newright=newright.toString() + "px"
//alert(newright)
//{alert(eval(thistablename).clientWidth)
eval(thistablename).style.right=newright
}

if (counter>1)
{makesecondtable(arrayfornewtable)}
}


//CREATES THE TOP LINE AND ALL INVISIBLE TABLES

for (var i=1; i <= topline.length-1; i++)
{
var boxnum="box"+i;
var lastbox="box"+(i-1);
var boxheight=itemheight
var tvisible=""
var thidden=""
var thislink=""

if (i==1) {rightcoordinate=0}
else
{widthofthisbox=eval(lastbox).clientWidth;
rightcoordinate=widthofthisbox+rightcoordinate}

if(topline[i][1].slice(0,9)=="show-menu")
{
var tablename="TopMenuTable" + topline[i][1].slice(9);
tvisible="hidelowertables();makevisible('" + tablename + "')";
thidden="makehidden('" + tablename + "')"
var menuname="menu" + topline[i][1].slice(9);
var makeatable=true
}
else
{
var thislink=" onclick=\"window.location.href='" + topline[i][1] + "'\""
var makeatable=false
}
var thisbox="<div nowrap id=" + boxnum + " style=" + toplinestyle + rightcoordinate 
thisbox += " onmouseover=\"" + mouseoverstyle + tvisible + "\""
thisbox += " onmouseout=\"" + mouseoutstyle + thidden + "\""
thisbox += thislink + ">" + extraspaces + topline[i][0] + extraspaces ;
thisbox += "</div>";
document.write(thisbox)

if (makeatable)
{makefirsttable(itemheight,rightcoordinate,menuname,tablename,eval(boxnum).clientWidth);}

} //end topline loop

