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

ACCT = {

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(ACCT.dsp(d)!='none'&& ACCT.dsp(d)!=''){
			return d.offsetHeight;
		}
		viz = d.style.visibility;
		d.style.visibility = 'hidden';
		o = ACCT.dsp(d);
		ACCT.dsp(d,'block');
		r = parseInt(d.offsetHeight);
		ACCT.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 = ACCT.E(d);
	if(ACCT.sh(d)>0){
		v = Math.round(ACCT.sh(d)/d.s);
		v = (v<1) ? 1 :v ;
		v = (ACCT.sh(d)-v);
		d.style.opacity = (v/d.maxh);
		d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
		ACCT.sh(d,v+'px');
	}else{
		ACCT.sh(d,'0px');
		ACCT.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 = ACCT.E(d);
	if(ACCT.sh(d)<d.maxh){
		v = Math.round((d.maxh-ACCT.sh(d))/d.s);
		v = (v<1) ? 1 :v ;
		v = (ACCT.sh(d)+v);
		d.style.opacity = (v/d.maxh);
		d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
		ACCT.sh(d,v+'px');
	}else{
		ACCT.sh(d,d.maxh + 'px');
		clearInterval(d.t);
	}
},

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

//Expand Initializer
ex:function(d){
	if(ACCT.dsp(d)=='none'){
		ACCT.dsp(d,'block');
		d.style.height='0px';
		clearInterval(d.t);
		d.t=setInterval('ACCT.et("'+d.id+'")',ACCT.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 TableAccordian(d,s,tc){
	// get all the elements that have id as content
	tables = document.getElementsByTagName('table');
	
	for(i=0;i<tables.length;i++) {
		tablerows = tables[i].getElementsByTagName('tr');

		c=[];
		// Contentbereiche
		for(j=0;j<tablerows.length;j++){
			h=tablerows[j];
			htd = h.getElementsByTagName('td')[0];
			
			if(h.className == 'maxAkkordeonText') {
				hdiv = document.createElement('div');
				while (htd.hasChildNodes()) { hdiv.appendChild(htd.removeChild(htd.firstChild)); }
				htd.appendChild(hdiv);
				
				hdiv.id = 'akkordeon_' + i.toString() + j.toString() + '-content';
				hdiv.style.display='none';
				hdiv.style.overflow='hidden';
				hdiv.maxh = ACCT.sh(hdiv);
				hdiv.s=(s==undefined)? 7 : s;
				c.push(hdiv.id);
			}
		}
		
		// Headerbereiche
		for(j=0;j<tablerows.length;j++) {
			if (tablerows[j].className == 'maxAkkordeonTitle') {
				h=tablerows[j];
				htd = h.getElementsByTagName('td')[0];
				
				hdiv = document.createElement('div');
				while (htd.hasChildNodes()) { hdiv.appendChild(htd.removeChild(htd.firstChild)); }
				htd.appendChild(hdiv);
				h=hdiv;
				
				h.id = 'akkordeon_' + i.toString() + (j+1).toString() + '-header';
				h.c = c;
				h.tc = tc;
				h.onclick = function(){
						cn=this.id;
						n=cn.substr(0,cn.indexOf('-'));
						if (ACCT.dsp(ACCT.E(n+'-content')) == 'block') {
							ACCT.cl(ACCT.E(n+'-content'));
							ACCT.cc(ACCT.E(n+'-header'),'');
						} else {
							ACCT.ex(ACCT.E(n+'-content'));
							n=ACCT.E(n+'-header');
							ACCT.cc(n,'__');
							n.className=n.className+' '+n.tc;
						}
				}
			}
		}
	}
}


