/*
DezinerFolio.com Simple Accordians.

Author  : G.S.Navin Raj Kumar
Website : http://dezinerfolio.com
The Variable names have been compressed to achive a higher level of compression.
*/

/*
This script has been cleaned up and updated by Troy Wheelhouse to 
allow an accordian speed of '0', which removes the transition effect altogether.

This is useful to me when this was used for horizontal tabs, where no transition 
was desirable.
*/


// set or get the current display style of the div
function dsp(d,v){
	if(v==undefined){
		return d.style.display;
	}else{
		d.style.display=v;
	}
}

// set or get the height of a div.
function sh(d,v){
	// if you are getting the height then display must be block to return the absolute height
	if(v==undefined){
		if(dsp(d)!='none'&& dsp(d)!=''){
			return d.offsetHeight;
		}
		viz = d.style.visibility;
		d.style.visibility = 'hidden';
		o = dsp(d);
		dsp(d,'block');
		r = parseInt(d.offsetHeight);
		dsp(d,o);
		d.style.visibility = viz;
		return r;
	}else{
		d.style.height=v;
	}
}
/*
* Variable 'T' defines the refresh rate of the accordian
*/
t=10;

//Collapse Timer is triggered as a setInterval to reduce the height of the div exponentially.
function ct(d){
	d = document.getElementById(d);
	if(sh(d)>0){
		v = Math.round(sh(d)/d.s);
		v = (v<1) ? 1 :v ;
		v = (sh(d)-v);
		sh(d,v+'px');
		d.style.opacity = (v/d.maxh);
		d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
	}else{
		sh(d,0);
		dsp(d,'none');
		clearInterval(d.t);
	}
}

//Expand Timer is triggered as a setInterval to increase the height of the div exponentially.
function et(d){
	d = document.getElementById(d);
	if(sh(d)<d.maxh){
		v = Math.round((d.maxh-sh(d))/d.s);
		v = (v<1) ? 1 :v ;
		v = (sh(d)+v);
		sh(d,v+'px');
		d.style.opacity = (v/d.maxh);
		d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
	}else{
		sh(d,d.maxh);
		clearInterval(d.t);
	}
}

// Collapse Initializer
function cl(d){
	if(dsp(d)=='block'){
		d.style.overflow='hidden';
		if (d.s != 0)
		{
			clearInterval(d.t);
			d.t=setInterval('ct("'+d.id+'")',t);
		}
		else
		{
			dsp(d,'none');
		}
	}
}

//Expand Initializer
function ex(d){
	if(dsp(d)=='none')
	{
		dsp(d,'block');
		d.style.overflow='visible';

		if (d.s != 0)
		{
			d.style.height='0px';
			clearInterval(d.t);
			d.t=setInterval('et("'+d.id+'")',t);
		}
	}
}

// Removes Classname from the given div.
function cc(n,v){
	s=n.className.split(/\s+/);
	for(p=0;p<s.length;p++){
		if(s[p]==v+n.tc){
			s.splice(p,1);
			n.className=s.join(' ');
			break;
		}
	}
}
//Accordian Initializer
function Accordian(d,s,tc){
/* Variable 'D' defines the id of the accordian div
 * Variable 'S' defines the speed of the accordian
 * Variable 'TC' defines CSS class name that indicates the selected tab
 */

	// get all the elements that have id as content
	l=document.getElementById(d).getElementsByTagName('div');
	c=[];
	for(i=0;i<l.length;i++){
		h=l[i].id;
		if(h.substr(h.indexOf('-')+1,h.length)=='content'){c.push(h);}
	}
	sel=null;
	//then search through headers
	for(i=0;i<l.length;i++){
		h=l[i].id;
		if(h.substr(h.indexOf('-')+1,h.length)=='header'){
			d=document.getElementById(h.substr(0,h.indexOf('-'))+'-content');
			d.style.display='none';
			d.style.overflow='hidden';
			d.maxh =sh(d);
			d.s=(s==undefined)? 7 : s;
			h=document.getElementById(h);
			h.tc=tc;
			h.c=c;
			// set the onclick function for each header.
			h.onclick = function(){
				for(i=0;i<this.c.length;i++){
					cn=this.c[i];
					n=cn.substr(0,cn.indexOf('-'));
					if((n+'-header')==this.id){
						ex(document.getElementById(n+'-content'));
						n=document.getElementById(n+'-header');
						cc(n,'__');
						if (n.className.match(tc)==undefined)
							n.className=n.className+' '+n.tc;
					}else{
						cl(document.getElementById(n+'-content'));
						cc(document.getElementById(n+'-header'),'');
					}
				}
				
				eval(this.id.substr(0,this.id.indexOf('-')) + '_header_onclick()');
			}
			var re = eval('/\\b' + tc + '\\b/');
			if(h.className.match(re)!=undefined){ sel=h;}
		}
	}
	if(sel!=undefined){sel.onclick();}
}
