// Faq box code

// first=true; to open first box on load, first=false; to have them all closed
var first=true;

var colHeight=0;var ocolHeight=0;var boxHeight=0;var curHeight=0;var ocurHeight=0;var obj;var objo;var oid=-1;var timer;var timer2;var cid;var allclosed=true;var imBusy=false;
// functions that deal with opening a box
function openbox(id) {	
	if (imBusy==false) {
		imBusy=true;obj=faqAmount[id-1];boxHeight=faqItem[id-1];colHeight=qHeight[id-1];curHeight=colHeight;cid=id;
		// call to close open box after opening a new one
		if (id!=oid && allclosed==false) { closeBox(oid); } else { imBusy=false; }
		if ((obj.offsetHeight-1)<=colHeight) { allclosed=false;obj.firstChild.className+=" qhover";openAni(); } 
		else { allclosed=true;objo=obj;ocolHeight=colHeight;closeBox(oid); }
	}
}
function openAni() { timer=setInterval("moveDown();",1); }
function moveDown() {
	if (curHeight<boxHeight) { curHeight=curHeight+15;obj.style.height=curHeight+"px";} 
	else { clearInterval(timer);obj.style.height=boxHeight+"px";oid=cid; }
}
// functions that deal with closing a box
function closeBox(oid) {
	objo=faqAmount[oid-1];ocolHeight=qHeight[oid-1];ocurHeight=faqItem[oid-1];	
	objo.firstChild.className=objo.firstChild.className.replace(new RegExp(" qhover\\b"), "");	
	closeAni();
}
function closeAni() { timer2=setInterval("moveUp();",1); }
function moveUp() {
	if (ocurHeight>ocolHeight) { ocurHeight=ocurHeight-15;objo.style.height=ocurHeight+"px"; } 
	else { clearInterval(timer2);objo.style.height=ocolHeight+"px";imBusy=false; }
}
// get heights for each box, close all boxes and if required, open the first (var first=true;) or any specific box using #[number] in the url
var faqItem=new Array();var qHeight=new Array();var faqAmount;
function hasFocus() {	
	if (document.getElementById('faqContainer')) {
		document.getElementById('faqContainer').onclick=function() { document.getElementById('blurme').focus(); }
		faqAmount=document.getElementById('faqContainer').getElementsByTagName("li");
		var stopit=faqAmount.length;
		if (stopit>0) {
			for(var i=1; i<=stopit; i++) {		
				faqItem.push(faqAmount[i-1].offsetHeight);
				qHeight.push(faqAmount[i-1].firstChild.offsetHeight);
				faqAmount[i-1].nr = i;
				faqAmount[i-1].onclick=function() { openbox(this.nr); }		
			}
			for(var i=1; i<=faqItem.length; i++) { faqAmount[i-1].style.height=qHeight[(i-1)]+"px";	}	
			if (location.hash) { var id=location.hash;id=id.replace(/#/,"");openbox(id); } 
			else if (first==true) { openbox(1); }
		}
	}
}
//onload=hasFocus;
