/***
  jQuery Menu
***/

jQuery(document).ready(function(){

	setSubMenuPosition("#menu ul li", 0);

	jQuery(".current_page_ancestor, .current_page_item").children("a")
									.css("background", "#DBEBD1")
									.css("color", "#999999");

	jQuery("#menu ul li").each(function(){
		this.normalbg =  jQuery(this).children("a").css("background-color");
		this.normalcolor = jQuery(this).children("a").css("color");
	})
	.mouseover(function(e){
		
		jQuery(this)
			.children("ul")
			.stop()
			.dequeue()
			.css("display", "block")
			.animate({opacity:1}, {duration:200, easing:"easeOutExpo"});
		 
		 jQuery(this).children("a").animate({backgroundColor:"#DBEBD1", color:"#333"}, {queue:false,easing:"easeOutExpo",duration:300});
		 
	})
	.mouseout(function(e){
		jQuery(this).children("ul")
			.stop()
			.dequeue()
			.animate({opacity:0}, {duration:200, easing:"easeOutExpo", complete:function(){ jQuery(this).css("display", "none"); }});

			jQuery(this).children("a").animate({backgroundColor:this.normalbg, color:this.normalcolor}, {queue:false,easing:"easeOutExpo",duration:300});
	});
});


/***
  Iterative function that creates all menu level 
***/

function setSubMenuPosition(element, level)
{
	jQuery(element).children("ul")
							.css("width", 281)
							.css("opacity", 0)
							.css("position", "absolute")
							.css("display", "none")
							.css("top", ((level == 0) ? 24 : 12))
							.css("left", 130*((level == 0) ? 0 : 1))
							.css("z-index", 5*level)
							.each(function(){
								setSubMenuPosition(jQuery("li", this), level+1)
							});
}

/***
 Some tools
***/

function RGB2HTML(str)
{
    if(str.substring(0,3).toLowerCase() == "rgb")
    {
    	var c = str.substring(4, str.length-1).replace(/ /g, "").split(",");
    	var decColor = parseInt(c[0]) + 256 * parseInt(c[1]) + 65536 * parseInt(c[2]);
    	return "#"+decColor.toString(16);
    }
    else
    {
	return str;
    }
}

