// JavaScript Document
function rightMenu()
{
	//force all links from the right menu to reset the session
	$('#rightMenuLinks a').click(function()
	{
		var href = $(this).attr('href');
		$.get('/includes/left_menu_active.php'
				  ,{
			
					  'id':0
				  }
				  ,function(returnData)
					{
						if($.trim(returnData) == 'ok')
						{
							//redirect the user to the href
							window.location = href;
							return false;
						}
						else
						{
							return false;
						}					
					}
				  ,'text');
		return false;
	});
}
function headerLinks()
{
	//force all links from the right menu to reset the session
	$('#topMenuLinks a').click(function()
	{
		var href = $(this).attr('href');
		$.get('/includes/left_menu_active.php'
				  ,{
			
					  'id':0
				  }
				  ,function(returnData)
					{
						if($.trim(returnData) == 'ok')
						{
							//redirect the user to the href
							window.location = href;
							return false;
						}
						else
						{
							return false;
						}					
					}
				  ,'text');
		return false;
	});

}
function mainmenu(){
	//apply this function to all <li> that have a class of root and an <a> with and class of parentLink
	$('.left_menu_ul > li.root a.parentLink').click(function()
	{
		// get the root menu id
		var id = ($(this).attr('id')).split('_');
		//get href from the clicked menu link
		var href = $(this).attr('href');
		//slide up all sub menus
		$('.hasChild ul').slideUp('fast');
		//slide down this sub menu if it isn't already down and therefore has it's display attribute set to 'block'
		//alert($(this).parent().find('ul').css('display'));
		if($(this).parent().find('ul').css('display') != 'block')
		{
			$(this).parent().children().slideDown('fast');
			
			//assign a get to save the session
			if($(this).parent().children().size() > 1){
				$.get('/includes/left_menu_active.php?id=' + id[1]);	
			}
			else
			{
				//the below line was in use before we changed it to fix safari
				//$.get('includes/left_menu_active.php?id=0');
				
				//this has been added due to a problem in safari regarding the redirection of the page
				$.get('/includes/left_menu_active.php'
				  ,{
			
					  'id':0
				  }
				  ,function(returnData)
					{
						//window.location = href;
						//return false;
						//removed the code below due to menu bug, it wasn't loading the page if they
						//were in a directory (e.g /faqs/)
						
						if($.trim(returnData) == 'ok')
						{
							//redirect the user to the href
							window.location = href;
							return false;
						}
						else
						{
							return false;
						}
						
					}
				  ,'text');
				return false;
			}
		}
		else
		{
			//clear the session to 0 (the root)
			$.get('/includes/left_menu_active.php?id=0');
		}
		//make sure this parent menu is visible
		$(this).show();
		//check if the root menu has More than just an <a>, i.e. a <ul> as well and therefore a sub menu of <li>s
		//if not don't return false and let it link through to another page
		//alert($(this).parent().children().size());
		if($(this).parent().children().size() > 1){
			return false;
		}
	});
}