$(document).ready(function()
{
	$("#sections ul.level1").each(function()
	{
		if($(this).attr('rel') == 'empty')
		{
			var next = $(this).next('ul.level2');
			var parent = $(this);
			var link = parent.children().children();
			
      if (link.attr('rel') != "show_products") //vynimka pre kategorie bez podkategorii
        link.attr('href',link.attr('href')+"#0");
			
      if (link.attr('rel') != "show_products") //vynimka pre kategorie bez podkategorii
        link.bind('click',function() {
  				next.reactivate();
  				parent.children().children().addClass('curr_a');
  				parent.children().addClass('active');
  				parent.children().attr('id','actived');
  				return false;
  			});
		}
	}
	);
}
);

$.fn.reactivate = function()
{

 // $("#sections ul.level2.curr_sub").attr('class','level2');
  
  $("#sections ul.level2.curr_sub").slideUp('slow',
	function()
	{
		$(this).removeClass('curr_sub');
		element.slideDown('slow',
		function()
		{
			element.addClass('level2');
		});
	});
  
	var element = $(this);
	var old_element = $("#sections ul.display");
	$("#sections li.active").each(function()
	{
	  $(this).children().removeClass('curr_a');
		$(this).removeClass('active');
		$(this).attr('id','');
	});
	if(old_element.html() == null)
	{
		element.slideDown('slow',
		function()
		{
			element.addClass('display');
		});
	}else
	{
	old_element.slideUp('slow',
	function()
	{
		$(this).removeClass('display');
		element.slideDown('slow',
		function()
		{
			element.addClass('display');
		});
	});
	}
}
