/* 
Simple JQuery menu.
HTML structure to use:

Notes: 

1: each menu MUST have an ID set. It doesn't matter what this ID is as long as it's there.
2: each menu MUST have a class 'menu' set. If the menu doesn't have this, the JS won't make it dynamic

Optional extra classnames:

noaccordion : no accordion functionality
collapsible : menu works like an accordion but can be fully collapsed
expandfirst : first menu item expanded at page load

<ul id="menu1" class="menu [optional class] [optional class]">
<li><a href="#">Sub menu heading</a>
<ul>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
...
...
</ul>
<li><a href="#">Sub menu heading</a>
<ul>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
...
...
</ul>
...
...
</ul>

Copyright 2008 by Marco van Hylckama Vlieg

web: http://www.i-marco.nl/weblog/
email: marco@i-marco.nl

Free for non-commercial use
*/

function initMenus() {
	$('ul.block-category-left-menu ul').hide();
	
	$('ul.block-category-left-menu li a.blockcategory-header').click(
		function() {
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;
			
			var first_child = $(this).children(':first-child');
			var second_child = first_child.next();
			
			if($(this).hasClass('expanded'))
			{
				$(this).addClass('collapsed').removeClass('expanded');
				$('#' + parent + ' ul:visible').slideUp('normal');
				
				first_child.removeClass('hide_me_now').addClass('show_me_now');
				second_child.removeClass('show_me_now').addClass('hide_me_now');
			}
			else
			{
				$(this).addClass('expanded').removeClass('collapsed');
				
				first_child.removeClass('show_me_now').addClass('hide_me_now');
				second_child.removeClass('hide_me_now').addClass('show_me_now');
			}
			
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
	
	$('ul.block-category-left-menu li a.blockcategory-header').each(function(){
		if(this.id == 'category_id_category_' + currentCategoryId)
		{
			var first_child = $(this).children(':first-child');
			var second_child = first_child.next();
			
			first_child.removeClass('show_me_now').addClass('hide_me_now');
			second_child.removeClass('hide_me_now').addClass('show_me_now');
			
			$(this).addClass('expanded').removeClass('collapsed');
			$(this).next().slideDown('slow');
		}
	});
	
	$('ul.block-category-left-menu li ul li a').each(function(){
		if(this.id == 'category_id_category_' + currentCategoryId)
		{
			var menu_header = $(this).parent().parent().prev();
			var first_child = menu_header.children(':first-child');
			var second_child = first_child.next();
			
			first_child.removeClass('show_me_now').addClass('hide_me_now');
			second_child.removeClass('hide_me_now').addClass('show_me_now');
			
			$(this).addClass('category_id_category');
			$(this).parent('li').parent('ul').slideDown('slow');
			$(this).parent('li').parent('ul').prev().addClass('expanded').removeClass('collapsed');
		}
	});
}
$(document).ready(function() {initMenus();});
