// http://www.zero1.co.uk HTML AJAX call for loading the menu system
var oldOnload = window.onload;
window.onload = function(){};

var xmlhttp;
var menuContent;

var menuHighlight = Array();

//////////////////////////////////////////////////////////////////////////////////////////
// Edit below here
/*
Assign CSS id's to the <li>'s in the menu.html file.
Using these id's (Right side) link the selected menu item to the page / foler name (Right side)
For example.

menu.html
---------
<li id="menu_title_video_camera_hire">

This file
---------
menuHighlight['video_camera_hire']			= 'menu_title_video_camera_hire';

Now any folder path / page name from the URL that contains "video_camera_hire"
will highlight the <li> with the id of "menu_title_video_camera_hire"

menuHighlight['SEARCH_FOR']					= 'ID TO HIGHLIGHT';
*/
//////////////////////////////////////////////////////////////////////////////////////////
menuHighlight['video_camera_hire']	= 'menu_title_video_camera_hire';
menuHighlight['video_camera_package_hire']	= 'menu_title_video_camera_hire';
menuHighlight['camera_hire']		= 'menu_title_camera_hire';
menuHighlight['camera_package_hire']		= 'menu_title_camera_hire';
menuHighlight['lens_hire']			= 'menu_title_lens_hire';
menuHighlight['accessory_hire']		= 'menu_title_accessory_hire';
menuHighlight['apple_hire']		= 'menu_title_apple_hire';
menuHighlight['services']			= 'menu_title_services';
menuHighlight['how_to_hire']		= 'menu_title_how_to_hire';
menuHighlight['about_us']			= 'menu_title_about_us';
menuHighlight['contact']			= 'menu_title_contact';
//////////////////////////////////////////////////////////////////////////////////////////
// Edit above here
//////////////////////////////////////////////////////////////////////////////////////////


function highlightMenu()
{
	pathArray = window.location.pathname.split('/');
	
	elementId = 'menu_title_home';
	
	for(i=0;i<pathArray.length;i++)
	{
		if(menuHighlight[pathArray[i]] != null && menuHighlight[pathArray[i]].length > 0)
		{
			elementId = menuHighlight[pathArray[i]];
			break;
		}
	}
	
	if(elementId.length > 0)
	{
		try
		{
			document.getElementById(elementId).className = 'menu_highlighted';
		} catch(e) {
			alert('Failed to highlight the menu.');
		}
	}
}

function updateMenu()
{
	try
	{
		document.getElementById('menuSystem').innerHTML = menuContent;
		highlightMenu();
	} catch(e) {
		alert("Failed to update menu system");
	}
}

function handleHttpResponse()
{
	try
	{
		if(xmlhttp.readyState == 4)
		{
			menuContent = xmlhttp.responseText;
			updateMenu();
		}
	} catch(e) {
		alert("Failed to load menu system");
	}
}

function loadMenu()
{	
	// IE6 Fix for lack of native XMLHttpRequest support
	/*@cc_on @if (@_win32 && @_jscript_version >= 5) if (!window.XMLHttpRequest)
	window.XMLHttpRequest = function() { return new ActiveXObject('Microsoft.XMLHTTP') }
	@end @*/

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		try
		{
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp = false;
		}
		
		if(xmlhttp)
		{
			xmlhttp.open("GET", '/menu.html', false);
			xmlhttp.send(null);
			handleHttpResponse();
			/*
			xmlhttp.open("GET", '/menu.html', true);
			xmlhttp.onreadystatechange = handleHttpResponse;
			xmlhttp.send(null);
			*/
		}
	}
	
	// Shopping cart system, nothing to do with the menu system
	try
	{		
		if( document.getElementsByTagName )
		{
			var Lt = document.getElementsByTagName('a');
		}
		else if( document.styleSheets && document.all )
		{
			var Lt = document.all.tags('A');			
		}
		
		if(Lt)
		{
			for( var x = 0; Lt[x]; x++ )
			{
				//check for the rel attribute to see if it contains 'style'
				if( Lt[x].rel )
				{
					var rel = Lt[x].rel;
				}
				else if( Lt[x].getAttribute )
				{
					var rel = Lt[x].getAttribute('rel');
				}
				else
				{
					var rel = '';
				}
				
				if( typeof( rel ) == 'string' && rel.toLowerCase() == 'checkout' )
				{
					Lt[x].href = '/checkout.php';
				}
			}
		}
		
	} catch(e) {
		
	}
}

if (window.addEventListener)
{
	window.addEventListener("load", loadMenu, false);
} else if (window.attachEvent) {
	window.attachEvent("onload", loadMenu);
} else {
	window.onload = loadMenu;
}

