// JavaScript Document
// All js below is written by Sherri Kalm -  sherrikalm@hotmail.com
// unless otherwise noted
// if you want to use it go right ahead

//this it used to get a clicked menu to disappear if you click it again
var lastOneClicked = "n"; // not in use see fnToggleMenu below
var activeTab = "";
var activeMenu = "";

function fnMakeThisTabActive(tab) {	
document.getElementById(tab).className="tabmenuActive";
activeTab = tab;
}

function fnMakeThisTabNotActive(tab) {	
document.getElementById(tab).className="tabmenu";
activeTab="";
}

function fnHideMenus(){
	//hides all menus
	var ar = document.getElementById("MenuHolder").getElementsByTagName("div");
	for (var i=0; i<ar.length; i++){
		ar[i].style.visibility = "hidden";
	}
}

function fnShowThisMenu(menuName){
	var ar = document.getElementById("MenuHolder").getElementsByTagName("div");
	for (var i=0; i<ar.length; i++){
		ar[i].style.visibility = "hidden";
		if(ar[i].id == menuName){
		ar[i].style.visibility = "visible";
		}
	}
	activeMenu = menuName;
}

function fnTabMOver(menuName, tab){
//what to do if the mouse is over a tab
//only one tab can be active at a time
//only one menu should be visible at a time

//If any tab other tab is active make it Not active
	if(activeTab != ""){
		fnMakeThisTabNotActive(activeTab);
	}
//If any menu is visible hide it
	if(activeMenu != ""){
		fnHideMenus();
	}
//Make yourself the active tab
	fnMakeThisTabActive(tab);
//make your menu visible
	fnShowThisMenu(menuName);

} //close funtion

function fnTabMOut(menuName, tab) {
//If tab's menu is not open then
// make tab not active
// make tab's menu disappear
	
}

function fnMenuMOver(menuName, tab) {
	//make your tab active
	fnMakeThisTabActive(tab);
	//make your menu stay visible
	fnShowThisMenu(menuName);
}

function fnMenuMOut(menuName, tab) {
	//make menu's tab not active
	fnMakeThisTabNotActive(tab)
	//make menu disappear
	fnHideMenus();
	
}



function fnToggleMenu(menuName, menu){
	//this function is not used in this site but it works and 
	// it is kind of cool soo....
	// if you want menus to appear and onclick well have at it..
//toggle the menus on click

//make the menus appear or disappear
//only one menu should be visible at a time
//if a menu is reclicked - close it
	if(document.getElementById){
		var ar = document.getElementById("MenuHolder").getElementsByTagName("div");
		//if we clicke on home make all the menus disappear
		//alert(ar[1].className);
		if(menuName == 'tdHome' || menuName == 'tdList'){
			for (var i=0; i<ar.length; i++){
				ar[i].style.visibility = "hidden";				
				lastOneClicked = "";					
			}
		}else{		
			//toggle menus 
			for (var i=0; i<ar.length; i++){							
				//check to see if this is a re-click
				if(ar[i].id == lastOneClicked){
					ar[i].style.visibility = "hidden";
					lastOneClicked = "";					
				}else{
					if(ar[i].id == menuName){
					ar[i].style.visibility = "visible";
					lastOneClicked = menuName;					
					}else{
					ar[i].style.visibility = "hidden";					
					}
				}
			}
		}
		
	}
	

} //close funtion

//////////////////////////////////////////////////////////////////////////////////////////////
// This adjusts the drop down menus to be under their parents
//////////////////////////////////////////////////////////////////////////////////////////////

function fnFindMenuPosition(){	
	
	var cell; //the cell are what we want to line up against
	var divCurXPos; //current X or left position of the div
	var divCurYPos; //current Y or top position of the div

	
	var arDivs = document.getElementById("MenuHolder").getElementsByTagName("div"); 
	for (var i=0; i<arDivs.length; i++){							
		//move the menus so they are underneath corresponding table cells
		switch(arDivs[i].id){
			case "menu1":
					cell = document.getElementById('tdMenu1');
					divCurXPos = findPosX(cell);
					divCurYPos = findPosY(cell);//cell.offsetTop; //findPosY(cell);
					arDivs[i].style.left = (divCurXPos - 7) + "px";
					divCurYPos = divCurYPos + cell.offsetHeight;	
					//alert(divCurYPos + cell.offsetHeight);
					arDivs[i].style.top = '0px';//divCurYPos + "px";
			break;
			
			case "menu2":
					cell = document.getElementById('tdMenu2');
					divCurXPos = findPosX(cell);
					divCurYPos = findPosY(cell);//cell.offsetTop; //findPosY(cell);
					arDivs[i].style.left = (divCurXPos - 7) + "px";
					divCurYPos = divCurYPos + cell.offsetHeight;	
					arDivs[i].style.top = '0px';//divCurYPos + "px";
			break;
			
			case "menu3":
					cell = document.getElementById('tdMenu3');
					divCurXPos = findPosX(cell);
					divCurYPos = findPosY(cell);//cell.offsetTop; //findPosY(cell);
					arDivs[i].style.left = (divCurXPos - 7) + "px";
					divCurYPos = divCurYPos + cell.offsetHeight;	
					arDivs[i].style.top = '0px';//divCurYPos + "px";
			break;

			case "menu4":
					cell = document.getElementById('tdMenu4');
					divCurXPos = findPosX(cell);
					divCurYPos = findPosY(cell);//cell.offsetTop; //findPosY(cell);
					arDivs[i].style.left = (divCurXPos - 7) + "px";
					divCurYPos = divCurYPos + cell.offsetHeight;	
					arDivs[i].style.top = '0px';//divCurYPos + "px";
			break;

		} 
		
	}	

IsHome();

}



function IsHome(){
	
	if (window.document.title == "Surefish - Home"){
		BoxMatchUp();
		NavBoxFix();
	}
	
}
//////////////////////////////////////////////////////////////////////////
//This load of nonsense fixes up the box heights on the home page
//////////////////////////////////////////////////////////////////////////
function BoxMatchUp(){
//swap the top of the boxes so they line up
	var topBar = document.getElementById('flashyTopbar');
	var LeftBox = document.getElementById('Inner_BoxLeft');
	var RightBox = document.getElementById('Inner_BoxRight');
	var t = topBar.offsetHeight + 10; //findPosX(flashyTopbar);
	RightBox.style.top = t + "px";
	LeftBox.style.top = t + "px";
	
	//now make them the same height
	var boxHeight;
	//make both boxes the height of the tallest box
	if (RightBox.offsetHeight > LeftBox.offsetHeight) {	
		//right side is taller than left side
		boxHeight = RightBox.offsetHeight; //document.getElementById('Inner_BoxRight').style.height;//findPosX(RightBox); //
		//alert('r bigger  ' + boxHeight);
		//alert('hi');
		LeftBox.style.height = boxHeight + "px";
		//now adjust the heights to be equal - this is a hack to get around a bug - yippee!
		RightBox.style.height = LeftBox.style.height;
		
		//alert('r: ' + RightBox.style.height + ' -- l: ' + LeftBox.style.height); 
	}else{
		//left side is taller than right side
		
		boxHeight = LeftBox.offsetHeight;//findPosX(LeftBox); //LeftBox.offsetHeight;
		
		//alert('l bigger   ' + boxHeight);
		//alert('r: ' + RightBox.stye.height);
		RightBox.style.height = boxHeight + "px";
		
		//now adjust the heights to be equal - this is a hack to get around a bug - yippee!
		//LeftBox.style.height = RightBox.stye.height;
		LeftBox.style.height = RightBox.style.height;
		//alert('r: ' + RightBox.style.height + ' -- l: ' + LeftBox.style.height);
	}
}
/////////////////////////////////////////////////////////////////////////////////
//this is a big ugly mess
////////////////////////////////////////////////////////////////////////////////
//essentially we want to do two things
// 1. find out where the logos need to be placed under the boxes and put them there
// 2. find out how much total space is used to make the nice white box to contain them
////////////////////////////////////////////////////////////////////////////////
function NavBoxFix(){
	if(navigator.appName == "Microsoft Internet Explorer") {
		//SetBoxHeightsNS();
		SetBoxHeightsIE();
	}else if (navigator.appName == "Netscape"){
		SetBoxHeightsNS();
	}else{
		alert("This site has not been tested in browsers other than IE and NS (minimally) - you may have some difficulty on the home page");
		SetBoxHeightsIE();
	}
}

//alert(navigator.appName);

function SetBoxHeightsIE() {

	//first figure out where the logo links box goes
	var Box;
	Box = document.getElementById('Inner_BoxLeft');
	
	var BoxHeight;
	BoxHeight = Box.style.height;
	//alert("BoxHeight: " + BoxHeight);

	var BoxTop;
	BoxTop = Box.style.top;
	//alert("BoxTop: " + BoxTop);
	
	var LogoBox;
	LogoBox = document.getElementById('LogoLinks');
	
	var LogoBoxTop;
	LogoBoxTop = parseInt(BoxTop) + parseInt(BoxHeight) + 10;
	//alert("LogoBoxTop: " + LogoBoxTop);
	
	LogoBox.style.top = LogoBoxTop + "px";
	
	var LogoBoxHeight;
	LogoBoxHeight = LogoBox.offsetHeight;	
	
	//Set the size of the main box to that of the LogoBox's top position + its height + 10	
	var MBox = document.getElementById('MainBox');
	var MBoxHeight;
	MBoxHeight = parseInt(LogoBoxTop) + 2 + LogoBoxHeight;
	//alert("MBoxHeight: " + MBoxHeight);
	MBox.style.height = MBoxHeight + "px";	
	
}

function SetBoxHeightsNS(){
	//NS does not load images - w3c spec clearly indicates that 
	// the onload event happens after the page is fully loaded
	// yet NS seems to wait for the images - the little #$@#$@ grumble
	var Box;
	Box = document.getElementById('Inner_BoxLeft');
	
	var BoxHeight;
	BoxHeight = Box.offsetHeight;
	//alert("BoxHeight: " + BoxHeight);
	
	//var BoxOffsetHeight;
	//BoxOffsetHeight = Box.offsetHeight;
	//alert("BoxOffsetHeight: " + BoxOffsetHeight);

	var BoxTop;
	BoxTop = Box.style.top;
	//alert("BoxTop: " + BoxTop);
	
	var LogoBox;
	LogoBox = document.getElementById('LogoLinks');
	
	var LogoBoxTop;
	LogoBoxTop = parseInt(BoxTop) + parseInt(BoxHeight) + 10;
	//alert("LogoBoxTop: " + LogoBoxTop);
	
	LogoBox.style.top = LogoBoxTop + "px";
	
	var LogoBoxHeight;
	LogoBoxHeight = LogoBox.offsetHeight;
	
	
	var MBox = document.getElementById('MainBox');
	var MBoxHeight;
	//MBoxHeight = 900;
	MBoxHeight = parseInt(LogoBoxTop) + 2 + LogoBoxHeight;
	//alert("MBoxHeight: " + MBoxHeight);
	
	//Set the size of the main box to that of the LogoBox's top position + its height + 10
	MBox.style.height = MBoxHeight + "px";	
	
	//window.reload();
	
}


//////////////////////////////////////////////////////////////////////////


//these two are copped from http://www.webdeveloper.com can't remember who...thanks though!
	function findPosX(obj) {
		xPos = eval(obj).offsetLeft;
		tempEl = eval(obj).offsetParent;
		while (tempEl != null) {
			xPos += tempEl.offsetLeft;
			tempEl = tempEl.offsetParent;
		}
		return xPos;
	}


	function findPosY(obj) {
		yPos = eval(obj).offsetTop;
		tempEl = eval(obj).offsetParent;
		while (tempEl != null) {
			yPos += tempEl.offsetTop;
			tempEl = tempEl.offsetParent;
		}
		return yPos;
	}

//////////////////////////////////////////////////////////////////////////////////////////////
// navigation
//////////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////////////
// this function swaps the source doc of the iframe "FlipContent"
//////////////////////////////////////////////////////////////////////////////////////////////
function SwapContent(newframeUrl) {
	//newframeUrl is the new source doc for frame	
	var ar=document.getElementsByTagName('iframe');
	for(var i=0; i<ar.length; i++) {
		if(ar[i].id=="FlipContent") {
				ar[i].src = newframeUrl;
			}
		} 
		
		//now if any menus are expanded - make them disappear
		if(document.getElementById){
		var arM = document.getElementById("MenuHolder").getElementsByTagName("div");
		//make all the menus disappear
			for (var i=0; i<arM.length; i++){
				arM[i].style.visibility = "hidden";
				lastOneClicked = "";
			}
		}

}

