/* ------------------------------------------------------------------------------------
	Misc.js
	
	General JavaScript functions library.
	
	Feb 09 : DB : Intial development
------------------------------------------------------------------------------------ */

/* --------
Core functions
-------- */
function getElementsByClassNameIE(searchClass,node,tag) {
	/* --------
	Selects elements by the class name.
	Create function if it doesn't already exist.
	
	NOTE: getElementsByClassName not supported by IE (upto IE8b2)
	
	Modified version of: http://www.dustindiaz.com/getelementsbyclass/
		(found via http://ejohn.org/blog/getelementsbyclassname-speed-comparison)
	-------- */
	
	var classElements = new Array();
	if ( node == null )
			node = document;
	if ( tag == null )
			tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
			if ( pattern.test(els[i].className) ) {
					classElements[j] = els[i];
					j++;
			}
	}
	return classElements;
}


/* --------
Category Navigation functions
-------- */
function sub_menu_show(id){
	/* --------
	Displays the specified sub menu
	-------- */
	
	// Hide current sub menu
	sub_menu_hide();
	
	// Get current item and set class to current
	var obj_currentitem = document.getElementById(id);
	obj_currentitem.className = 'current';
}

function sub_menu_hide(){
	/* --------
	Hides all sub menus
	-------- */
	
	// Get left navigation
	var obj_leftnavigation = document.getElementById('left_navigation');
	
	// Get current left navigation item (use custom function if needed)
	if(typeof document.getElementsByClassName != 'function') {
		var arr_currentitem = getElementsByClassNameIE('current', obj_leftnavigation);
	}else{
		var arr_currentitem = obj_leftnavigation.getElementsByClassName('current');
	}
	
	// If there is a current item, remove the class name
	if(arr_currentitem.length > 0){
		arr_currentitem[0].className = '';
	}
}