/*
	-> Tab Nav
	tab navigation in accordion style...
	
	coded in january 2007 by pinit.
	http://me.pinit.it

	(feel free to use but please keep this comment!)
*/

var tabnav = {
	divs : new Array,
	h : new Array,
	mytravel : null,
	hash : window.location.hash,
	fire : function() {
		var mytags = document.getElementsByTagName("a");
		n = 0;
		for (i=0; i<mytags.length; i++) {
		if (mytags[i].className=="h_lnk") {
				var lnk = mytags[i];
				lnk.mydiv = mytags[i].parentNode.parentNode.id.substr((mytags[i].parentNode.parentNode.id.search("_"))+1);
				lnk.onclick = function() {tabnav.show(this.mydiv);return false;}
				tabnav.divs[n] = lnk.mydiv;
				div = document.getElementById(lnk.mydiv);
				tabnav.h[n] = div.offsetHeight;
				div.style.overflow = "hidden";
				div.style.height = "0";
				n++;
			}
		}
		if (tabnav.hash.indexOf('#') != -1) {
			id = tabnav.hash.substr((tabnav.hash.search('#'))+1);
			tabnav.show(id);
			window.location = tabnav.hash;
			}
	},
	show : function(id) {
		iclose=null;
		for (i=0; i<tabnav.divs.length; i++) {
			div = document.getElementById(tabnav.divs[i]);
			if (tabnav.divs[i] != id) {if (div.offsetHeight > 2) {iclose=i;}}
			else {iopen=i;}
		}
		if (this.mytravel == null) {this.mytravel = setInterval("tabnav.travelling("+iopen+","+iclose+")",50);}
	},
	travelling : function(iopen,iclose) {
		closedone = false;
		opendone = false;
		if (iclose == null) {closedone=true;}
		else {
			divclose = document.getElementById(tabnav.divs[iclose]);
			hclose = divclose.offsetHeight;		
			if (hclose>2) {hclose=parseInt(hclose+(-hclose/2));} else {closedone=true;}
		}
		divopen = document.getElementById(tabnav.divs[iopen]);
		hopen = divopen.offsetHeight;
		if (Math.abs(hopen-(tabnav.h[iopen]+20)) > 2) {hopen=parseInt(hopen+((tabnav.h[iopen]+20)-hopen)/2);} else {opendone=true;}
		if (closedone&&opendone) {clearInterval(this.mytravel);this.mytravel=null;} 
		else {		
			if (iclose != null) {divclose.style.height= hclose+'px';}
			divopen.style.height= hopen+'px';
		}
		//document.getElementById("debug").innerHTML = "h-op:" + tabnav.h[iopen] + "|h-cl:" + tabnav.h[iclose] + "|odone:" + opendone + "|oclose:" + closedone + "|hop:" + hopen;
	}
}