
//Secondary (left) Navigation Menu
rebuildSideNavigation=function() {
	var clicked_menu_head;
	var speed = 300;
 
 	$("div.menu_body").hide();
	$(".menu_body:eq(0)").show();
	$('.menu_head').css({backgroundImage:"url(images/nav/open.gif)"});
	
			//aded by sam to select the correct item
	$('.menu_body > div > a').each(function() {
		if(jQuery.historyCurrentHash ){
			if( this.href.indexOf(jQuery.historyCurrentHash.replace(/^#/, '')+'.php') > -1){
			//$(this).css({border:"1px solid #FF6600"});//ajax linking hilight
			this.className='current';
			}
		}else if( this.href.indexOf(getPageFromUrl( {'href':window.location.href} )+'.php') > -1  ){
			//$(this).css({border:"1px solid #FF6600"});//direct linking hilight
			this.className='current';
		}
	});
			
	$('.menu_head').click(function() {
		
		clicked_menu_head = $(this);
		if (clicked_menu_head.next().is(':visible')) {
			clicked_menu_head.next().slideUp();
			clicked_menu_head.css({backgroundImage:"url(images/nav/closed.gif)"});
		}
 
		// if clicked menu head is submenu, check if there are any submenus in it, then hide
		clicked_menu_head.next().find('p.menu_head').each(function () {
			$(this).next().slideUp(speed);
			$(this).css({backgroundImage:"url(images/nav/closed.gif)"});
		});
 
		parent_menu_head = clicked_menu_head.parents('div.menu_body').prev(clicked_menu_head.parents('div.menu_body').size()-1);
 
		if (clicked_menu_head.next('div.menu_body').is(':visible')) {
		} else clicked_menu_head.css({backgroundImage:"url(images/nav/open.gif)"}).next('div.menu_body').slideDown(speed);
 
 
		$('#firstpane').children('p').siblings('p').each(function() {
			// loop through each main menu, if not equal, hide all sub menu
			if (parent_menu_head.attr('id')) {
				if (parent_menu_head.attr('id') != $(this).attr('id')) {
					$(this).children('div.menu_body').slideUp(speed);
				}
			} else {
				if (clicked_menu_head.attr('id') != $(this).attr('id')) {
					$(this).css({backgroundImage:"url(images/nav/closed.gif)"})
					$(this).next().slideUp(speed).find('p.menu_head').each(function() {
						$(this).next().slideUp(speed);
					});
				}
			}
 
		});
		return false;
	});
}


$(document).ready(rebuildSideNavigation);