/*
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.
*/

// Prototype Method to get the element based on ID
function $(d){
	return document.getElementById(d);
}

// 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 'S' defines the speed of the accordian
* Variable 'T' defines the refresh rate of the accordian
*/
s=7;
t=8;
clicked = false;

function linkClicked()
{
 clicked = true;
}

//Collapse Timer is triggered as a setInterval to reduce the height of the div exponentially.
function ct(d){
//alert(d);
	d = $(d);
	if(sh(d)>1){
		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 = $(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'){
		clearInterval(d.t);
		d.t=setInterval('ct("'+d.id+'")',t);
	}
}

//Expand Initializer
function ex(d){
	if(dsp(d)=='none'){
		dsp(d,'block');
		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){
    sel=null;
	// get all the div elements in 'basic-accordion' that have id as content
	l=$(d).getElementsByTagName('div');
	// list of content div ids.
	c=[];
	
	
	for(i=0;i<l.length;i++){
	    // get id of div
		h=l[i].id;
		// if the div is class="...-content add id to c
		if(h.substr(h.indexOf('-')+1,h.length)=='content'){c.push(h);}
	}
	
	//if(l.length > 0)
    //	sel=l[0].id;
	
	//then search through headers
	for(i=0;i<l.length;i++){
		h=l[i].id;
        // if the div is class="...-header add id to d
		if(h.substr(h.indexOf('-')+1,h.length)=='header'){
		    // get the content for the header
			d=$(h.substr(0,h.indexOf('-'))+'-content');
			d.style.display='none';
			d.style.overflow='hidden';
			
			// set max height equal to the height of basic-accordion
			d.maxh =sh(d);
			
			d.s=(s==undefined)? 7 : s;
			
			h=$(h);
			// header class
			h.tc=tc;
			// content div ids
			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 && !clicked){		
	     
						ex($(n+'-content'));
						n=$(n+'-header');
						if(n.className != "accordion_headings header_highlight" && !clicked)
						{
						    cc(n,'__');							  	
						    n.className=n.className+' '+n.tc;
						}
						else if(!clicked)
						{
						    cc(n,'');				
						    cl($(cn.substr(0,cn.indexOf('-'))+'-content'));
						}
					}else if(!clicked){	
						cl($(n+'-content'));
						cc($(n+'-header'),'');
					}
				}
			}
			
			h.initialise = function(){
			    for(i=0;i<this.c.length;i++){
				    cn=this.c[i];					
				    n=cn.substr(0,cn.indexOf('-'));
				    cl($(n+'-content'));
				    cc($(n+'-header'),'');
			    }	
			}
		}
	}
	if(l.length > 0 && sel!=null && sel!=undefined){sel.onclick();}
}