$(document).ready(function() {
	var menu = $(".menu");
	
	menu.children("li").each(function() {
		$(this).hover(function() {
			$(this).addClass("hasactive");
			if($(this).children("ul").length > 0) {
				$(this).css("zIndex", 100);
				ul = $(this).children("ul");
				ul.show();
				// fade page out 
			}
		}, function() {
			$(this).removeClass("hasactive");
			if($(this).children("ul").length > 0) {
				$(this).children("ul").hide();
				// fade page in
			}
		})
		
		if($(this).children("ul").length > 0) {
			me = $(this).children("ul");
			$(me).show();
			me.css("width", (me.children("li").length * me.children("li").eq(0).outerWidth()) + "px" );
			hh = 0;
			me.children("li").each(function() {
				h = parseInt($(this).children("ul").outerHeight());
				hh = h > hh ? h : hh;
			});
			hh = hh + 30;
			me.children("li").each(function() {
				$(this).css("height", hh + "px" );
			});
			$(me).hide();
		}
		
	});
	$(".showhide").click(function() {
		$(this).parent().parent().children().each(function() {
			$(this).removeClass("active");
			rrr = $(this).children().eq(0).attr("rel");
			if(rrr) {
				$("#" + rrr).hide();
			}
		});
		$(this).parent().addClass("active");
		r = $(this).attr("rel");
		$("#" + r).show();
		return false;
	});
	
	function slideToggle(el, bShow){
		
	  var $el = $(el), height = $el.data("originalHeight"), visible = $el.is(":visible");
	  
	  // if the bShow isn't present, get the current visibility and reverse it
	  if( arguments.length == 1 ) bShow = !visible;
	  
	  // if the current visiblilty is the same as the requested state, cancel
	  if( bShow == visible ) return false;
	  
	  // get the original height
	  if( !height ){
	    // get original height
	    height = $el.show().height();
	    // update the height
	    $el.data("originalHeight", height);
	    // if the element was hidden, hide it again
	    if( !visible ) $el.hide().css({height: 0});
	  }
	
	  // expand the knowledge (instead of slideDown/Up, use custom animation which applies fix)
	  if( bShow ){
	    $el.show().animate({height: height}, {duration: 500});
	  } else {
	    $el.animate({height: 0}, {duration: 500, complete:function (){
	        $el.hide();
	      }
	    });
	  }
	}
});
