var ns = (document.layers) ? true : false; 
var ie = (document.all) ? true : false;
var mz = (document.getElementById && (window.innerWidth > 0)) ? true : false; //Mozilla/Opera
if(mz) ie = false;

if (mz){
	var myoffset = parseInt((window.innerWidth - 779)/2);
	if (myoffset < 0) myoffset = 0;
	document.getElementsByTagName("body")[0].style.marginLeft = myoffset+"px";
}


var menuArray = new Array();
var breitenArray = new Array();
var initStat = false;
var webRoot = "pic/pic/";


// ** Dropdown Object ***************************************************
function dropdown(name,offX,offY,bgc,hic,txtc,txts,bwidth){

	this.theName = name;
	this.offsetX = offX;
	this.offsetY = offY;
	this.popupCoord = offY;
	this.bgfarbe = bgc;
	this.highfarbe = hic;
	this.txtfarbe = txtc;
	this.txtsize = txts;
	this.leerwidth = bwidth;
	this.dataSize = eval(this.theName+'Data.length');

	this.expand = dropdown_expand;
	this.high = dropdown_high;
	this.unhigh = dropdown_unhigh;
	this.constuct = dropdown_constructor;
	// Other : Get the width of the Reiter, to count the width of the topPullDown Line
	breitenArray[breitenArray.length] = this.offsetY;
	this.constuct();
}


function dropdown_expand(){
  if(initStat){
	menuCollaps()
	this.unhigh();
	if(ns)	{
		switch(this.theName)
		{
			
			case 'gemeinde':		this.popupCoord = (document.images['geme'].x - 1); break;
			case 'verwaltung':		this.popupCoord = (document.images['verw'].x - 1); break;
			case 'bauwohnen':		this.popupCoord = (document.images['bauw'].x - 1); break;
			case 'wirtschaft': 		this.popupCoord = (document.images['wirt'].x - 1); break;

	
		}
		eval('document.layers[\''+this.theName+'Container\'].visibility = \"show\"');
		eval('document.layers[\''+this.theName+'Container\'].left ='+ this.popupCoord);
	}
	if(ie) {
		this.popupCoord = logo.offsetLeft+this.offsetY;
		eval('document.all[\''+this.theName+'Container\'].style.visibility = \"visible\"');
		eval('document.all[\''+this.theName+'Container\'].style.left ='+ this.popupCoord);
	}
	if(mz){
		this.popupCoord = document.getElementById('logo').offsetLeft+this.offsetY;
		document.getElementById(this.theName+'Container').style.left = this.popupCoord;
		document.getElementById(this.theName+'Container').style.visibility = "visible";
	}
  }	
}


// ** Dropdown Highlight Functions **************************************
function dropdown_high(x){
	if (ns) {this.unhigh(); eval('window.document.'+this.theName+'Container.document.layers[\''+this.theName+x+'\'].bgColor = \'#'+this.highfarbe+'\''); return;}
	if (ie) {this.unhigh(); eval(this.theName+x+'.style.backgroundColor = \'#'+this.highfarbe+'\'');}
	if (mz) {this.unhigh(); document.getElementById(this.theName+x).style.backgroundColor = '#'+this.highfarbe;}	
}

function dropdown_unhigh(){
	for(i=0;i<this.dataSize;i++){
		if (ns) eval('window.document.'+this.theName+'Container.document.layers[\''+this.theName+i+'\'].bgColor = \''+this.bgfarbe+'\'');
		if (ie) eval(this.theName+i+'.style.backgroundColor = \''+this.bgfarbe+'\'');
		if (mz) document.getElementById(this.theName+i).style.backgroundColor = this.bgfarbe;
	}
}
// ** End of Dropdown Highlight Functions *******************************



// ** Object Constructor ************************************************
// HTML Code and Styles are generated
// Every Dropdown consists of one Containerlayer that
// holds one cascaded layer for every entry
// **********************************************************************
function dropdown_constructor(){
	// HTML-Layers
	this.codeString = '<div id=\"'+this.theName+'Container\" onMouseOver=\"window.clearTimeout(zu);\">\n';
	this.codeString += '<a href=\"'+eval(this.theName+'Data[0][1]')+'\" onMouseOver=\"'+ this.theName+'.high(0); window.clearTimeout(zu);\"></a>';
	for(i=0;i<this.dataSize;i++){
		this.codeString += '<div id=\"'+this.theName+i+'\" align=\"left\" onMouseOver=\"window.clearTimeout(zu);\">';
		this.codeString += '<img src=\"'+ webRoot + 'empty.gif\" width=\"12\" height=\"20\" border=\"0\">';
		this.codeString += '<a href=\"'+eval(this.theName+'Data['+i+'][1]')+'\" onMouseOver=\"'+ this.theName+'.high('+i+'); window.clearTimeout(zu);\" class="dropdowntext'+this.theName+'">';
		this.codeString += eval(this.theName+'Data['+i+'][0]');
		this.codeString += '<br><img src=\"'+ webRoot + 'grau.gif\" width=\"148\" height=\"1\" border=\"0\"></a></div>\n';
	}
	this.codeString += '<img src=\"'+ webRoot + 'layer_bg.gif" width=\"148\" height=\"5\"><br>\n';
	this.codeString += '<img src=\"'+ webRoot + 'dunkelblau.gif\" width=\"150\" height=\"1\"></div>\n\n';
	// HTML-Styles
	this.styleString = '<style type=\"text/css\">\n';
	this.styleString += '#'+this.theName+'Container{position: absolute; top:'+this.offsetX+'px; left:'+this.offsetY+'px; width:150px; visibility:hidden; z-index:2;';
	this.styleString += (ns)? ' layer-background-image:url(\"pic/pic/layer_bg.gif\");}\n':' background:url(\"pic/pic/dunkelblau.gif\");}\n';
	
	
	for(i=0;i<this.dataSize;i++){
		if(ns) this.styleString += '#'+this.theName+i+'{position: relative; left:1px; font-size: '+this.txtsize+'px; layer-background-color:#'+this.bgfarbe+'; z-index:1;}\n'
		if(ie) this.styleString += '#'+this.theName+i+'{position: top; width:148px; font-size: '+this.txtsize+'px; background-color:#'+this.bgfarbe+'; z-index:1;}\n'
		if(mz) this.styleString += '#'+this.theName+i+'{position: relative; width:148px; left:1px; font-size: '+this.txtsize+'px; backgroundColor:#'+this.bgfarbe+'; z-index:1;}\n'
	}
	this.styleString += '.dropdowntext'+this.theName+':link{font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;  text-decoration: none; color:'+this.txtfarbe+'}\n';
	this.styleString += '.dropdowntext'+this.theName+':visited{font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;  text-decoration: none; color:'+this.txtfarbe+'}\n';
	this.styleString += '.dropdowntext'+this.theName+':active{font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;  text-decoration: none; color:'+this.txtfarbe+'}\n';
	this.styleString += '</style>\n';

	// Other
	menuArray[menuArray.length] = this.theName;
	
	document.writeln(this.styleString);
	document.writeln(this.codeString);
	
	if(ns){
		eval('window.document.layers[\''+this.theName+'Container\'].captureEvents(Event.MOUSEOUT|Event.MOUSEMOVE)');
		eval('window.document.layers[\''+this.theName+'Container\'].onMouseOut = dropdown_mouseLeave');
	}
	if(ie) eval('document.all[\''+this.theName+'Container\'].onmouseout = dropdown_mouseLeave;');
	if(mz) document.getElementById(this.theName+'Container').onmouseout = dropdown_mouseLeave;

	
}
// ** End of Object Constructor. *******************************************

var zu;
function dropdown_mouseEnter() {window.clearTimeout(zu)}
function dropdown_mouseLeave() {zu = window.setTimeout('menuCollaps()',50);}

function menuCollaps(){
	for(i=0;i < menuArray.length; i++){
		if(ns){eval('document.layers[\''+menuArray[i]+'Container\'].visibility = "hide"');}
		if(ie){eval('document.all[\''+menuArray[i]+'Container\'].style.visibility = "hidden"');}
		if(mz){document.getElementById(menuArray[i]+'Container').style.visibility = "hidden";}
		unhighlightHeadMenu()
		window.clearTimeout(zu);
	}
}	
window.onresize = resize;
window.saveInnerWidth  = window.innerWidth; 
window.saveInnerHeight = window.innerHeight;
function resize() {
    if (saveInnerWidth != window.innerWidth || saveInnerHeight != window.innerHeight ) document.location.reload();
}
function newImage(src){
	var tmp = new Image();
	tmp.src = webRoot + src;
	return tmp;
}

geme00 = newImage("../bt/bt_nav_01.gif");	geme01 = newImage("../bt/bt_nav_10.gif");	geme10 = newImage("../bt/bt_nav_10.gif");
verw00 = newImage("../bt/bt_nav_02.gif");	verw01 = newImage("../bt/bt_nav_20.gif");	verw10 = newImage("../bt/bt_nav_20.gif");
bauw00 = newImage("../bt/bt_nav_03.gif");	bauw01 = newImage("../bt/bt_nav_30.gif");	bauw10 = newImage("../bt/bt_nav_30.gif");
wirt00 = newImage("../bt/bt_nav_04.gif");	wirt01 = newImage("../bt/bt_nav_40.gif");	wirt10 = newImage("../bt/bt_nav_40.gif");


var pageHighlight = '';
var aktHighlight = '';

function init(){
	if(document.wirt.src.substr(document.wirt.src.length-6,2) == '10') pageHighlight = 'wirt';
	else if(document.geme.src.substr(document.geme.src.length-6,2) == '10') pageHighlight = 'geme';
	else if(document.verw.src.substr(document.verw.src.length-6,2) == '10') pageHighlight = 'verw';
	else if(document.bauw.src.substr(document.bauw.src.length-6,2) == '10') pageHighlight = 'bauw';

	initStat = true;
}

function highlightHeadMenu(which){
  if(initStat){
	unhighlightHeadMenu();
	eval('document.'+which+'.src = '+which+'01.src');
  }	
}

function unhighlightHeadMenu(){
	if(initStat){
		document.geme.src = (pageHighlight != 'geme')? geme00.src : geme10.src;
		document.wirt.src = (pageHighlight != 'wirt')? wirt00.src : wirt10.src;
		document.verw.src = (pageHighlight != 'verw')? verw00.src : verw10.src;
		document.bauw.src = (pageHighlight != 'bauw')? bauw00.src : bauw10.src;


	}
}

var gemeinde	 	= new dropdown('gemeinde',95,220,'FFFFFF','E5F2F9','#20448F',12,88);
var verwaltung	 	= new dropdown('verwaltung',95,381,'FFFFFF','E5F2F9','#20448F',12,88);
var bauwohnen		= new dropdown('bauwohnen',95,512,'FFFFFF','E5F2F9','#20448F',12,88);
var wirtschaft     	= new dropdown('wirtschaft',95,578,'FFFFFF','E5F2F9','#20448F',12,87);


