<!--
/*****************************************************************************
Author: 
 Name: homelib.js
 Date: 
 Description: 
*****************************************************************************/

//SECTION TO ACTIVATE
var section  = 'life'

//GLOBALS
var isLoaded = 0;
var imgPreload = new Array;
var img = 0;
var menuID;
var animLevel = 0;
var newMenu = '';
var currMenu = '';
var clipCount = 0;
var delay = 0;
var origHeight = '';
var st = 0;

//BROWSER SPECIFIC
var isNN = (document.layers) ? 1:0
var isIE = (document.all) ? 1:0

//CONTENT
var UNTERNEHMENITEMS = new Array()
UNTERNEHMENITEMS[0] = new menuItem("wirueberuns","img/menu/button_wirueberuns_off.gif","unternehmen/wir.html");
UNTERNEHMENITEMS[1] = new menuItem("positionierung","img/menu/button_positionierung_off.gif","unternehmen/position.html");
UNTERNEHMENITEMS[2] = new menuItem("historie","img/menu/button_historie_off.gif","unternehmen/historie.html");
UNTERNEHMENITEMS[3] = new menuItem("team","img/menu/button_team_off.gif","unternehmen/team.html");
UNTERNEHMENITEMS[4] = new menuItem("koop","img/menu/button_koop_off.gif","unternehmen/kooperation.html");
var UNTERNEHMEN = new menu("unternehmen",50,136,UNTERNEHMENITEMS)

var PRODUKTEITEMS = new Array()
PRODUKTEITEMS[0] = new menuItem("bakterien","img/menu/button_bakterien_off.gif","produkte/bakterien.html")
PRODUKTEITEMS[1] = new menuItem("facs","img/menu/button_facs_off.gif","produkte/facs.html")
PRODUKTEITEMS[2] = new menuItem("protein","img/menu/button_protein_off.gif","produkte/protein.html")
PRODUKTEITEMS[3] = new menuItem("strukturen","img/menu/button_strukturen_off.gif","produkte/strukturen.html")
PRODUKTEITEMS[4] = new menuItem("zellen","img/menu/button_zellen_off.gif","produkte/zellen.html")
var PRODUKTE = new menu("produkte",150,136,PRODUKTEITEMS)

var techITEMS = new Array()
techITEMS[0] = new menuItem("hintergrund","img/menu/button_hintergrund_off.gif","technologie/hintergrund.html")
techITEMS[1] = new menuItem("expression","img/menu/button_expression_off.gif","technologie/express.html")
techITEMS[2] = new menuItem("patente","img/menu/button_patente_off.gif","technologie/patente.html")
var tech = new menu("tech",250,136,techITEMS)



var INVESTITEMS = new Array()
INVESTITEMS[0] = new menuItem("investoren","img/menu/button_investoren_off.gif","ir/investoren.html")
INVESTITEMS[1] = new menuItem("finanz","img/menu/button_finanz_off.gif","ir/finanz.html")
var INVEST = new menu("invest",350,136,INVESTITEMS)

var KONTAKTITEMS = new Array()
KONTAKTITEMS[0] = new menuItem("adresse","img/menu/button_adresse_off.gif","kontakt/adresse.html")
KONTAKTITEMS[1] = new menuItem("form","img/menu/button_form_off.gif","kontakt/formular.html")
KONTAKTITEMS[2] = new menuItem("anfahrt","img/menu/button_anfahrt_off.gif","kontakt/anfahrt.html")
KONTAKTITEMS[3] = new menuItem("impressum","img/menu/button_impressum_off.gif","kontakt/impressum.html")
var KONTAKT = new menu("kontakt",450,136,KONTAKTITEMS)


//ALL TABLE MENU'S
var menuNum = 0;
var menus = new Array()
menus[menuNum++] = UNTERNEHMEN
menus[menuNum++] = PRODUKTE
menus[menuNum++] = tech
menus[menuNum++] = INVEST
menus[menuNum++] = KONTAKT


/*****************************************************************************
Function: menu

Description:
  //MENU OBJECT
	
Parameters: 
  id
	xpos
	ypos
	child

Modified: 
*****************************************************************************/	
function menu(id,xpos,ypos,child) {
	this.id = id
	this.xpos = xpos
	this.ypos = ypos
	this.child = child
}


//MENU ITEM OBJECT
function menuItem(id,img,href) {
	this.id = id
	this.img = img
	this.href = href
}


//DO NS RELOAD
function refreshPage() {
	if (innerWidth != origWidth || innerHeight != origHeight){
  	  location.reload();
	}
}


//IE: BUILD THE MENU'S
function buildMenusIE() {
	var i,j;
	for (i = 0; i < menus.length; i++) {
		thisMenu = menus[i]
		mh = thisMenu.child.length * 10
		document.write("<div id=" + thisMenu.id + "") 
		document.write(" style=position:absolute;visibility:hidden;top:0;left:0;height:"+mh+";width:100;")
		document.write(" onMouseOut = \"menuPopDown('" + thisMenu.id + "');\">")
		document.write("<table cellspacing=0 cellpadding=0 border=0 width=100 bgcolor='#0A6E80'")
		for (j = 0; j < thisMenu.child.length; j++) {
			thisChild = thisMenu.child[j]
			document.write("<tr><td>")
			document.write("<a href="+thisChild.href+" onmouseover=nimgSwitch(\"" + thisChild.id + "\")")
			document.write(" onmouseout=nimgSwitch(\"" + thisChild.id + "\");>")
			document.write("<img src="+thisChild.img+" name="+thisChild.id+" border=0></a>")
			document.write("</td></tr>")
		}
		document.write("</table></div>")
		posMenu(thisMenu.id,thisMenu.xpos,thisMenu.ypos)
	}
}	


//NS: BUILD MENUS
function buildMenusNS() {
	var i,j;
	for (i = 0; i < menus.length; i++) {
		thisMenu = menus[i]
		mh = thisMenu.child.length * 10
		document.write("<layer name=" + thisMenu.id + " visibility=hide width=100 height=" + mh + "")
		document.write(" onMouseOut= \"menuPopDown('" + thisMenu.id + "', event);\">")
		document.write("<table cellspacing=0 cellpadding=0 border=0 width=100 bgcolor=0A6E80>")
		for (j = 0; j < thisMenu.child.length; j++) {
			thisChild = thisMenu.child[j]
			document.write("<tr><td>")
			document.write("<a href="+thisChild.href+" onMouseOver=nimgSwitch(\""+thisChild.id+"\",\""+ thisMenu.id +"\")")
			document.write(" onMouseOut=nimgSwitch(\""+thisChild.id+"\",\""+thisMenu.id+"\")>")
			document.write("<img src="+thisChild.img+" name="+thisChild.id+" border=0></a>")
			document.write("</td></tr>")
		}
		document.write("</table></layer>")
		posMenu(thisMenu.id,thisMenu.xpos,thisMenu.ypos)
	}
}	


//POSITION THE MENU
function posMenu(menu,x,y) {
	if (isNN) {
		thisMenu = document.layers[menu]
		thisMenu.moveTo(x,y)
	} else {
		thisMenu = document.all[menu]
		thisMenu.style.left = x
		thisMenu.style.top = y
	}
}


//CHECK POSITION OF MOUSE TO MENU
// Only works in IE.
function checkPosMouse() {
	if (currMenu == "") {
			return
	} 
	
	else if (currMenu != "") {
		
		var menuWidth = document.all[currMenu].style.pixelWidth
		var menuHeight = document.all[currMenu].style.pixelHeight
		var menuTop = document.all[currMenu].style.pixelTop -30
		var menuBottom = menuHeight + menuTop + 40
		var menuLeft = document.all[currMenu].style.pixelLeft 
		var menuRight = menuLeft + menuWidth 
		var mouseX = event.clientX 
		var mouseY = event.clientY - 10
			
			if (mouseX >= menuLeft && mouseX <= menuRight && mouseY >= menuTop && mouseY <= menuBottom) {
				return
			} 
	
			else if (currMenu != ""){
				menuPopDown(currMenu)
			}
	}
}


//POP MENU UP
// 
function menuPopUp(menu) {
	if ((!isNN && currMenu == menu && document.all[menu].style.visibility == 'visible')
		||
		(isNN && currMenu == menu && document.layers[menu].visibility == 'show'))
		return;
	
	newMenu = menu;
	hideAll();
	
	if (isNN) {
		document.layers[newMenu].visibility = 'show'
	} 
	
	else {
			document.all[newMenu].style.visibility = 'visible'
	}
	
	currMenu = newMenu;
	scrollDown(newMenu);
}


//RESET MENU TO DEFAULT
function resetMenu(menu) {
	if (isNN) {
		var activeMenu = document.layers[menu]
		activeMenu.clip.bottom = 0
		} else {
			var activeMenu = document.all[menu]
			activeMenu.style.clip = "rect(0px 100px 0px 0px)"
		}
}


//FIND THE CLIP VALUE
function clipValues(menu) {
	if (isNN) {
		var thisMenu = document.layers[menu]
		return thisMenu.clip.bottom
		} else {
			if( document.all[currMenu]){
				var thisMenu = document.all[currMenu].style
				var clipVal = thisMenu.clip.split("rect(")[1].split(")")[0].split("px")
				btClip = clipVal[2]
				return (btClip)
			}
	}
}


//CLIP THE MENU
function clipBy(menu,bClip) {
	currClip = clipValues(menu)
	if (isNN) {
		var clipMe = clipCount * (gMenuHeight()/4)  + bClip
		var thisMenu = document.layers[menu]
		thisMenu.clip.bottom = clipMe
		} else {
			var clipMe = clipCount * (gMenuHeight()/4) + bClip
			var thisMenu = document.all[menu].style
			thisMenu.clip = "rect(0px 100px " + clipMe + "px 0px)"
	}
}


//GET THE HEIGHT OF UNCLIPPED CURRMENU
function gMenuHeight() {
	if (isNN){
		return document.layers[currMenu].document.height
		} else if(document.all[currMenu]){
			return document.all[currMenu].style.pixelHeight + 20
	}
}


//REVEAL DOWN
function scrollDown(dir) {
	clearTimeout(st)
	if (clipValues(currMenu) < gMenuHeight()) { 
		clipBy(currMenu,gMenuHeight()/100)
		clipCount++
		st = setTimeout("scrollDown()",30)
		} else {
			clearTimeout(st)
			clipCount = 0;
	}
}

/******************************************************************************
Function: menuPopDown()

Description:  Hides a specific menu based on position of the
              mouse after a mouseout event.

Parameters: 
            menu - the name of the section to hide (Life, 
                   Knowledge, etc.); string
            evt - This is the Event object for Netscape.  This
                  will be used to determine position; object.
			
Modified: 
*****************************************************************************/

function menuPopDown(menu, evt) {
	
	// Declarations
	var menuWidth;   // width of the div or layer containing the menu.
	var menuHeight;  // height of the dive or layer containing the menu.
	var menuTop;     // Y coordinate of the menu in the browser.
	var menuBottom;  // The menu's Y coord. plus its height.
	var menuLeft;    // X coordinate of the menu in the browser.
	var menuRight;   // The menu's X coord. plus its width.
	var mouseX;      // Place where cursor is on the document (Left to Right).
	var mouseY;      // Place where cursor is on the document (Top to Bottom).
	var intScrollTop // Only used in IE. Amount of pixels the browser is scrolled down.
	
	// Check to see what type of browser it is.
	//*** Netscape ***	
	if(isNN) {
		
		// Retrieve all positioning info. from elements and the Event object.
		menuWidth = document.layers[menu].clip.width;
		menuHeight = document.layers[menu].clip.height;
		menuTop = document.layers[menu].top - 30;
		menuBottom = menuTop + menuHeight + 40;
		menuLeft = document.layers[menu].left; 
		menuRight = menuWidth + menuLeft;
		mouseX = evt.pageX;
		mouseY = evt.pageY - 10;
		
		//Make sure that the cursor is off the menu before hiding.
		if(mouseX <= menuLeft + 1 || mouseX >= menuRight || mouseY >= menuBottom - 5 || mouseY <= menuTop) {
				hider(currMenu);
				setState(currMenu, 'off');
		}
	}
	
	//*** IE ***
	// Test to see if mouse is over the current Menu.
	else if(isIE){
		
		// Need to retrieve scroll pos. for IE due to a positioning problem when
		// the page is not scrolled to the top.	
		intScrollTop = document.body.scrollTop;
		
		// Retrieve all positioning from the event object and elements.
		menuWidth = document.all[currMenu].style.pixelWidth;
		menuHeight = document.all[currMenu].style.pixelHeight;
		menuTop = document.all[currMenu].style.pixelTop - 30;
		menuBottom = menuHeight + menuTop + 40;
		menuLeft = document.all[currMenu].style.pixelLeft;
		menuRight = menuLeft + menuWidth; 
		
		// Add the scroll position to the cursor coordinates.  If not
		// the coordinates will be based on position of mouse in the viewable 
		// document.
		mouseX = event.clientX + intScrollTop; 
		mouseY = event.clientY - 10  + intScrollTop;
		
		if(mouseX <= menuLeft + 1 || mouseX >= menuRight || mouseY >= menuBottom - 5 || mouseY <= menuTop + 5) {
				hider(currMenu);
				setState(currMenu, 'off');
		}
	}
}


//GENERIC LAYER HIDE
function hider(menu) {

	if (isNN) {
		document.layers[menu].visibility = 'hide'
	} 
	
	else {
		document.all[menu].style.visibility = 'hidden'
	}
}


//HIDE ALL THE MENUS
function hideAll() {
		
	if (currMenu) {
		setState(currMenu,'off')
	}
	
	for (i = 0; i < menus.length; i++) {
		thisMenu = menus[i];
		hider(thisMenu.id);
		resetMenu(thisMenu.id);
	}
}


//SET THE STATE ON AN IMAGE
function setState(id,state) {
	var strURL = document.URL; //Holds the URL of the current document.
	var intPosition; 					 // Position of the first forward slash ("/").
	var strSection;						 // Section the web page is in.
	var ref = id + 'img'; 		 // ID of the menu item and "img" for retrieval of the other state image.
	
	// *** Find out which section the web page is in. ***
	// Search the string without the protocol(ie. http://)
	intPosition = strURL.indexOf("/", 7) + 1;
	strSection = strURL.substr(intPosition, strURL.indexOf("/", intPosition) - intPosition);

	// *** Only change images if the section is different from the menu being looked at. ***
	// Check the Id of the menu with the section.
	// Knowledge ID is spelled different than the section, so check for that.
	
	if(id == 'knwledge') {
		if(strSection != 'knowledge')
			document.images[ref].src = 'img/menu/button_' + ref + '_' + state + '.gif';
	}
	
	else if(id != strSection) {
		document.images[ref].src = 'img/menu/button_' + ref + '_' + state + '.gif';
	}
		
}


//IMAGE SWITCH
function nimgSwitch(img,menu) {

	//*** Check to see what type of browser
	
	//*** If Netscape
	if (isNN) {
		
		if (menu) {
			var state = (document.layers[menu].document.images[img].src.indexOf('_off.gif') >= 0) ? '_on.gif' : '_off.gif';
			var thisImg = 'img/menu/button_' + img + state;
			document.layers[menu].document.images[img].src = thisImg
		} 
		
		else {
			var state = (document.images[img].src.indexOf('_off.gif') >= 0) ? '_on.gif' : '_off.gif';
			var thisImg = (img.match(currMenu))? 'img/menu/button_' + img + '_on.gif' : 'img/menu/button_' + img + state;
			document.images[img].src = thisImg
		}
	} 
	
	//*** If IE
	else {
		//*** Find out what state the image is in and set it to the opposite.
		var state = (document.images[img].src.indexOf('_off.gif') >= 0) ? '_on.gif' : '_off.gif';

		//*** Check the image name with the current menu + 'IMG'.
		//*** If the names are the same then leave the image on otherwise, set it based on the state.
		var thisImg = (img.toUpperCase() == currMenu.toUpperCase() + 'IMG')? 'img/menu/button_' + img + '_on.gif' : 'img/menu/button_' + img + state;
		document.images[img].src = thisImg
	}
}


//NS: PRELOAD LAYER EMBEDDED IMAGES FOR NS	
function getImages() {
	
	if (isNN) {
			
			for (i = 0; i < document.layers.length; i++) {
				
				var thisLayer = document.layers[i]
				
				for (j = 0; j < thisLayer.document.images.length; j++) {
					
					if (document.images[j].name) {
						imgPreload[img] = new Image() ;
						imgPreload[img].src = 'img/menu/button_' + thisLayer.document.images[j].name + '_on.gif' ;
						img++;
				}
			}
		}
	}
}


//GET IMAGE'S
function npreloadImgs() {
	//*** Loop through all the images on the page.
	for (i = 0; i < document.images.length; i++) {
		
		//*** Check to see if the image has a name.
		
		//*** If the image has a name
		if (document.images[i].name) {
				//*** Preload the image.
				imgPreload[img] = new Image() ;
				imgPreload[img].src = 'img/menu/button_' + document.images[i].name + '_on.gif' ;
				img++;
			}
		}
		
	getImages(); 
	setState(section,'off'); //change to on!!
}


//BUILD THE MENU'S
//*** NN ***
if (isNN) {
	buildMenusNS();
} 

//*** IE ***
else if(isIE) {
	buildMenusIE();
}

//-->

