// JavaScript Document

var menus		= new Array('m1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8');
var shortcuts	= new Array('e',  'p',  'u',  's',  'd',  'r',  'c',  'o');
var submenus	= new Array('s1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9');
var shortcuts2	= new Array('l',  'i',  'h',  'r',  'b',  'c',  't',  'p', 's');
var openmenu	= null;
var linkid		= 0;
var keyselecter = false;

// Hide all menus, the hider-div
// and add the class "js" to the dd Tags
function initmenu() {
	menus.each(function(element){try {$(element).hide();}catch(e){}});
	$('hider').hide();
	var dds = document.getElementsByTagName('dd'); 
	for (var i = 0; i < dds.length; i++) { 
		dds[i].className = 'js';
	}		 
}

function hideAllSelect() {
/*	Funktioniert im IE irgendwie nicht
	var bodytag = document.getElementsByTagName("body").item(0);
	var selects = bodytag.getElementsByTagName("select");		
	for (i = 0; i < selects.length; i++) {
		try {
			selects[i].hide();
		} catch (e) {
		}
	}
*/
}

function showAllSelect() {
/*	Funktioniert im IE irgendwie nicht
	var bodytag = document.getElementsByTagName("body").item(0);
	var selects = bodytag.getElementsByTagName("select");		
	for (i = 0; i < selects.length; i++) {
		try {
			selects[i].show();
		} catch (e) {
		}
	}
*/
}


function hideShortcuts(id) {
/*
	if (id == 'm') {
		shortcut.remove("Ctrl+Shift");
		shortcuts.each(function(element) {
			if(BrowserDetect.browser == "Firefox") {
				$('m'+((shortcuts.indexOf(element)+1))+'i').innerHTML = $('m'+((shortcuts.indexOf(element)+1))+'i').innerHTML.replace(new RegExp('\<u.*\>(.*)\<.*\>',""), '$1');
			} else if(BrowserDetect.browser == "Explorer") {
				$('m'+((shortcuts.indexOf(element)+1))+'i').innerHTML = $('m'+((shortcuts.indexOf(element)+1))+'i').innerHTML.replace(new RegExp('\<.*"\>', "i"), '');
				$('m'+((shortcuts.indexOf(element)+1))+'i').innerHTML = $('m'+((shortcuts.indexOf(element)+1))+'i').innerHTML.replace(new RegExp('(\<\/.*\>)',""), '');
			}				
		});
		shortcut.add("Ctrl+Shift",  function() { showShortcuts('m'); });
	} else if (id == 's') {
		shortcut.remove("Shift+Alt");
		shortcuts2.each(function(element) {
			if(BrowserDetect.browser == "Firefox") {
				$('s'+((shortcuts2.indexOf(element)+1))+'i').innerHTML = $('s'+((shortcuts2.indexOf(element)+1))+'i').innerHTML.replace(new RegExp('\<u.*\>(.*)\<.*\>',""), '$1');
			} else if(BrowserDetect.browser == "Explorer") {
				$('s'+((shortcuts2.indexOf(element)+1))+'i').innerHTML = $('s'+((shortcuts2.indexOf(element)+1))+'i').innerHTML.replace(new RegExp('\<.*"\>', "i"), '');
				$('s'+((shortcuts2.indexOf(element)+1))+'i').innerHTML = $('s'+((shortcuts2.indexOf(element)+1))+'i').innerHTML.replace(new RegExp('(\<\/.*\>)',""), '');
			}
		});
		shortcut.add("Shift+Alt",  function() { showShortcuts('s'); });
	}
*/
}
function showShortcuts(id) {
/*
	if(BrowserDetect.browser == "Firefox" || BrowserDetect.browser == "Explorer") {
		if (id == 'm') {
			shortcut.remove("Ctrl+Shift");
			shortcuts.each(function(element) {
				$('m'+((shortcuts.indexOf(element)+1))+'i').innerHTML = $('m'+((shortcuts.indexOf(element)+1))+'i').innerHTML.replace(new RegExp("("+element+")","i"), '<u style="text-decoration:underline;">$1</u>');
			});
			shortcut.add("Ctrl+Shift", function() { hideShortcuts('m'); });
		} else if (id == 's') {
			shortcut.remove("Shift+Alt");
			shortcuts2.each(function(element) {
				$('s'+((shortcuts2.indexOf(element)+1))+'i').innerHTML = $('s'+((shortcuts2.indexOf(element)+1))+'i').innerHTML.replace(new RegExp("("+element+")","i"), '<u style="text-decoration:underline;">$1</u>');
			});
			shortcut.add("Shift+Alt", function() { hideShortcuts('s'); });
		}
	}
*/
}

// Fade and appear the menus
// and show or hide the hider-div
/*
function menu(id) {
	menus.each(function(element) {
		if ($(element).visible() && 'm'+id != element) new Effect.Fade(element, { duration: 0.3 });
		if (!$(element).visible() && 'm'+id == element) {
			new Effect.Appear(element, { duration: 0.5 });
			$('hider').show();
			hideAllSelect();
			openmenu = id;
			if(keyselecter) {
				$('m'+id+'i').focus();					
				keyselecter = false;
			}
		}
	});
	if(id == '' && $('hider').visible()) {
		openmenu = null;
		$('hider').focus();
		$('hider').hide();
		showAllSelect();
	}
}
*/

function menu(id){
menus.each(function(element){
try{if($(element).visible()&&'m'+id!=element)new Effect.Fade(element,{duration:0.3});}catch(e){}
try{
if(!$(element).visible()&&'m'+id==element){
new Effect.Appear(element,{duration:0.5});
$('hider').show();
$('hider2').show();
hideAllSelect();
openmenu=id;
if(keyselecter){
$('m'+id+'i').focus();
keyselecter=false;
}
}
}catch(e){}
});
if(id==''&&$('hider').visible()){
openmenu=null;
$('hider').focus();
$('hider').hide();
$('hider2').hide();
showAllSelect();
}
}


function menushift(direction) {
	keyselecter = true;
	if (openmenu != null) {
		if ((openmenu > 0  && parseInt(direction) < 0) || (openmenu < (menus.length) && parseInt(direction) > 0)) {
			menu(''+(parseInt(openmenu)+parseInt(direction)));
			linkid = 0;
		}
	}
}

function selectMenu(id, direction) {
	if (openmenu != null) {

		var menudl = $('m'+id);
		var menudds = menudl.getElementsByTagName("dd");		
		var maxmenu = menudds.length;
	
		if ((linkid > 1  && parseInt(direction) < 0) || (linkid < maxmenu && parseInt(direction) > 0)) {
			linkid += direction;
			$('l'+id+linkid).focus();
		}
	}
}

/*
shortcuts.each(function(element) {
	shortcut.add("Ctrl+Shift+" + element, function() { keyselecter = true; menu((shortcuts.indexOf(element)+1)); });
});

shortcuts2.each(function(element) {
	shortcut.add("Shift+Alt+" + element.toUpperCase(), function() { 
		$('s'+(shortcuts2.indexOf(element)+1)+'i').focus();					
	});
});


shortcut.add("Left",  function() { menushift(-1); });
shortcut.add("Right", function() { menushift(1); });
shortcut.add("Esc",   function() { menu(''); });

shortcut.add("Up",    function() { selectMenu(openmenu, -1); });
shortcut.add("Down",  function() { selectMenu(openmenu, 1); });

// Kein @ mehr möglich!
shortcut.add("Ctrl+Shift",  function() { showShortcuts('m'); }, {'propagate': true});
shortcut.add("Shift+Alt",  function() { showShortcuts('s'); });
*/
