//$(function() // Register the menu
//      {
// Add the click event handler on the list item with sub list
//$('li:has(ul)') 
//           .click(function(event){
//            if (this == event.target) {
//               // Hide all the children of the other lists
//               $('li:has(ul)').children().hide('slow'); 
//               // Make the animation
//               $(this).children().animate({opacity:'toggle',height:'toggle'},'slow'); 
//                                      }
//                     return false;
//                                 }
 //                  )
  //          // Change the cusrsor.
//           .css({cursor:'pointer'})
//           // Hide all the nested lists (on the first tinm only).
//           .children().hide();
//       }
// );
 // basic show and hide
$(document).ready(function(){
	
 	$('ul.menulist ul').hide();
//        alert(podstrona);
        //alert("!");
	//$('ul.menulist ul ul').show();	
	//$('ul.menulist li:has(ul) a[href*=podstrona]').show();
	//$('ul.menulist li ul').show();
        $('ul.menulist ul:has(ul:has(a[href$=\=' + podstrona +']))').show();
	$('ul.menulist ul ul:has(a[href$=\=' + podstrona +'])').show();	
	$('ul.menulist ul:has(a[href$=\=' + podstrona +'])').show();

//	$('ul.menulist li:has(ul) a').prepend($("<span>\+ </span>"));

//	$('ul.menulist li:has(ul) a').append($("<img src=\"img/plus.gif\" width=\"12\" height=\"12\" style=\"float: right;\" />"));
//	$('ul.menulist li:has(ul) a[href="#"]').append($("<span style=\"float: right;\">\+ </span>"));
	$('ul.menulist li:has(ul) a[href="#"]').append($("<span>&nbsp;&nbsp;&nbsp;\>\></span>"));
/*	$('ul.menulist li:has(ul) a').attr('style', function(){
		var currentPaddingLeft = $(this).css("padding-left");
		currentPaddingLeft = currentPaddingLeft.match("[0-9]{1,}");
//alert("padding-left:" + (parseInt(currentPaddingLeft+1) +"px");
		return "padding-left:" + (parseInt(currentPaddingLeft)-10) +"px";
	});
	$('ul.menulist li:has(ul) a').prepend($("<span>\+ </span>"));	*/
//  $('ul.menulist li:has(ul) a').addClass("menuzwiniete");
	
	$('ul.menulist li a').click(
		function() {
			var par = this.parentNode.parentNode.id;
//                        alert(par);
			var tmp = $(this).next();
		
			if((tmp.is('ul')) && (tmp.is(':visible'))) {
//				if($('#' + par).hasClass('collapsible')) {
					$('#' + par + ' ul:visible').slideUp(500);
//				}
				return false;
			}
			if((tmp.is('ul')) && ( !tmp.is(':visible'))) {
				$('#'+ par +' ul:visible').slideUp(500);
				tmp.slideDown(500);
/*				$(this).children("span").remove();
				$(this).append($("<span style=\"float: right;\">\- </span>"));*/
				return false;
			}
		}
	);
/*	function() {
		$('div.menu > ul > li').children('ul').hide();  
		$('div.menu > ul > li').click(function() {
			var $visibleMenus = $('div.menu > ul > li').children('ul:visible');
			$visibleMenus.addClass('menuhover');
			$(this).children('ul').slideToggle();
			
//			$('div.menu > ul > li > dl').slideToggle('fast')
		});
	
		$("div.menu >ul >li").hover(
			function(){
//				$(this).append($("<span style=\"background:orange\"> ***</span>"));
				$(this).addClass("menuhover");
			},
			function () {
				$(this).removeClass("menuhover");
			}			
		);
 
*/
});
