
/*
DezinerFolio.com Simple Accordians.

Author  : G.S.Navin Raj Kumar
Object Version : V Ripoche
Website : http://dezinerfolio.com

*/

/*
* The Variable names have been compressed to achive a higher level of compression.
*/

Accordian = {
	/*
	* Variable 'S' defines the speed of the accordian
	* Variable 'T' defines the refrethis.sh rate of the accordian
	*/
	s:7,
	t:10,
	blocker:new Array(),
	// 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(this.dsp(d)!='none'&& this.dsp(d)!=''){
				return d.offsetHeight;
			}
			viz = d.style.visibility;
			d.style.visibility = 'hidden';
			o = this.dsp(d);
			this.dsp(d,'block');
			r = parseInt(d.offsetHeight);
			this.dsp(d,o);
			d.style.visibility = viz;
			return r;
		}else{
			d.style.height=v;
		}
	},
	//Collapse Timer is triggered as a setInterval to reduce the height of the div exponentially.
	ct: function(d){
		d = $(d);
		if(this.sh(d)>0){
			v = Math.round(this.sh(d)/d.s);
			v = (v<1) ? 1 :v ;
			v = (this.sh(d)-v);
			this.sh(d,v+'px');
			d.style.opacity = (v/d.maxh);
			d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
		}else{
			this.sh(d,0);
			this.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 = $(d);
		if(this.sh(d)<d.maxh){
			v = Math.round((d.maxh-this.sh(d))/d.s);
			v = (v<1) ? 1 :v ;
			v = (this.sh(d)+v);
			this.sh(d,v+'px');
			d.style.opacity = (v/d.maxh);
			d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
		}else{
			this.sh(d,d.maxh);
			clearInterval(d.t);
		}
	},
	// Collapse Initializer
	cl: function(d){
		if(this.dsp(d)=='block'){
			clearInterval(d.t);
			d.t=setInterval('Accordian.ct("'+d.id+'")',this.t);
		}
	},
	//Expand Initializer
	ex: function(d){
		if(this.dsp(d)=='none'){
			this.dsp(d,'block');
			d.style.height='0px';
			clearInterval(d.t);
			d.t=setInterval('Accordian.et("'+d.id+'")',this.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
	load: function(d,s,tc){
		var thisObj = this;
		// get all the elements that have id as content
		l=$(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=$(h.substr(0,h.indexOf('-'))+'-content');
				d.style.display='none';
				d.style.overflow='hidden';
				d.maxh =this.sh(d);
				d.s=(s==undefined)? 7 : s;
				h=$(h);
				h.tc=tc;
				h.c=c;
				// set the onclick function for each header.
				h.onclick = function(){
					if(!thisObj.blocker[this.id]){
						for(i=0;i<this.c.length;i++){
							cn=this.c[i];
							n=cn.substr(0,cn.indexOf('-'));
							if((n+'-header')==this.id){
								thisObj.ex($(n+'-content'));
								n=$(n+'-header');
								thisObj.cc(n,'__');
								n.className=n.className+' '+n.tc;
							}else{
								thisObj.cl($(n+'-content'));
								thisObj.cc($(n+'-header'),'');
							}
						}
					}
				}
				if(h.className.match(/selected+/)!=undefined){ sel=h;}
			}
		}
		if(sel!=undefined){sel.onclick();}
	}
}
