var sitemap = function(){

	var self = this;
	var cnt = "ul.menu";
	var level = 1;
	level --;
	var roll = function(rollelm){

	if($(rollelm).children("ul.menu").css("display") == "none")
		{
			$(rollelm).children("ul.menu").slideDown("slow");
			$(rollelm).children("ul.tabs").slideDown("slow");
			$(rollelm).removeClass("dropdown");
			$(rollelm).addClass("dropup");
		}
		else
		{
			$(rollelm).find("ul.menu").slideUp("slow");	
			$(rollelm).find("ul.menu").parent("li").addClass("dropdown");	
			$(rollelm).find("ul.menu").parent("li").removeClass("dropup");	
		}
		
	}
	this.prepare = function(){
		$(cnt).children("li").each(function(){

			var patt1 = /\d/;
			var lvl = $(this).attr("class").match(patt1);
			if(lvl>level && ($(this).children(cnt).size()>0 || $(this).children("ul.tabs").size()>0 )){
				if(($(this).children("p").children("a").attr("href").indexOf("/dla_firmy/male") ==-1 && $(this).children("p").children("a").attr("href").indexOf("/dla_firmy/klienci_korpo") ==-1) || lvl!=1){

				$(this).addClass("dropdown");
				$(this).children("ul.menu").hide();
				$(this).children("ul.tabs").hide();
				$(this).next("li.sub").hide();}
			}
		});
//		self.ready();
	}
	var init = function(){
		prepare();
		var dropenable = $(cnt+" li.dropdown");
		$(dropenable).children("p").children("a").click(function(e) {e.stopPropagation();});
		$(dropenable).click(function(evt){roll(this);evt.stopPropagation();});
		$(dropenable).hover(function () {$(this).addClass("hover");}, function () {$(this).removeClass("hover");});
		$("a#zwin").click(function(event){	
			$(dropenable).find("ul.menu").slideUp("slow");	
			$(dropenable).find("ul.menu").parent("li").addClass("dropdown");	
			$(dropenable).find("ul.menu").parent("li").removeClass("dropup");
			$("a#rozwin").show();
			$("a#zwin").hide();
			event.preventDefault();
		});
			$("a#rozwin").click(function(event){
			$(dropenable).find("ul.menu").slideDown("slow");	
			$(dropenable).find("ul.menu").parent("li").removeClass("dropdown");	
			$(dropenable).find("ul.menu").parent("li").addClass("dropup");	
			$("a#rozwin").hide();
			$("a#zwin").show();
			event.preventDefault();
		});
		$("a#zwin").hide();
	}
	init();
	
}
$(document).ready(function() {sitemap();});