//====================================================================================================
//======================================================================= Globals
//====================================================================================================
var Menus = new Array();
var Images = new Array();

//====================================================================================================
//======================================================================= RegisterSection
//====================================================================================================
function RegisterMenu( sectionId ){
	//var section = GetObject( sectionId );
	sectionName = sectionId + "-Div";
	
	if(navigator.appName == 'Netscape'){ 
		var section = document.getElementById(sectionName);
		sectionWidth = section.scrollWidth;
 	} else if(navigator.appName == "Microsoft Internet Explorer") {
		var section = document.all[sectionName];
		sectionWidth = section.style.scrollWidth;
	}	
	//SetStatus("RegisterMenu(" + sectionId + ", " + sectionWidth + ")");
	
	Menus.push( [ sectionId, false,  sectionWidth, false, false ] );
}

//====================================================================================================
//======================================================================= GetSectionIndex
//====================================================================================================
function GetSectionIndex( sectionId ){
	index = 0;
	i = 0;
	while( Menus[i] ){
		if( Menus[i][0] == sectionId ){
			index = i;
		}
		i++;
	}
	return index;
}

//====================================================================================================
//======================================================================= preloadImage
//====================================================================================================
function preloadImage( imagePath ){
	//var preload = new Image();
	//preload.src = imagePath;
}
//====================================================================================================
//======================================================================= changeOpac
//====================================================================================================
function changeOpac(opacity, id) {
    //var object = document.getElementById(id).style;
	if(navigator.appName == 'Netscape'){ 
		var object = document.getElementById(id).style;
 	} else if(navigator.appName == "Microsoft Internet Explorer") {
		var object = document.all[id].style;
	}
	
	object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 


//====================================================================================================
//======================================================================= changeSize
//====================================================================================================
function changeSize( height, id){
    //var object = document.getElementById(id).style;
	if(navigator.appName == 'Netscape'){ 
		var object = document.getElementById(id).style;
 	} else if(navigator.appName == "Microsoft Internet Explorer") {
		var object = document.all[id].style;
	}

	object.height = height;
}

//====================================================================================================
//======================================================================= resize
//====================================================================================================
function resize( id, curHeight, newHeight, millisec){
    var speed = Math.round(millisec / 100);
    var timer = 1;

    if(curHeight > newHeight) {
        for(i = curHeight; i >= newHeight; i--) {
            j = i / newHeight;
			setTimeout("changeSize(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(curHeight < newHeight) {
        for(i = curHeight; i <= newHeight; i++)
            {
            setTimeout("changeSize(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}
function setMenuZ( menuName , zValue){
	if(navigator.appName == 'Netscape'){ 
		var menuObject = document.getElementById(menuName).style;
 	} else if(navigator.appName == "Microsoft Internet Explorer") {
		var menuObject = document.all[menuName].style;
	}
	menuObject.zIndex = zValue;
}
//====================================================================================================
//======================================================================= fade
//====================================================================================================
function fade( id, makeVisible, millisec){
    var speed = Math.round(millisec / 100);
    var timer = 1;
	var sectionName = id + "-Div";
	var imageName = id;
	
	i = GetSectionIndex( id );
	visible = Menus[i][1];
	
    if( !visible & makeVisible ) {
		//if the div is not visible, show it
		
		//hide any others that are visible
		//SetStatus("fade: Menus.length [" + Menus.length + "]");
		setMenuZ( sectionName, "1");
		imageOver(id);
		
		for( j = 0; j < Menus.length; j++){
			if( Menus[j][0] != id ){
				//SetStatus("Blanking [" + Menus[j][0] + "] j(" + j + ") i(" + i + ")");
				Menus[j][1] = false;		//set it to not visible
				Menus[j][3] = false;		//set it to not active
				Menus[j][4] = false;		//set cancelFade to false
				divName = Menus[j][0] + "-Div";
				changeOpac(0, divName);	//fade to black
				imageOut(Menus[j][0]);
				setMenuZ( divName, "0");
			}
		}
		
		//set the flage to visible
		Menus[i][1] = true;
		
		//display the intended menu
        for(j = 0; j <= 100; j++) {
            setTimeout("changeOpac(" + j + ",'" + sectionName + "')",(timer * speed));
            timer++;
        }
		
    } else if(!makeVisible) {
		//otherwise, hide the div
		if( !Menus[i][4] && !Menus[i][3] ){
			//if we have no cancelFade
			if( Menus[i][1] ){
				//if it's visible, hide it
				//SetStatus("Fading out: no cancel, visible set to true");
				//set visible to false
				Menus[i][1] = false;
				setMenuZ( sectionName, "0");
				imageOut(id);
				
				//do the fade
				for(j = 100; j >= 0; j--)
					{
					setTimeout("changeOpac(" + j + ",'" + sectionName + "')",(timer * speed));
					timer++;
				}
			} else {
				//SetStatus("Fading out: no cancel, visible set to false");
				//otherwise do nothing
			}
		} else if( Menus[i][3] ) {
			//otherwise, go to full opacity
			//SetStatus("Fading out: cancel");
			changeOpac(100, sectionName );
		}
    }
}
//====================================================================================================
//======================================================================= showMenu
//====================================================================================================
function showMenu( sectionId ){
	i = GetSectionIndex( sectionId );
	//SetStatus("showMenu: " + sectionId + " i: " + i);
	
	if( !Menus[i][1] ){
		//fade in
		Menus[i][3] = true;
		Menus[i][4] = true;
		fade( sectionId, true, 200);
	}
}
//====================================================================================================
//======================================================================= hideMenu
//====================================================================================================
function hideMenu( sectionId ){
	i = GetSectionIndex( sectionId );
	//SetStatus("hideMenu: " + sectionId + " i: " + i);
		
	if( Menus[i][1] ){
		//fade out
		Menus[i][3] = false; //set active to false
		Menus[i][4] = false; //set cancel to false
		setTimeout("fade( '" + sectionId + "', false, 300 )", 2000);
	}
}
//====================================================================================================
//======================================================================= hideMenu
//====================================================================================================
function hideAllMenus( ){
	//SetStatus("hideAllMenus: ");
	
	for( i=0; i<Menus.length; i++){
		//fade out
		Menus[i][1] = false;
		Menus[i][3] = false; //set active to false
		Menus[i][4] = false; //set cancel to false
		divName = Menus[i][0] + "-Div";
		changeOpac(0, divName);	//fade to black
		imageOut(Menus[i][0]);
	}
}
//====================================================================================================
//======================================================================= enterMenu
//====================================================================================================
function enterMenu( sectionId ){
	i = GetSectionIndex( sectionId );
	//SetStatus("enterMenu: " + sectionId + "Menus[" + i + "][1] = " + Menus[i][1]);
	if( Menus[i][1] ){ //if visible
		Menus[i][3] = true; // active = true
		Menus[i][4] = true; // cancelFade = true
	}
}
//====================================================================================================
//======================================================================= leaveMenu
//====================================================================================================
function leaveMenu( sectionId ){
	i = GetSectionIndex( sectionId );
	if( Menus[i][1] ){
		//SetStatus("leaveMenu: " + sectionId);
		Menus[i][3] = false; // active = false
		Menus[i][4] = false; // cancelFade = false
		hideMenu( sectionId ); //toggle the section if visible
	}
}
//====================================================================================================
//======================================================================= homeOver
//====================================================================================================
function homeOver(){
	hideAllMenus();
	imageOver("Menu-Home");
}
//====================================================================================================
//======================================================================= homeOut
//====================================================================================================
function homeOut(){
	imageOut("Menu-Home");
}
//====================================================================================================
//======================================================================= imageOver
//====================================================================================================
function imageOver( imageId ){
	//alert("imageOver: " + imageId + " == " + document.images[imageId].src + " new: " + "./images/" + imageId + "_over.jpg");
	document.images[imageId].src = "./images/" + imageId + "_over.jpg";
}
//====================================================================================================
//======================================================================= imageOff
//====================================================================================================
function imageOut( imageId ){
	document.images[imageId].src = "./images/" + imageId + ".jpg";
}
//====================================================================================================
//======================================================================= LoadImagePopup
//====================================================================================================
function LoadImagePopup(id){
	//Popup("?action=Error");
	if( id > 0 ){
		window.open("image_popup.php?image_id=" + id,"", "menubar=no,scrollbar=no,status=no,resizable=no,toolbar=no,titlebar=no,location=no");
	} else {
		//Popup( "?action=Error" );
	}
}
//====================================================================================================
//======================================================================= Debug
//====================================================================================================
function SetStatus( message ){
	if(navigator.appName == 'Netscape'){ 
		var object = document.getElementById('status');
 	} else if(navigator.appName == "Microsoft Internet Explorer") {
		var object = document.all['status'];
	}
	
	object.innerHTML += message + "<br>";
}