var sitemap = function(){

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

	if($(rollelm).children(cnt).css("display") == "none")
		{
			$(rollelm).children(cnt).slideDown("slow");
			$(rollelm).children("ul.tabs").slideDown("slow");
			$(rollelm).removeClass("dropdown");
			$(rollelm).addClass("dropup");
		}
		else
		{
			$(rollelm).find(cnt).slideUp("slow");	
			$(rollelm).find(cnt).parent("li").addClass("dropdown");	
			$(rollelm).find(cnt).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(cnt).hide();
				//$(this).children("ul.tabs").hide();
				//$(this).next("li.sub").hide();
			}
				//}
		});
//		self.ready();
	}
	var init = function(){
		prepare();
		var dropenable = $(cnt+" li.dropdown");
		$(dropenable).children(cnt).hide();
		$(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(cnt).slideUp("slow");	
			$(dropenable).find(cnt).parent("li").addClass("dropdown");	
			$(dropenable).find(cnt).parent("li").removeClass("dropup");
			$("a#rozwin").show();
			$("a#zwin").hide();
			event.preventDefault();
		});
			$("a#rozwin").click(function(event){
			$(dropenable).find(cnt).slideDown("slow");	
			$(dropenable).find(cnt).parent("li").removeClass("dropdown");	
			$(dropenable).find(cnt).parent("li").addClass("dropup");	
			$("a#rozwin").hide();
			$("a#zwin").show();
			event.preventDefault();
		});
		$("a#zwin").hide();
	}
	init();
	
}
$(document).ready(function() {sitemap();})
