$(document).ready(function () {
	//$('#cbyMenu a[href="#"]').unbind('click').bind('click',function(event) {js_menuClick(this);event.preventDefault();});
	$('#cbyMenu a[href="#"]').parent().bind('mouseenter',function(event) {
		$('#cbyMenu').find('ul ul').slideUp(100);
		$(this).find('ul').eq(0).slideDown(100);
		event.preventDefault();
	});
	$('#cbyMenu').bind('mouseleave',function(event) {
		$(this).find('ul ul').slideUp(100);
		event.preventDefault();
	});
	$("#cbyContent .cbyOpenCloseDiv").each(function(i,obj) {
		$(obj).children('div').eq(1).hide();
		$(obj).children('div').eq(0).css('cursor','pointer').unbind('click').bind('click',function(){$(this.parentNode).toggleClass('close').find('div').eq(1).slideToggle()});
	});
});

function js_menuClick(obj){
	var node=$(obj).parents('div.cbyWebmenus')[0];		//Select the parent cbyWebmenus
	
	if (node && node.getAttribute("auto_open_child")=="yes" && obj.getAttribute("href")=="#") {		// Auto open next child if enabled
		var childs=$(obj.parentNode).find("a[href!='#']");
		if (childs.length) {document.location=childs.eq(0).attr("href");return false;}
	}
	if (node && node.getAttribute("modal")=="yes") {				//If modal mode, close all other menus -> TODO=TOCHECK
		if ($(obj).hasClass("selected")) {
			$(node).find("a").removeClass("selected");
			$(node).find("ul ul:visible").slideToggle("fast");
		} else {
			$(node).find("a").removeClass("selected");
			$(node).find("ul ul:visible").slideToggle("fast");
			$(obj.parentNode).children("ul").slideToggle("fast");
			$(obj).toggleClass("selected");
		}
	} else {
		$(obj.parentNode).children("ul").slideToggle("fast");
	}
	return false;
}
function js_getNodeInfo(node) {
	var info="";
	info+="nodeName: "+node.nodeName+"\n";
	
	pathNode=node;
	pathText="";
	while (pathNode) {
		pathText=pathNode.nodeName+" > "+pathText;
		pathNode=pathNode.parentNode;
	}
	info+="nodePath: "+pathText+"\n";
	
	info+="nodeAttributes:\n";
	for (i=0;i<node.attributes.length;i++)
		info+="  '"+node.attributes[i].name+"' = '"+node.attributes[i].value+"'\n";
	return info;
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

