var hoverColor = "#c0c0c0";

// Extend Behaviour 
Behaviour.addUnLoadEvent = function(func){
	var oldonunload = window.onunload;
		
	if (typeof window.onunload != 'function') {
		window.onunload = func;
	} else {
		window.onunload = function() {
			oldonunload();
			func();
		}
	}
};

var defaultRules = {
	'a' : function(element){
		element.onfocus = function(){
			this.blur();
		};
	},
	'#main_navi td .menuitem' : function(element){
		element.menuColor = RicoUtil.getElementsComputedStyle( element, "backgroundColor", "background-color");

		element.onmouseover = function(){
			// hover color
			this.menuColor = RicoUtil.getElementsComputedStyle( this, "backgroundColor", "background-color");
			this.style["backgroundColor"] = hoverColor;

/*
if(document.all){
	$("debug").innerHTML += "<pre>";
	$("debug").innerHTML += HTMLentities(this.parentNode.parentNode.parentNode.innerHTML);
	$("debug").innerHTML += "</pre>";
}
*/

			var SPANs = this.lastChild.getElementsByTagName("b"); //this.lastChild.getElementsByTagName("span");
			for(var i=0;i<SPANs.length;i++){
				SPANs[i].style["backgroundColor"] = hoverColor;

			}

			// show tooltip
			var e = document.getElementsByClassName("tooltip", this);
			if(e.length>0){
				// display tooltip
				e[0].style.display="block";
			}

		};

		element.onmouseout = function(){
			// hover color restore
			this.style["backgroundColor"] = this.menuColor;
			var SPANs = this.lastChild.getElementsByTagName("b"); // this.lastChild.getElementsByTagName("span");
			for(var i=0;i<SPANs.length;i++){
				SPANs[i].style["backgroundColor"] = this.menuColor;
			}

			// hide tooltip
			var e = document.getElementsByClassName("tooltip", this);
			if(e.length>0){
				// display tooltip
				e[0].style.display="none";
			}
		};
	}
}
Behaviour.register(defaultRules);
Behaviour.addLoadEvent(function(){

	// display logout button if user is logged in
	if(Cookies.getCookieValue("loggedin"))$("logout_button").style["display"]="";
/*
if(document.all){
	$("debug").innerHTML += "<pre>";
	$("debug").innerHTML += HTMLentities(s);
	$("debug").innerHTML += "</pre>";
} else console.log("debug: %s" ,s );
*/
});

function HTMLentities(t){
	 return t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<br>\n");
}