function strrpos(haystack, needle) {
	haystack_len = haystack.length;
	found = false;
	while (haystack_len >= 0) {
		// get 1 char and compare
		char = haystack.substr(haystack_len, 1);
		if (char == needle) {
			var found = true;
			return (haystack_len+1);
		}
		haystack_len--;
	}
	if (!found) return -1;
}
if (window.location.hostname == "www.btha.co.uk") {
	serverpath = window.location.protocol+"//"+window.location.hostname+"/";
} else {
	serverpath = window.location.protocol+"//"+window.location.hostname+"/btha/";	
}
sub_menu_items = new Array('about_us_general_info', 'about_us_contact', 'about_us_toy_trust', 'about_us_toy_safety', 'about_us_max_it', 'about_us_toy_fair', 'membership_becoming', 'membership_benefits', 'membership_code', 'membership_members', 'membership_links', 'value_national', 'value_making_time', 'value_solutions', 'value_playsafe', 'value_playday', 'press_publications', 'press_press', 'healthy_development');
menu_items = new Array('about_us', 'membership', 'value', 'press', 'faq');

function preloadMenuImages() {
	// preload all the images
	
}

function turnAllOff() {
	for (var aid in menu_items) {
		// declare all the on/off states
		eval(menu_items[aid]+"_over_src = 'images/"+menu_items[aid]+"_button_over.gif';");
		eval(menu_items[aid]+"_off_src = 'images/"+menu_items[aid]+"_button_off.gif';");
		// turn off all the others before turning on the selected one.
		document.images[menu_items[aid]].src = serverpath+eval(menu_items[aid]+"_off_src");
		document.getElementById('subnav_'+menu_items[aid]).style.display = 'none'; 
	}
	if (document.images['parents'].src == serverpath+'images/parents_button_over.gif') {
		document.images['parents'].src = serverpath+'images/parents_button_off.gif';	
	} else {
		document.images['parents'].src = serverpath+'images/parents_button_over.gif';	
	}
}
function showMenu(img_name) {
//	alert(img_name);
	for (var aid in menu_items) {
		// declare all the on/off states
		eval(menu_items[aid]+"_over_src = 'images/"+menu_items[aid]+"_button_over.gif';");
		eval(menu_items[aid]+"_off_src = 'images/"+menu_items[aid]+"_button_off.gif';");
		// turn off all the others before turning on the selected one.
		document.images[menu_items[aid]].src = serverpath+eval(menu_items[aid]+"_off_src");
		document.getElementById('subnav_'+menu_items[aid]).style.display = 'none'; 
	}
	for (var aid in sub_menu_items) {
		// declare all the on/off states
		eval(sub_menu_items[aid]+"_over_src = 'images/"+sub_menu_items[aid]+"_over.gif';");
		eval(sub_menu_items[aid]+"_off_src = 'images/"+sub_menu_items[aid]+"_off.gif';");
		// turn off all the others before turning on the selected one.
		document.images[sub_menu_items[aid]].src = serverpath+eval(sub_menu_items[aid]+"_off_src");
//		document.getElementById('subnav_'+menu_items[aid]).style.display = 'none'; 
	}
	// Find the filename
	if (img_name != "") {

			pos = strrpos(window.location.pathname, "/");
		var path = window.location.pathname.substr(0, pos);
		if (document.images[img_name].src == serverpath+eval(img_name+"_off_src")) {
			// turn on the correct one and display the sub nav
			document.images[img_name].src = serverpath+eval(img_name+"_over_src");
			document.getElementById('subnav_'+img_name).style.display = 'block'; 
		}
	}
}

function showSubMenu(img_name) {
	for (var aid in sub_menu_items) {
		// declare all the on/off states
		eval(sub_menu_items[aid]+"_over_src = 'images/"+sub_menu_items[aid]+"_over.gif';");
		eval(sub_menu_items[aid]+"_off_src = 'images/"+sub_menu_items[aid]+"_off.gif';");
		// turn off all the others before turning on the selected one.
		document.images[sub_menu_items[aid]].src = serverpath+eval(sub_menu_items[aid]+"_off_src");
	}
//	alert(img_name);
	if (img_name != "") {
		pos = strrpos(window.location.pathname, "/");
		var path = window.location.pathname.substr(0, pos);
		if (document.images[img_name].src == serverpath+eval(img_name+"_off_src")) {
			// turn on the correct one
	//		alert(serverpath+eval(img_name+"_over_src"));
			document.images[img_name].src = serverpath+eval(img_name+"_over_src");
		}
	}
}