/*
Name: sectionMenu.js
Description: the left hand side menu for all pages
*/

var currItem = false;

function setCurrentSection(initialSection){
					
	//get URL parameters		
	var param = getParam(location);
	
	//alert(param);
	
	if(param != null){
		
		//display the selected item
		toCurrent(param);
		//scroll the windows to focus on the Viewer
		//window.scrollTo(200,200)
	}
	else{	//set the initial section
		if(initialSection){
			//alert(initialSection);
			toCurrent(initialSection);
			param = initialSection;	
		}
	}
	//alert(param);
	return param;	
}

//function getParam
//Params: url, is the current browser's location address string
//Return value: it returns the first parameter in the address string
//			    it no parameters found, returns null

function getParam(url){
	var str = new String(url);
	str = str.substring((str.indexOf("?")+1));
	var params;
	var arg = null;
	//alert(str);
	
	if(str.length > 0){
		params = new Array(str.split(","));
	//	alert(params.length);
		if( params.length > 0){
			var temp = new String(params[0]);
			if(temp.indexOf("=") != -1){				
				arg = temp.substring(temp.indexOf("=")+1);
			}
			//alert(arg);
		}
	}
	return arg;
}

/*
highlight
highlight a section menu item

- highlight css property
	- font color: #ffffff
	- cell background color: #7fb5ff
- normal css property
	- font color: #003366
	- cell background color: #6699FF

Params:
	- anItem
*/
function highlight(anItem){
	var newItem = getObj(anItem, 1);
	if(newItem && currItem != newItem){
		newItem.color='#ffffff';
		newItem.backgroundColor='#7fb5ff';
	}
	//newItem.className='highlight';
}

/*
toNormal
set a section item to normall css property

Params:
	anItem
*/

function toNormal(anItem){
	var newItem = getObj(anItem, 1);
	if(newItem && currItem != newItem){
		//-----> set it to normal
		newItem.color='#ffffff';
		newItem.backgroundColor='#6699ff';
	}
}

/*
toCurrent
set a section item to current selected item	
Params:
	anItem, the new item to become current item
*/
function toCurrent(anItem){

	if(currItem){
		//----> set back to normal
		currItem.color='#ffffff';
		currItem.backgroundColor='#6699ff';
	}
	//alert(anItem);
	//alert(findObj(anItem, document));
	var newItem = getObj(anItem, 1);
	//newItem = findObj(anItem, document);
	//alert(newItem);
	currItem = newItem;
	currItem.color="#003366";
	currItem.backgroundColor='#7fb5ff';		
}

