function addClass(eleObj,classVal,toggle){
		if(toggle==true){//if class is to be added
			if(!eleObj.className){//if the 'class' attribute does not exist
				eleObj.className = classVal;
			}else if(eleObj.className && eleObj.className.indexOf(classVal)== -1){//if the 'class' attribute does exist then add value to existing value
				eleObj.className+=' ' + classVal;
			}
		}else if(toggle==false){//if class is to be removed
			var newClassVal=eleObj.className.replace(classVal,'');//replace classVal with empty string and return the remaining class value
			eleObj.className=newClassVal;
		}
}
var leftNavArr = new Array();
var divNavArr = new Array();// corresponding divs for each nav item
var firstIndex;
function setLeftNav(){
	if(!document.getElementById('leftNav')){
		return;
	}
	
	var navItems = document.getElementById('leftNav').getElementsByTagName('a');
	for(var i = 0; i < navItems.length; i++){
		var startChar = navItems[i].href.lastIndexOf('#') + 1;
		var arrIndex = navItems[i].href.substr(startChar);
		if(i == 0){
			firstIndex = arrIndex;
		}
		leftNavArr[arrIndex] = navItems[i];
		divNavArr[arrIndex] = document.getElementById(arrIndex);
		
		//leftNavArr.push(navItems[i]);
		navItems[i].onclick = function(){
			
			if(document.getElementById('catIntro')){
				addClass(document.getElementById('catIntro'),'hide',true);
			}
			
			window.location.hash = this.href.split('#')[1];
			for(var i in leftNavArr){
				if(leftNavArr[i] != this){
					addClass(leftNavArr[i].parentNode,'current',false);
					addClass(divNavArr[i],'hide',true);
				}else{
					addClass(leftNavArr[i].parentNode,'current',true);
					addClass(divNavArr[i],'hide',false);
				}
			}
			
			return false;
		}
	}
	if(window.location.hash){
		addClass(leftNavArr[window.location.hash.split('#')[1]].parentNode,'current',true);
		addClass(divNavArr[window.location.hash.split('#')[1]],'hide',false);
	}else{
		addClass(leftNavArr[firstIndex].parentNode,'current',true);
		addClass(divNavArr[firstIndex],'hide',false);
	}
}
function setTopForm(){
	var loginLink = document.getElementById('topLogin');
	var formArr = loginLink.getElementsByTagName('form');
	formArr[0].style.height = '0px';
	loginLink.onclick = function(){
		
	}
}
/* Expand and shrink objects class */
function expandEle(varsArr){
	this.testVar;
	this.expObj;
	this.expObjW;
	this.expObjH;
	this.step = 10;
	this.intervalId;
	this.trigger;
	this.trigTxt;
	this.trigTxtNew = "close";
	this.startH = 0;
	this.endH;
	this.getDfState = null;// default state when page loads
	this.state = false; //true if obj open false if closed
	parentObj = this;
	this.openClass = "open";
	this.openObj;// object to apply class to when open
	for (var key in varsArr) { this[key] = varsArr[key]; }
	
	
	//this.expObj.style.padding="0";
	this.initialise = function(){//determine if obj should be open onload from URL get variable
		if(this.expObj && this.trigger){
			this.expObj.style.height="0";
		}else{
			return;
		}
		if(this.getDfState != null && window.location.href.indexOf(this.getDfState) != -1){
			this.startExp();
		}
		if(this.trigger){
			this.trigger.onclick = createMethodReference(this, "startExp");
			this.trigTxt = this.trigger.innerHTML;
		}
		
	}
	this.growEle = function(){
		addClass(this.openObj,'open',true);
		if(this.expObj.clientHeight < this.endH){
			this.expObj.style.height = (this.expObj.clientHeight + this.step) + "px";
		}else{
			clearInterval(this.intervalId);
			this.state = true;
			this.trigger.innerHTML = this.trigTxtNew;
			
		}

}
this.shrinkEle = function(){
	addClass(this.openObj,'open',false);
	if(this.expObj.clientHeight > 0){
			var currH = this.expObj.clientHeight - this.step;
			this.expObj.style.height = currH + "px";
		}else{
			clearInterval(this.intervalId);
			this.state = false;
			this.trigger.innerHTML = this.trigTxt;
			
		}
}

	this.initialise();
}
expandEle.prototype.startExp = function(){//onclick for trigger in class expandEle
   		//alert(this.testVar);
		if(this.state == false){
			if(this.openObj.className.indexOf(this.openClass) == -1){
				this.intervalId = setInterval (createMethodReference(this, 'growEle'), 1 );
			//this.intervalId = createMethodReference(object, 'growEle');
			}
		}else{
			if(this.openObj.className.indexOf(this.openClass) != -1){
				this.expObj.style.height = this.endH+"px";
				this.intervalId = setInterval (createMethodReference(this, 'shrinkEle'), 1 );
				//this.intervalId = createMethodReference(object, 'shrinkEle');
				//alert(this.expObj.style.height);
			}
		}
		return false;
}
/*expandEle.prototype.growEle = function(){
		if(this.expObj.clientHeight < this.endH){
			this.expObj.style.height = (this.expObj.clientHeight + this.step) + "px";
		}else{
			clearInterval(this.intervalId);
			this.state = true;
			this.trigger.innerHTML = this.trigTxtNew;
			addClass(this.openObj,'open',true);
		}

}
expandEle.prototype.shrinkEle = function(){
	if(this.expObj.clientHeight > 0){
			var currH = this.expObj.clientHeight - this.step;
			this.expObj.style.height = currH + "px";
		}else{
			clearInterval(this.intervalId);
			this.state = false;
			this.trigger.innerHTML = this.trigTxt;
			addClass(this.openObj,'open',false);
		}
}*/
/* Input text class */
function inputLabelVal(){
	for (var key in varsArr) { this[key] = varsArr[key]; }
	this.parentEle;
	this.inpArr = this.parentEle.getElementsByTagName('input');
	for(var i = 0; i < this.parentEle.length; i++){
		
	}
	
}
function createMethodReference(object, methodName) {
    return function () {
        object[methodName]();
    };
}
function ieNavHover(){
	this.re_ie6 =/MSIE 6.0/;
	if(this.re_ie6.test(navigator.userAgent)){//test for IE6 browser
		var liArr = document.getElementById('mainNav').getElementsByTagName('li');
		for(var i in liArr){
			liArr[i].onmouseover = function(){
				addClass(this,'ieHover',true);
			}
			liArr[i].onmouseout = function(){
				addClass(this,'ieHover',false);
			}
		}
	}
}
window.onload = function(){
	//setLeftNav();
	mapIni();
//	setTopForm();
	ieNavHover()
	var loginForm = new expandEle({expObj:document.forms[0],endH: 140,step:14,trigger: document.getElementById('loginTrig'),getDfState:'s=members',openObj: document.getElementById('topLogin')});
	
	var googleMap = new expandEle({expObj:document.getElementById('googleMaps'),endH: 320,step:40,trigger: document.getElementById('mapLink'),openObj: document.getElementById('leftCol')});
	if(document.getElementById('loginHome')){
	var homeLogin = new expandEle({expObj:document.forms[0],endH: 130,trigger: document.getElementById('loginHome').firstChild,getDfState:'s=members',openObj: document.getElementById('topLogin')});
	}
}
