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;
		}
}

/* 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(){
		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);
		}

}
this.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);
		}
}

	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 createMethodReference(object, methodName) {
    return function () {
        object[methodName]();
    };
}


function setVeil(eleArr,classVal){
	for(var i =0; i < eleArr.length; i++){
		//eleArr[i].style.display = 'none';
		var spanEle = document.createElement("span");
		spanEle.className = classVal;
		eleArr[i].parentNode.appendChild(spanEle);
		spanEle.style.height = eleArr[i].parentNode.offsetHeight;
	}
}
function ieEleHover(parentEle,childEle){
	if(!parentEle){
		return;
	}
	this.re_ie6 =/MSIE 6.0/;
	if(this.re_ie6.test(navigator.userAgent)){//test for IE6 browser
		var eleArr = parentEle.getElementsByTagName(childEle);
		for(var i in eleArr){
			eleArr[i].onmouseover = function(){
				addClass(this,'ieHover',true);
			}
			eleArr[i].onmouseout = function(){
				addClass(this,'ieHover',false);
			}
		}
	}
}
function getExcerpt(charLength,parentOb,newParent){
	//alert(' 1st parentOb = ' + parentOb.nodeName );
	var firstObj = parentOb.firstChild;
	//alert('2st parentOb = ' + parentOb.nodeName );
	//alert(firstObj.nextSibling.nodeName);
	while(firstObj.nodeType != 1 && firstObj.nextSibling != null){
		
		
			firstObj = firstObj.nextSibling;
		
		
	}//alert('firstObj.tagName = ' + firstObj.nodeName );
	if(firstObj.nodeName == "P"){
		excerptObj = document.createElement('span');
		excerptObj.className = 'excerpt';
		excerptObj.innerHTML = firstObj.innerHTML.substr(0,charLength) + '...';
		//alert('alora' + excerptObj.nodeName);
		
		//return excerptObj;
		newParent.appendChild(excerptObj);
	}
	//
}
function toggleEle(parentEle,trigger,togEle,classVal,excerpt){
	if(!document.getElementById(parentEle)){
		return;
	}
	var linkArr = document.getElementsByTagName(trigger);
	
	for(var i = 0; i < linkArr.length; i++){
		
		if(excerpt == true){
			var nextObj = getAdjEle(linkArr[i],false);
			//var newNode = getExcerpt('150',nextObj);
			getExcerpt('150',nextObj,linkArr[i]);
			//
			//linkArr[i].appendChild(getExcerpt('150',nextObj));
			//linkArr[i].insertBefore(newNode, linkArr[i].firstChild);
			//alert(window.location.hash.substr(1));
			if(window.location.href.indexOf('hExcrpt=true') != -1 && linkArr[i].className.indexOf(window.location.hash.substr(1)) != -1){
				var nextObj = getAdjEle(linkArr[i],false);
				addClass(linkArr[i],classVal,true);
				addClass(nextObj,classVal,true);
			}
		}
		linkArr[i].onclick = function(){
			var nextObj = getAdjEle(this,false);
			if(nextObj.className.indexOf(classVal) != -1){
				togBoolean = false;
			}else{
				togBoolean = true;
			}
			addClass(this,classVal,togBoolean);
			addClass(nextObj,classVal,togBoolean);
			//alert(nextObj.nodeName);
		}
	}
}
function getAdjEle(currObj,prevSib){
	var adjObj;
	/*if(currObj.previousSibling == null){ /* required for IE otherwise an error generated */
		//alert(currObj.previousSibling);
		//return null;
	/*}*/
	/**///if(currObj.nextSibling == null){ /* required for IE otherwise an error generated */
		//alert(currObj.nextSibling);
	//	return null;
	//}
	if(prevSib == true){
		adjObj = currObj.previousSibling;
		while(adjObj.nodeType != 1 && adjObj.previousSibling != null){
			adjObj = adjObj.previousSibling;
		}
		
	}else if(prevSib == false){
		adjObj = currObj.nextSibling;
		while(adjObj.nodeType != 1 && adjObj.nextSibling != null){
			//alert(adjObj.nodeType);
			adjObj = adjObj.nextSibling;
		}
	
	}
	//alert('adjObj.nodeName = ' + adjObj.firstChild.nodeName);
	return adjObj;
}

window.onload = function(){
	toggleEle('normFaqs','dt','dl','open',false);
	toggleEle('excFaqs','dt','dl','open',true);
//	setTopForm();
	ieEleHover(document.getElementById('staffThumbs'),'li');
	ieEleHover(document.getElementById('mainNav'),'li');
	if(document.getElementById('loginForm')){	
		var loginForm = new expandEle({expObj:document.getElementById('loginForm'),endH: 111,step:37,trigger: document.getElementById('loginLink').firstChild,getDfState:'s=members',openObj: document.getElementById('leftCol'),trigTxtNew:'Close Login'});
	}
	if(document.getElementById('memOrder')){
		//alert(Math.round(document.getElementById('memOrder').offsetHeight/4)*4);
		var loginForm = new expandEle({expObj:document.getElementById('memOrder'),endH: Math.round(document.getElementById('memOrder').offsetHeight/12)*12,step:Math.round(document.getElementById('memOrder').offsetHeight/12),trigger: document.getElementById('orderLink').firstChild,getDfState:'s=members',openObj: document.getElementById('mainCol'),trigTxtNew:'Close order form'});
	}
	if(document.getElementById('staffThumbs')){
		setVeil(document.getElementById('staffThumbs').getElementsByTagName('img'),'veil');
	}
	if(document.getElementById("googleMap")){
		initialize();
	}
}
