
//----------------------------------------- PARAMETER HEAD ------------------------------------------

// image parameter
homeBase="./";
//homeBase="http://begamax.de/";
imgBase="img/";
//imgBase="hg/";
imgSpacer="spacer.gif";
imgBullet="menuItem.gif";
imgSubMenu="subMenu.gif";

/*
 * Images for menu bg. 
 * Syntax: imgTable_ROW_COL
 * NOTICE: If you change the Images see code of
 * 'generateMenu' to update hardcoded img sizes!!
 */
imgTable_1_1="def_menu_1.gif";
imgTable_1_2="def_menu_2.gif";
imgTable_1_3="def_menu_3.gif";
imgTable_2_1="def_menu_4.gif";
imgTable_2_3="def_menu_5.gif";
imgTable_3_1="def_menu_6.gif";
imgTable_3_2="def_menu_7.gif";
imgTable_3_3="def_menu_8.gif";

// etxtra Images for left border of submenu
imgTable_1_1sub="def_menu_1.gif";
imgTable_2_1sub="def_menu_4.gif";
imgTable_3_1sub="def_menu_6.gif";

// image sizes 
var leftWidth=10;
var topHeight=9;

var rightWidth=12;
var bottomHeight=11;

// background color
var bgColor="#F3F3F3";


// Menu layout paramerter
popMenuWidth=150;
itemTopMargin=20;

topOffset = 64;  // Banner Area Heigth

//Menu stylesheet parameter
var menuStyleName="menuNr";

//----------------------------------END OF PARAMETER HEAD------------------------------------------


// Global variables
var imageLoadFlag = 0;
var imageCache = new Array();
var menuLoadFlag = 0;
var menuCount = 0;
var onMenu = 0;
var winW, winH;
var mT = 0;
var mF = "";
var htBuffer = "";

// Defines Y-coordinate for menu
var m_x, m_y;


// Simple browser detection (seperate into:  NS4.x, IE4.x, DOCOM[5+] browsers)
var ns = (navigator.appName == 'Netscape');
var gen3 = (parseInt(navigator.appVersion) >= 3 && parseInt(navigator.appVersion) < 4);
var gen3mac = ((navigator.appName=="Netscape")&&(parseInt(navigator.appVersion)==3)&&(navigator.appVersion.indexOf("Macintosh")!=-1));
var ns4 = (ns && parseInt(navigator.appVersion) >= 4 && parseInt(navigator.appVersion) < 5);
var ns5 = (ns && parseInt(navigator.appVersion) >= 5 && parseInt(navigator.appVersion) < 6);
var ie = (navigator.appName == 'Microsoft Internet Explorer');
var ie3 = (ie && navigator.appVersion < 4);
var ie4 = (ie && parseInt(navigator.appVersion) >= 4);
var docom = (document.getElementById);
var win2k = (navigator.userAgent.indexOf('Windows NT 5.0') != -1);
var ie4mac = (ie && !docom && navigator.userAgent.indexOf('Macintosh') != -1);
var ie5mac = (navigator.appVersion.indexOf('MSIE 5.0; Macintosh')!=-1);
var dhtmlBrowser = (ie4 || ns4 || docom);
var win31 = (navigator.appVersion.indexOf("Win16") != -1)
var SHOW, HIDE;


if (ie4 || docom) {
  SHOW = "visible";
  HIDE = "hidden";
} else if (ns4) {
  SHOW = "show";
  HIDE = "hide";
}


// Menu class settings:
var allMenus = new Array();
var allMenCounter = 0;
function closeAll(except){
	for(var i=0; i<allMenus.length; i++){
		var currAllmen = allMenus[i];
		//alert("closing menu: "+currAllmen.getMenuName());
		if(currAllmen != except){
			if(!currAllmen.isSubMenu()){
				menuSwap(currAllmen.getMenuNr(),currAllmen.getMenuStartImage(),currAllmen.getInactiveSwapImgCacheNr(), HIDE);
			} else{
				subMenuSwap(currAllmen.getMenuNr(), HIDE);	
			}
		}
	}
}

// functions of DyneMneu:

function MgetTimeoutIdent(){
	return this.timeoutIdent;
}
function MsetTimeoutIdent(id){
	this.timeoutIdent = id;
}

function MaddSubMenu(newMenu){
	this.subMenus[this.smCount] = newMenu;
	this.smCount++;
	newMenu.setParentMenu(this);
	newMenu.setSubMenu(true);
}
function MgetMenuCount(){
	return this.smCount;
}
function MgetSubMenu(smNumber){
	return this.subMenus[smNumber];
}

function MgetAllDependantMenus(){
	this.allChilds = new Array();
	this.childCounter = 0;

	for(this.ix =0; this.ix < this.smCount; this.ix++){
		this.currentSubmen = this.getSubMenu(this.ix);
		//alert("inspecting: "+this.currentSubmen.getMenuName());
		this.nextGen = this.currentSubmen.getAllDependantMenus();
		for(this.m = 0; this.m< this.nextGen.length; this.m++){
			this.allChilds[this.childCounter] = this.nextGen[this.m];
			this.childCounter++;
		}
		// add direct child too
		this.allChilds[this.childCounter] = this.currentSubmen;
		this.childCounter++;
	}
	//alert(this.getMenuName()+" has "+this.allChilds.length+"childs");
	return this.allChilds;
}

function MsetMenuStartImage(name){
	this.menuStartImgName = new String(name);
}
function MgetMenuStartImage(){
	return this.menuStartImgName;
}

function MsetActiveSwapImgCacheNr(nr){
	this.activeSwapCacheNr = nr;
}
function MgetActiveSwapImgCacheNr(){
	return this.activeSwapCacheNr;
}
function MsetInactiveSwapImgCacheNr(nr){
	this.inactiveCacheNr = nr;
}
function MgetInactiveSwapImgCacheNr(){
	return this.inactiveCacheNr;
}

function MgetMenuNr(){
	return this.menuNr;
}
function MsetSubMenu(bol){
	this.isASubMenu = bol;
}
function MisSubMenu(){
	return this.isASubMenu;
}

function MsetLinkURL(url){
	this.linkURL = url;
}

function MaddMenuItem(newItem){
	this.menuItems[this.miCount] = newItem;
	this.miCount++;
	if(newItem.isSubMenuItem()){
		this.addSubMenu(newItem.getSubMenu());
	}
}
function MgetMenuItem(index){
	return this.menuItems[index];
}
function MgetItemCount(){
	return this.miCount;
}
function MgetMenuName(){
	return this.menuName;
}

function MgetParentMenu(){
	return this.parentMenu;
}
function MsetParentMenu(father){
	this.parentMenu = father;
}

// dyneMenu constructor
function DyneMenu(nr, mname){
// member vars:
	this.menuNr = nr;
	this.timeoutIdent = 0;
	this.menuName = mname;

 	this.subMenus = new Array();
	this.smCount = 0;
	this.menuItems = new Array();
	this.miCount = 0;

// add this menu to allMenusArray
	allMenus[allMenCounter] = this;
	allMenCounter++


// member functions:
	this.isSubMenu = MisSubMenu;
	this.setSubMenu = MsetSubMenu;
	this.getMenuNr = MgetMenuNr;
	this.getActiveSwapImgCacheNr = MgetActiveSwapImgCacheNr;
	this.setActiveSwapImgCacheNr = MsetActiveSwapImgCacheNr;
	this.getInactiveSwapImgCacheNr = MgetInactiveSwapImgCacheNr;
	this.setInactiveSwapImgCacheNr = MsetInactiveSwapImgCacheNr;
	this.getMenuStartImage = MgetMenuStartImage;
	this.setMenuStartImage = MsetMenuStartImage;
	this.getSubMenu = MgetSubMenu;
	this.getMenuCount = MgetMenuCount;
	this.addSubMenu = MaddSubMenu;
	this.getTimeoutIdent = MgetTimeoutIdent;
	this.setTimeoutIdent = MsetTimeoutIdent;
	this.addMenuItem = MaddMenuItem;
	this.getMenuItem = MgetMenuItem;
	this.getItemCount = MgetItemCount;
	this.getMenuName = MgetMenuName;
	this.setParentMenu = MsetParentMenu;
	this.getParentMenu = MgetParentMenu;
	this.getAllDependantMenus = MgetAllDependantMenus;
}

// menu item fuctions
function IsetLinkURL(url){
	this.linkURL = url;
}
function IgetLinkURL(){
	return this.linkURL;
}
function IsetText(txt){
	this.text = txt;
}
function IgetText(){
	return this.text;
}
function ImakeSubMenuItem(subMen){
	this.isASubMenuItem = true;
	this.subMenu = subMen;
	subMen.setSubMenu(true);
}
function IisSubMenuItem(){
	return this.isASubMenuItem;
}
function IgetSubMenu(){
	return this.subMenu;
}

function MenuItem(itemLink, itemText){
	this.linkURL = itemLink;
	this.text = itemText;

	// member fuctions:
	this.setLinkURL = IsetLinkURL;
	this.getLinkURL = IgetLinkURL;
	this.setText = IsetText;
	this.getText = IgetText;
	this.makeSubMenuItem = ImakeSubMenuItem;
	this.isSubMenuItem = IisSubMenuItem;
	this.getSubMenu = IgetSubMenu;
}

//-----------------------------------------------

function buildItemHTML(theMenu, itemNr){
//alert("building item HTML for: "+theMenu.getMenuNr()+", "+itemNr);
var isSubMenuItem = theMenu.getMenuItem(itemNr).isSubMenuItem();
var subMenu = theMenu.getMenuItem(itemNr).getSubMenu();
var parentMen = theMenu.getParentMenu();

var a = new String('<td bgcolor="'+bgColor+'"><img src="'+homeBase+imgBase+imgSpacer+'" width="1" height="'+itemTopMargin+'"><SPAN CLASS="lM"><A CLASS="lM" onMouseOver="');
	var mouseover = new String('clearTimeout('+theMenu.getMenuName()+'.getTimeoutIdent());');

	// add timout for all submenus
	if(isSubMenuItem){
		mouseover += "clearTimeout("+subMenu.getMenuName()+".getTimeoutIdent());";
		// make sub menu appear
		mouseover += "subMenuSwap("+subMenu.getMenuNr()+",SHOW);";
	}

	// clear timeoff for all father menus
	if(theMenu.isSubMenu()){
		while(parentMen){
			mouseover += "clearTimeout("+parentMen.getMenuName()+".getTimeoutIdent());";
			//alert("adding timeout for parent: "+parentMen.getMenuName());
			var nextParent = parentMen.getParentMenu();
			parentMen = nextParent;
		}
	}
	// reset prent as it is used later again !!!
	parentMen = theMenu.getParentMenu();

	// close all submenus:
		for(allsubs = 0; allsubs < theMenu.getAllDependantMenus().length; allsubs++){
			var allDeps = theMenu.getAllDependantMenus();
			var currSubMen = allDeps[allsubs];

			// if mor than on sub menu close sister menus on mourseover too
			// but do not close submenu of link !
			if(isSubMenuItem && (currSubMen.getMenuNr() != subMenu.getMenuNr())){
				mouseover += "subMenuSwap("+currSubMen.getMenuNr()+",HIDE);";
			}
			// if no submenu link, close all submenus
			if(!isSubMenuItem){
				mouseover += "subMenuSwap("+currSubMen.getMenuNr()+",HIDE);";
			}
		}

var b = new String('" onMouseOut="');
	
	// adding timeoff start on mouseout for all fathers and itself	
	var timeOffString = "";
	if(theMenu.isSubMenu()){
		timeOffString += theMenu.getMenuName()+".setTimeoutIdent(subMenuTimeOff("+theMenu.getMenuNr()+"));";
		// start timeoff for all father menus
			while(parentMen){
				if(parentMen.isSubMenu()){
					timeOffString += parentMen.getMenuName()+".setTimeoutIdent(subMenuTimeOff("+parentMen.getMenuNr()+"));";
				} else{
					timeOffString += parentMen.getMenuName()+".setTimeoutIdent(menuTimeOff("+parentMen.getMenuNr()+",'"+parentMen.getMenuStartImage()+"',"+parentMen.getInactiveSwapImgCacheNr()+"));";
				}
				//alert("adding timeout start (!) for parent: "+parentMen.getMenuName());
				var nextParent = parentMen.getParentMenu();
				parentMen = nextParent;
			}
	} else{
		timeOffString += theMenu.getMenuName()+".setTimeoutIdent(menuTimeOff("+theMenu.getMenuNr()+",'"+theMenu.getMenuStartImage()+"',"+theMenu.getInactiveSwapImgCacheNr()+"));";
	}

	// only for submenu items add Icon on right
	if(isSubMenuItem){
		timeOffString += subMenu.getMenuName()+".setTimeoutIdent(subMenuTimeOff("+subMenu.getMenuNr()+"));";
	}

var c = new String('" HREF="');
var d = new String('">');
var e = new String('</A></SPAN></TD>');
var f = new String('<TD bgcolor="'+bgColor+'">&nbsp;</TD>');

// add icon on right side for subMenu items
if(isSubMenuItem){
	f = new String('<td align="right" bgcolor="'+bgColor+'"><IMG SRC="'+homeBase+imgBase+imgSubMenu+'"></td>');
}

var itemHTML = a+mouseover+b+timeOffString+c+theMenu.getMenuItem(itemNr).getLinkURL()+d+theMenu.getMenuItem(itemNr).getText()+e+f;
//alert(theMenu.getMenuName()+" item: "+itemNr+" has tag: \n"+itemHTML);
return itemHTML;
}


function buildMenu(theMenu) {
//alert("generate menu: "+theMenu.getMenuNr());
 if (dhtmlBrowser) {
  var isSubMenu = theMenu.isSubMenu();
  var dU = theMenu.getMenuNr();
  var dN = menuStyleName + dU;
     
	document.write('<DIV ID="' + dN + '">');
	document.write('<table border="0" width="'+popMenuWidth+'" cellspacing="0" cellpadding="0">');

		document.write('<tr>');
		if(isSubMenu){
			document.write('<td height="'+topHeight+'" valign="top"><img src="'+homeBase+imgBase+imgTable_1_1sub+'" width="'+leftWidth+'" height="'+topHeight+'"></td>');
		} else{
			document.write('<td height="'+topHeight+'" valign="top"><img src="'+homeBase+imgBase+imgTable_1_1+'" width="'+leftWidth+'" height="'+topHeight+'"></td>');
		}
		document.write('<td background="'+homeBase+imgBase+imgTable_1_2+'" height="'+topHeight+'" colspan="3" valign="top"><img src="'+homeBase+imgBase+imgSpacer+'" width="'+popMenuWidth+'" height="1"></td>');
		document.write('<td height="'+topHeight+'" valign="top"><img src="'+homeBase+imgBase+imgTable_1_3+'" width="'+rightWidth+'" height="'+topHeight+'"></td>');
		document.write('</tr>');

		for (var itemCount = 0; itemCount < theMenu.getItemCount(); itemCount++) {
			document.write('<tr>');
			if( itemCount==0 ){
				if(theMenu.isSubMenu() ){
					document.write('<td  background="'+homeBase+imgBase+imgTable_2_1sub+'" rowspan="'+theMenu.getItemCount()+'"><img src="'+homeBase+imgBase+imgSpacer+'" width="6" ></td>');
				}else{
					document.write('<td  background="'+homeBase+imgBase+imgTable_2_1+'" rowspan="'+theMenu.getItemCount()+'"><img src="'+homeBase+imgBase+imgSpacer+'" width="6" ></td>');
				}
			}
			document.write('<td valign="middle" bgcolor="'+bgColor+'"><IMG SRC="'+homeBase+imgBase+imgBullet+'"></td>');
			document.write(buildItemHTML(theMenu,itemCount));
			//document.write('<td valign="middle" align="right" ><IMG SRC="'+homeBase+imgBase+imgBullet+'"></td>');
			if( itemCount == 0 )
				document.write('<td background="'+homeBase+imgBase+imgTable_2_3+'" rowspan="'+theMenu.getItemCount()+'" ><img src="'+homeBase+imgBase+imgSpacer+'" width="'+rightWidth+'" ></td>');
			document.write('</tr>');
		}

		document.write('<tr>');
		if(theMenu.isSubMenu()){
			document.write('<td valign="bottom" height="'+bottomHeight+'"><img src="'+homeBase+imgBase+imgTable_3_1sub+'" width="'+leftWidth+'" height="'+bottomHeight+'"></td>');
		} else{
			document.write('<td valign="bottom" height="'+bottomHeight+'"><img src="'+homeBase+imgBase+imgTable_3_1+'" width="'+leftWidth+'" height="'+bottomHeight+'"></td>');
		}

		document.write('<td colspan="3" background="'+homeBase+imgBase+imgTable_3_2+'" height="6"><img src="'+homeBase+imgBase+imgSpacer+'" width="'+popMenuWidth+'" height="1"></td>');
		document.write('<td valign="bottom" height="'+bottomHeight+'"><img src="'+homeBase+imgBase+imgTable_3_3+'" width="'+rightWidth+'" height="'+bottomHeight+'"></td>');
		document.write('</tr>');
	document.write('</table>');
	document.write('</div>');


  menuCount++;
  // orig Vers.: if (menuCount == 3) menuLoadFlag = 1;
  if (menuCount <= 1) menuLoadFlag = 1;

 }
}



function finishMenu(mId) {
	if (mId ==2) menuLoadFlag = 1;
}

function menuSwap(menuNr, oldImg, newImg, vizProp) {
//alert("oldImg is: "+oldImg+" document.images[oldImg] is: "+document.images[oldImg]);
  if (menuLoadFlag && imageLoadFlag) {
    if (vizProp == SHOW) {
      if (mF) {
        eval(mF);
        clearTimeout(mT);
      }
    } else
    mF = "";

	// Swap Menu start image 
	document.images[oldImg].src = imageCache[newImg].src;

    vizElement(menuStyleName + menuNr, vizProp);
    onMenu = menuNr;
  }
}

function subMenuSwap(menuNr, vizProp) {
  if (menuLoadFlag && imageLoadFlag) {
    if (vizProp == SHOW) {
    } else
    mF = "";
    vizElement(menuStyleName + menuNr, vizProp);
    onMenu = menuNr;
  }
}


function menuTimeOff(menuNr, oldImage, newImage) {
//alert("Setting timeoff for: "+menuNr+"," +oldImage+","+newImage);
   if (menuLoadFlag && imageLoadFlag) {
    mF = "menuSwap("+menuNr+",'"+oldImage+"', "+newImage+",HIDE)";
	//alert(" setting timout to function call: "+mF);
    mT = setTimeout(mF, 3000);
    //alert("done");
   return mT;
  }
}

function subMenuTimeOff(menuNr) {
  if (menuLoadFlag && imageLoadFlag) {
    mF = "subMenuSwap("+ menuNr+", HIDE)";
    mT = setTimeout(mF, 2000);
   return mT;
  }
}


function releaseTimeoff(){
	for(var i = 0; i < releaseTimeoff.arguments.length; i++){
		clearTimeout(releaseTimeoff.arguments[i]);
	}
}

function eleHeight(eleId)
{
//alert("eleIdHeigt");
   if (ie4)
     return eval('document.all.' + eleId + '.offsetHeight');
   else if (ns4)
     return eval('document.' + eleId + '.document.height');
   else if (docom)
     return document.getElementById(eleId).offsetHeight;
}

function vizElement(eleId, vizProp)
{
//alert("vizElement: "+eleId);
  if (docom) document.getElementById(eleId).style.visibility = vizProp;
  else if (ie4) eval('document.all.' + eleId + '.style.visibility = "' + vizProp + '"');
  else if (ns4) eval('document.' + eleId + '.visibility = "' + vizProp + '"');
}


function cacheImages() {

 if (document.images) {
  for (var loadProg = 0; loadProg < cacheImages.arguments.length; loadProg++) {
    cI = cacheImages.arguments[loadProg];
    imageCache[loadProg] = new Image();
    imageCache[loadProg].src = homeBase+imgBase+cI;
    //alert("caching: "+imageCache[loadProg].src);
  }
 imageLoadFlag = 1;
 }
}

function setup() {
//alert("setup");
 if (dhtmlBrowser) {
  cacheImages('nav-2.gif', 'nav-3.gif','nav-4.gif','nav-5.gif','nav-6.gif');

  if (!ie4 && docom) {
    for (var i = 0; i < menuCount; i++)
      finishMenu(i);
  }

  if (document.all) this.focus();
  if (ns4) {
    winW = window.innerWidth;
    winH = window.innerHeight;
    window.onresize = reDraw;
  }

 }
}

function reDraw() {
//alert("reDraw");
  if (ns4 && (winW!=window.innerWidth || winH!=window.innerHeight))
    history.go(0);
}

window.onload = setup;
window.offscreenBuffering = true;
