/**
 * Třída pro práci s menu
 * @param string jQuery selector
 */
function Menu(rootSelector) {
	
	this.rootSelector = rootSelector;
	this.root = $(this.rootSelector+" ul");
	this.submenus = this.root.length;
	this.timer = null;
	this.opening = false;
	this.type = "h"; // h nebo v
	this.menuId = null;

}

Menu.prototype.execute = function() {

	var _this = this;
	this.root.each(function(index,el) {
		
		var li = $(el).parent().get(0);
		var ul = $(li).parent().get(0);
		var level = $(el).attr("class").match(/level_([0-9]+)/)[1];
		var width = $(ul).width();
		if(level == 2) {
			width -= 8;
		}
		if(level > 1) {
			$(el).css("marginLeft",width+"px");
		}
		
		$(li).mouseover(function(event) {
			_this.show(this,event,level);
		}).mouseleave(function(event) {
			_this.hide(this,event,level);
		});
	});
}
	
Menu.prototype.show = function(parent,event,level) {
	$(parent).css("z-index",10001);
	if(!this.opening) {
		this.opening = true;
		var _this = this;
		if(level > 10) {
			$("> ul",parent).animate( { right : "+=5", opacity: 1 }, 200, "linear", function(){
				_this.opening = false;
			});
		}
		else {
			var ul = $("> ul",parent);
			var height = $(ul).height();
			if($.browser.msie && parseInt($.browser.version) == 8) {
				
			}
			//document.title = "height = "+height;
			if(level >= 2) {
				ul.css( { "margin-left" : ($(parent).width() - 5)+"px", "margin-top" : "-"+$(parent).height()+"px" } );
			}
			ul.slideDown(200,function(){
				_this.opening = false;
			});
		}
	}
}

Menu.prototype.hide = function(parent,event,level) {
	$("ul",parent).fadeOut(30);
}

Menu.prototype.hideAll = function() {
	$(this.root).hide();
}

