//
//	Cape Breton Regional Library
//	Copyright 2006
// 	http://cbrl.ca
//
//	Coded by Jamie MacKinnon	
//


// This is the function which is called upon the load of the homepage.
// It's primary purpose is to call the hidemenus() function to toggle off all of the submenus in the navigation bar.

function init() {
	hidemenus();
}


// This function hides each submenu on the navigation sidebar.
// While not necissarily elegant in the sense that each call is hard coded, it remains easy to maintain.
// If a visitor doesn't have JavaScript enabled the function won't be called; so the sub menus will all remain visible.

function hidemenus() {
	ref = document.getElementById('searchmenu');
	ref.style.display='none';
	ref = document.getElementById('servicesmenu');
	ref.style.display='none';
	ref = document.getElementById('supportmenu');
	ref.style.display='none';
	ref = document.getElementById('branchmenu');
	ref.style.display='none';
}


// This function performs the check when a main navigational element is clicked on.
// It first gets the element's refference by using the id passed to it, then checks the current display style property.
// Since the CSS doesn't explicity set the display attribute, the default behavior when first called is to hide the element.
// This helps facilitate the hiding of submenus upon page load. 
// After the initial call, the element will have had a display property assigned, and thus allow functional toggling of visibility.

function menu_toggle(menuID, trigger) {
	list = document.getElementById(menuID);
	if (list.style.display != 'none') {
		hide_menu(list);
	}
	else {
		show_menu(list);
	}

	if (trigger.className == '') {
		trigger.className='link_on';
	}
	else {
		trigger.className='';
	}
}


// This function toggles the elements display attribute to 'none', effectivly hiding it from the visitor
// It requires only one parameter, which is the element's refference usually obtained using it's id and getElementById()

function hide_menu(menuRef) {
	menuRef.style.display='none';
}


// This function toggles the elements display attribute to 'block', making the element visible and behaving as a block style element (obviously)
// Like hide_menu, this function also requires the element's refference as a parameter

function show_menu(menuRef) {
	menuRef.style.display='block';
}