/*
* Dickerfisch-Script von pfirsichmelba.de // Alexander Farkas <a.farkas@pfirsichmelba.de>
*
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
* 
* Bei guten Verbesserungen/öffentlichem Einsatz wäre ich für eine kurze Mail mit Link dankbar.
*/

//Verzögerung in ms
var df_navtimer = "500"; 
/*
 * Um das "Klettern im DOM" zu erleichtern, wird ein Attribut für alle Links, einer Unterkategorie vergeben. Wer es valide haben möchte, sollte class (oder ein anders erlaubtes Attribute (ausser id)) eintragen..
 */
var df_focusIsChildOF = "childof";
//Konfig Ende
//globale variabeln
var df_NavTimeID, globActiveNavLi = "", globWaitingNavLi = "";
//hover mit Verzögerung Funktionen
function showNavli(NavLiID) {
	var NavLiObj = $(NavLiID);
	if(globActiveNavLi == "" || globActiveNavLi == NavLiID) {
		Element.addClassName(NavLiObj,"over");
		globActiveNavLi = NavLiID;	
		globWaitingNavLi = NavLiID;
		window.clearTimeout(df_NavTimeID);
	} else
		globWaitingNavLi = NavLiID;
};
function hideNavli(NavLiID) {
	var NavLiObj = $(NavLiID);
	if(globActiveNavLi == NavLiID && globWaitingNavLi != NavLiID) {
		Element.removeClassName(NavLiObj,"over");
		globActiveNavLi = "";
	} 
	if(globWaitingNavLi != ""){
		globActiveNavLi = "";
		showNavli(globWaitingNavLi);
	} 
};
//hover mit Verzögerung ende
function addinfoNAV() {
	var allnav = $('nav'),alllis = $A(allnav.getElementsByTagName('li')),childul,focuslinks;
	alllis.each(function(li,i){
		childul = li.getElementsByTagName('ul')[0];
		if(childul){
			li.setAttribute("id","n"+i);
			li.onmouseover=function() {				
				showNavli(this.getAttribute("id"));
  			};
			li.onmouseout=function() {
				globWaitingNavLi = "";
				if(this.getAttribute("id") == globActiveNavLi)
					df_NavTimeID = window.setTimeout("hideNavli('"+this.getAttribute("id")+"')",df_navtimer);					
  			};
			focuslinks = $A(childul.getElementsByTagName('a'));
			focuslinks.each(function(focuslink){
				focuslink.setAttribute(df_focusIsChildOF,'n'+i);
				focuslink.onfocus=function(){
					Element.addClassName($(this.getAttribute(df_focusIsChildOF)),'over');
				};
				focuslink.onblur=function(){
					Element.removeClassName($(this.getAttribute(df_focusIsChildOF)),'over');
				};
			});
		}
	});
	Element.addClassName(allnav.getElementsByTagName('ul')[0],'navfxenabled');
};

//Starter
function navstart() {
	if(document.getElementById && document.createTextNode)
	{  
		addinfoNAV();
	}
};
