//farbdefinitionen
menuColorNormal = "#333333";
menuColorRollOver = "#82a0e1";

function MTUMenu(selector) {
	var btns = $$("#mainmenu a[id]");
	
	this.buttons = new Array();
	this.menus = new Array();
	this.urls = new Array();
	
	for (i = 0; i<btns.length; i++) {
		var btnId = btns[i];
		var btn = $(btnId);
		var btnNum = btn.id.split("mtuMenu")[1];
		var menu = $("mtuMenuPulldown"+btnNum);
		
		var btnInfo = btnNum + "|" + Utf8.encode(btn.innerHTML);
		//check if current button is active button
		if (btn.className == "active") btnInfo += "|active";
		
		this.buttons.push(btnInfo);
		
		this.menus.push(menu);
		
		this.urls[Number(btnNum)] = btn.href;
		
		if (menu != null) {
		
			//elemte zuweißen
			btn["menu"] = menu.menu = menu;
			menu["btn"] = btn.btn = btn;
			menu["btnNum"] = btnNum;
			//funktionen zuweisen
			menu.onmouseover = btn.onmouseover = showPopup;
			menu.onmouseout = btn.onmouseout = hidePopup;
			
			//horizontal positionieren
			var newx = btn.offsetLeft - 11;
			var menuwidth = menu.offsetWidth;
			if (newx + menuwidth > 811) newx = 811 - menuwidth;
			menu.style.left = newx + "px";
		
		}
	}
	
	this.getButtonsForFlash = getButtonsForFlash;
	this.setNewMenuPositionsFlash = setNewMenuPositionsFlash;
	this.clickMenuFromFlash = clickMenuFromFlash;
	
}

function setNewMenuPositionsFlash(pos) {
	var menu;
	var positions = pos.split("|");
	for (i = 0; i<this.menus.length; i++) {
		menu = this.menus[i];
		if (menu != null) {
			var newx = Number(positions[i]) - i - 12;
			var menuwidth = menu.offsetWidth;
			if (newx + menuwidth > 811) newx = 811 - menuwidth;
			menu.style.left = newx + "px";
		}
	}
}

function getButtonsForFlash() {
	var flash = "";
	for (i = 0; i<this.buttons.length; i++) {
		flash += escape(this.buttons[i]);
		if (i<this.buttons.length-1) flash += "$$$";
	}
	return flash;
}

function showMenuFromFlash(id) {
	var menu = $("mtuMenuPulldown"+id);
	clearTimeout(menu["menu_timeout"]);
	menu.style.visibility = "visible";
}

function hideMenuFromFlash(id) {
	var menu = $("mtuMenuPulldown"+id);
	clearTimeout(menu["menu_timeout"]);
	menu["menu_timeout"] = setTimeout("resetMenu('"+menu.id+"')", 100);
}

function clickMenuFromFlash(id) {
	document.location.href = this.urls[Number(id)]; 
}

function showPopup() {
	var menu = this["menu"];
	var btn = this["btn"];
	menu.style.visibility = "visible";
	clearTimeout(menu["menu_timeout"]);
	//buttontext blau einfärben
	btn.style.color = menuColorRollOver;
	//evtl. flash button färben
	var flashMenu = thisMovie("flashmm");
	if (flashMenu != null) {
		flashMenu.hlFlashButton(menu["btnNum"]);
	}
}

function hidePopup() {
	var menu = this["menu"];
	clearTimeout(menu["menu_timeout"]);
	menu["menu_timeout"] = setTimeout("resetMenu('"+menu.id+"')", 100);
}

function resetMenu(menuId) {
	var menu = $(menuId);
	menu.style.visibility = "hidden";
	var btn = menu["btn"];
	btn.style.color = menuColorNormal;
	var flashMenu = thisMovie("flashmm");
	if (flashMenu != null) {
		flashMenu.hlFlashButton();
	}
}

//get flash movie
function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}

/** * * UTF-8 data encode / decode * http://www.webtoolkit.info/ * **/ var Utf8 = { /** public method for url encoding */ encode : function (string) { string = string.replace(/\r\n/g,"\n"); var utftext = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { utftext += String.fromCharCode(c); } else if((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); } } return utftext; }, /**  public method for url decoding */ decode : function (utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0; while ( i < utftext.length ) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i+1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; } }

