/* 
   Metody jQuery na potrzeby menu dynamicznego
*/
$(document).ready(
	function()
	{
		$("#dynamicNavigation > ul > li.active").next("li").children(".lvl1_background").hide();
		$("#dynamicNavigation > ul > li").not(".active").hover(
			function() {
				$(this).addClass("item_active")
				$(this).next("li").children(".lvl1_background").hide()
				$(this).children(".lvl1_background").hide()
				if ($(this).children("div.level1").children("ul").size() != 0) {
					$(this).children("div.level1").show()
					if ($(this).children("div.level1").width() < $(this).width()) {
						var ulWidth = $(this).width() - 36
						$(this).children("div.level1").children("ul").children('li').children('a').css('width',ulWidth+'px')
					} else {
						var ulWidth = $(this).children("div.level1").width() - 30
						$(this).children("div.level1").children("ul").children('li').children('a').css('width',ulWidth+'px')
					}
				}
			},
			function() {
				$(this).removeClass("item_active")
				$(this).next("li").children(".lvl1_background").show()
				$(this).children(".lvl1_background").show()
				$("#dynamicNavigation > ul > li.active").next("li").children(".lvl1_background").hide();
				$(this).children("div.level1").hide()
			}
		).css('cursor', 'pointer');
		$("#dynamicNavigation > ul > li.active").hover(
			function() {
				if ($(this).children("div.level1").children("ul").size() != 0) {
					$(this).children("div.level1").show()
					if ($(this).children("div.level1").width() < $(this).width()) {
						var ulWidth = $(this).width() - 36
						$(this).children("div.level1").children("ul").children('li').children('a').css('width',ulWidth+'px')
					} else {
						var ulWidth = $(this).children("div.level1").width() - 30
						$(this).children("div.level1").children("ul").children('li').children('a').css('width',ulWidth+'px')
					}
				}
			},
			function() {
				$(this).children("div.level1").hide()
			}
		).css('cursor', 'pointer');
	}
);
