/*
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.
*/

// set or get the current display style of the div
function acc_dsp(d,v){
	if(v==undefined){
		return d.style.display;
	}else{
		d.style.display=v;
	}
}

// set or get the height of a div.
function acc_sh(d,v){
	// if you are getting the height then display must be block to return the absolute height
	if(v==undefined){
		if(acc_dsp(d)!='none'&& acc_dsp(d)!=''){
			return d.offsetHeight;
		}
		viz = d.style.visibility;
		d.style.visibility = 'hidden';
		o = acc_dsp(d);
		acc_dsp(d,'block');
		r = parseInt(d.offsetHeight);
		acc_dsp(d,o);
		d.style.visibility = viz;
		return r;
	}else{
		d.style.height=v;
	}
}
/*
* Variable 'S' defines the speed of the accordian
* Variable 'T' defines the refresh rate of the accordian
*/
s=7;
t=10;
mmax=0;
inteval = 10000;
my_inteval = null;

//Collapse Timer is triggered as a setInterval to reduce the height of the div exponentially.
function acc_ct(d){
	d = gId(d);
	if(acc_sh(d)>0){
		v = Math.round(acc_sh(d)/d.s);
		v = (v<1) ? 1 :v ;
		v = (acc_sh(d)-v);
		acc_sh(d,v+'px');
		d.style.opacity = (v/d.maxh);
		d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
	}else{
		acc_sh(d,0);
		acc_dsp(d,'none');
		clearInterval(d.t);
	}
}

//Expand Timer is triggered as a setInterval to increase the height of the div exponentially.
function acc_et(d){
	d = gId(d);
	if(acc_sh(d)<d.maxh){
		v = Math.round((d.maxh-acc_sh(d))/d.s);
		v = (v<1) ? 1 :v ;
		v = (acc_sh(d)+v);
		acc_sh(d,v+'px');
		d.style.opacity = (v/d.maxh);
		d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
	}else{
		acc_sh(d,d.maxh);
		clearInterval(d.t);
	}
}

// Collapse Initializer
function acc_cl(d){
	if(acc_dsp(d)=='block'){
		clearInterval(d.t);
		d.t=setInterval('acc_ct("'+d.id+'")',t);
	}
}

//Expand Initializer
function acc_ex(d){
	if(acc_dsp(d)=='none'){
		acc_dsp(d,'block');
		d.style.height='0px';
		clearInterval(d.t);
		d.t=setInterval('acc_et("'+d.id+'")',t);
	}
}

// Removes Classname from the given div.
function acc_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,sel){
	// get all the elements that have id as content
	l=gId(d).getElementsByTagName('dt');
	var dd=gId(d).getElementsByTagName('dd');
	mmax = dd.length;
	c=[];
	for(i=0;i<dd.length;i++){
		h = dd[i].id = 'd'+i+'-content';
		c.push(h);
	}
	for(i=0;i<l.length;i++){
		h=l[i].id = 'd'+i+'-header';;
	}
	//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=gId(h.substr(0,h.indexOf('-'))+'-content');
			d.style.display='none';
			d.style.overflow='hidden';
			d.maxh =acc_sh(d);
			d.s=(s==undefined)? 7 : s;
			h=gId(h);
			h.tc=tc;
			h.c=c;
			// set the onclick function for each header.			
			h.onmouseover = function(){
				var cur = 0;
				for(i=0;i<this.c.length;i++){
					cn=this.c[i];
					n=cn.substr(0,cn.indexOf('-'));
					if((n+'-header')==this.id){
						acc_ex(gId(n+'-content'));
						n=gId(n+'-header');
						acc_cc(n,'__');
						n.className=n.className+' '+n.tc;
						cur = parseInt(cn.substr(1,cn.indexOf('-')-1));
					}else{
						acc_cl(gId(n+'-content'));
						acc_cc(gId(n+'-header'),'');
					}
				}				
				if(my_inteval) {clearTimeout(my_inteval);}
				cur++;
				if(mmax <= cur) cur = 0;
				my_inteval = setTimeout('auto_flip('+cur+')',inteval);
			}
		}
	}	
	auto_flip(sel);
}

function auto_flip(idx){
	if(!idx) idx =0;
	gId('d'+idx+'-header').onmouseover();		
}
