
//conventions::
// level 1 : visible layers/nav
// level 2 : first level popup layers/nav
// level 3 : second level popup layers/nav

// --------------------------------------------------------
// set up globals

//positioning
var allheight;
var mainwidth;
var subwidth;
var mainNavY = new Array();
var mainNavX = new Array();
var subx;
var suby;

//home or subpage
var prefx;

//the real meat
var contentsL2 = new Array();
var contentsL3 = new Array();

var numL2 = new Array();//number of elements
var numL3 = new Array();//number of elements


//timers
var timerL2 = null;
var timerL3 = null;
var timerL2Img = null; //for layer 1 image

var aWait = 200;

//make sure only one showing at a time: be good children
var wLayerVis2 = null;
var wLayerVis3 = null;
var wImgVis1 = null; //for layer 1 image


// --------------------------------------------------------
// init main
function re_init(wPage) {

	//whether from home or subpages
	prefx = wPage;
	
	LL_init();
	LL_catchResize('');
	initPositions();
	
	createNav2();
	createNav3();
	
	buildNav2();
	buildNav3();
}


function initPositions(){

  //defines global attributes for all items
	allheight = 19;
	mainwidth = 200;
	subwidth = 250;
	//set positions of main level nav
	mainNavY[1]= 99; mainNavX[1]= 192;
	mainNavY[2]= 140; mainNavX[2]= 192;
	mainNavY[3]= 181; mainNavX[3]= 192;
	mainNavY[4]= 222; mainNavX[4]= 192;
	mainNavY[5]= 263; mainNavX[5]= 192;
	mainNavY[6]= 304; mainNavX[6]= 192;
	mainNavY[7]= 345; mainNavX[7]= 192;
	mainNavY[8]= 386; mainNavX[8]= 192;


	//set offset of sub level nav
	subx = 0;   suby = 0; 
}




//---------------------------------------------------------
//      LEVEL 2

//populate level 2 of nav
function addNav2(theArea,theText,theLink) {
	
	theLink  = prefx + theLink;
		
	(!numL2[theArea]) ? numL2[theArea] = 1 : numL2[theArea] += 1; //number of items in section

	if (LL_NN) {
		aString = '<tr>' + '<td bgcolor="#000000" width="' + mainwidth + '" height="' + allheight + '" valign="middle" background="assets/shared/spacer.gif"><ilayer width="' + mainwidth + '" height="' + allheight + '"><layer left="5" width="' + mainwidth + '" height="' + allheight + '"  onMouseOut="menu_2(\'' + theArea + '\', false,\'' + numL2[theArea] + '\');" onMouseOver="menu_2(\'' + theArea + '\', true,\'' + numL2[theArea] + '\');"><a class="HgmDnav2"  href="' + theLink + '">' + theText +'</a></layer></ilayer></td>' +
			'</tr>';
	} else {
		aString = ('<tr>' +
			'<td class="menuBack"  height="' + allheight +'" bgcolor="#ffffff" valign="middle" onMouseOut="menu_2(\'' + theArea + '\', false,\'' + numL2[theArea] + '\');" onMouseOver="menu_2(\'' + theArea + '\', true,\'' + numL2[theArea] + '\');"><a class="subNav" onMouseOver="menu_2(\'' + theArea + '\', true,\'' + numL2[theArea] + '\');"  href="' + theLink + '">' + theText +'</a></td>' +
			'</tr>');
	} 
	
	(!contentsL2[theArea]) ? contentsL2[theArea] = aString : contentsL2[theArea] += aString; //content for section
}	


//build level 2 of nav
function buildNav2(){
	e = mainNavY.length + 1;
	for (i=0; i< e; i++){
        height = allheight * numL2[i];
		copy = '<table border="0" cellpadding="0" cellspacing="0"><tr><td background="assets/hm/lNav_back.gif"><table border="0" cellpadding="0" cellspacing="0" width="' + mainwidth + '" height="' + height + '">' + contentsL2[i] + '</td></tr></table></table>';		

		if (contentsL2[i]){
		
			LL_makeLayer('layer2_' + i, mainNavX[i] + subx, mainNavY[i] + suby, mainwidth + 4, height + 20, false, copy, 'clss');
		}
	}		

}


//---------------------------------------------------------
//      LEVEL 3

//populate level 3 of nav
function addNav3(area, snArea, theText, theLink){
	
	if (LL_NN) {
		aString = '<tr>' +
			'<td class="menuBack" valign="center" background="assets/shared/spacer.gif"><ilayer width="100%" height="' + allheight + '"><layer left="5" width="100%" height="100%" onMouseOut="menu_2(\'' + area + '\', false, \'' + snArea + '\');" onMouseOver="menu_2(\'' + area + '\', true, \'' + snArea + '\');"><a href="' + theLink + '" class="HgmDnav2">' + theText +'</a></layer></ilayer></td>' +
			'</tr>';
	} else {
		aString = ('<tr>' +
			'<td class="menuBack" valign="center" onMouseOut="menu_2(\'' + area + '\', false, \'' + snArea + '\');" onMouseOver="menu_2(\'' + area + '\', true, \'' + snArea + '\');"><a href="' + theLink + '" class="subNav">' + theText +'</a></td>' +
			'</tr>');
	}
	
	if (!numL3[area]) {numL3[area] = new Array();}
	(!numL3[area][snArea]) ? numL3[area][snArea] = 1 : numL3[area][snArea] += 1; //number of items in section
	
	if (!contentsL3[area]) {contentsL3[area] = new Array();}
	(!contentsL3[area][snArea]) ? contentsL3[area][snArea] = aString : contentsL3[area][snArea] += aString; //content for section
}	

//build level 3 of nav
function buildNav3(){

	for (i=1; i< contentsL3.length; i++){
		if (contentsL3[i]){
			for (j=1; j< contentsL3[i].length; j++){
				if(contentsL3[i][j]){
				height = allheight * numL3[i][j];
				xpos = mainNavX[i] + suby + mainwidth;
				ypos = mainNavY[i] + subx + ((j * allheight) - allheight);
				
				copy = '<table border="0" cellpadding="2" cellspacing="0"><tr><table border="0" cellpadding="0" cellspacing="0" width="' + mainwidth + '" height="' + (height + 2) + '">' + contentsL3[i][j] + '</td></tr></table></table>';
				if (contentsL3[i]){
				LL_makeLayer('layer3_' + i + j, xpos, ypos, subwidth + 4, height + 20, false, copy, 'clss');
				}
				}
			}
		}
	}
} 




//---------------------------------------------------------
//      Roll Functions

//roll level 2 nav
function menu_2(wlayer, active, child3){

	trackRoll = wlayer;	
	childLayer = "layer3_" + wlayer + child3;
	wlayer = "layer2_" + wlayer;
		
	if (active){
			//for level 1 image
			
			//kill other img
			if (wImgVis1 != null){ 
			roll('dNav_' + wImgVis1, true);
			}
			
			roll ('dNav_' + trackRoll);
			clearTimeout(timerL2Img);	timerL2Img = null;
			wImgVis1 = trackRoll;
			
		//kill other layers level 2
		if (wLayerVis2 != null){ 
		LL_hideLayer(wLayerVis2);
		}
		LL_showLayer(wlayer);
		clearTimeout(timerL2);	timerL2 = null;
		wLayerVis2 = wlayer;
		
		if(LL_layerExists(childLayer)){//level 3 of nav

			//kill other layers level 3
			if (wLayerVis3){LL_hideLayer(wLayerVis3);}
			
			LL_showLayer(childLayer);
			clearTimeout(timerL3);	timerL3 = null;
			wLayerVis3 = childLayer;
		}
	}
	else{
		timerL2Img = setTimeout('roll ("dNav_" + \''+ trackRoll +'\', true);',aWait);//for level 1 image
		timerL2 = setTimeout('LL_hideLayer(\''+ wlayer +'\');',aWait);
		if (LL_layerExists(childLayer)){	timerL3 = setTimeout('LL_hideLayer(\''+ childLayer +'\');',aWait)		};//level 3 of nav
		
	}
}



//roll image functions
var sfx;
function roll(name,aOn){
	if (document.images) {  
		sfx = (aOn) ? '': '_o';
		document.images[name].src=eval(name + sfx + ".src");
	}
}
	
function newImage(src) {
	var anImg = new Image;
	anImg.src = src;
	return anImg;
}



