/*
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.
*/

ACC = {

E:function(d){
	return document.getElementById(d);
},

// set or get the current display style of the div
dsp:function(d,v){
	if(v==undefined){
		return d.style.display;
	}else{
		d.style.display=v;
	}
},

// set or get the height of a div.
sh:function(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:2,
t:2,

//Collapse Timer is triggered as a setInterval to reduce the height of the div exponentially.
ct:function(d){
	d = ACC.E(d);
	if(ACC.sh(d)>0){
		v = Math.round(ACC.sh(d)/d.s);
		v = (v<1) ? 1 :v ;
		v = (ACC.sh(d)-v);
		d.style.opacity = (v/d.maxh);
		d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
		ACC.sh(d,v+'px');
	}else{
		ACC.sh(d,'0px');
		ACC.dsp(d,'none');
		clearInterval(d.t);
	}
},

//Expand Timer is triggered as a setInterval to increase the height of the div exponentially.
et:function(d){
	d = ACC.E(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);
		d.style.opacity = (v/d.maxh);
		d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
		ACC.sh(d,v+'px');
	}else{
		ACC.sh(d,d.maxh + 'px');
		clearInterval(d.t);
	}
},

// Collapse Initializer
cl:function(d){
	if(ACC.dsp(d)=='block'){
		clearInterval(d.t);
		d.t=setInterval('ACC.ct("'+d.id+'")',ACC.t);
	}
},

//Expand Initializer
ex:function(d){
	if(ACC.dsp(d)=='none'){
		ACC.dsp(d,'block');
		d.style.height='0px';
		clearInterval(d.t);
		d.t=setInterval('ACC.et("'+d.id+'")',ACC.t);
	}
},

// Removes Classname from the given div.
cc:function(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){
	// get all the elements that have id as content
	l=ACC.E(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=ACC.E(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=ACC.E(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){
						ACC.ex(ACC.E(n+'-content'));
						n=ACC.E(n+'-header');
						ACC.cc(n,'__');
						n.className=n.className+' '+n.tc;
					}else{
						ACC.cl(ACC.E(n+'-content'));
						ACC.cc(ACC.E(n+'-header'),'');
					}
				}
			}
			if(h.className.match(/selected+/)!=undefined){ sel=h;}
		}
	}
	if(sel!=undefined){sel.onclick(); }
}


