/*
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

// set or get the current display style of the div
function dsp2(d2,v){
	if(v==undefined){
		return d2.style.display;
	}else{
		d2.style.display=v;
	}
}

// set or get the height of a div.
function sh2(d2,v){
	// if you are getting the height then display must be block to return the absolute height
	if(v==undefined){
		if(dsp2(d2)!='none'&& dsp2(d2)!=''){
			return d2.offsetHeight;
		}
		viz = d2.style.visibility;
		d2.style.visibility = 'hidden';
		o = dsp2(d2);
		dsp2(d2,'block');
		r = parseInt(d2.offsetHeight);
		dsp2(d2,o);
		d2.style.visibility = viz;
		return r;
	}else{
		d2.style.height=v;
	}
}
/*
* Variable 'S' defines the speed of the accordian
* Variable 'T' defines the refresh rate of the accordian
*/
s=7;
t=10;

//Collapse Timer is triggered as a setInterval to reduce the height of the div exponentially.
function ct2(d2){
	d2 = document.getElementById(d2);
	if(sh2(d2)>0){
		v = Math.round(sh2(d2)/d2.s);
		v = (v<1) ? 1 :v ;
		v = (sh2(d2)-v);
		sh2(d2,v+'px');
		d2.style.opacity = (v/d2.maxh);
		d2.style.filter= 'alpha(opacity='+(v*100/d2.maxh)+');';
	}else{
		sh2(d2,0);
		dsp2(d2,'none');
		clearInterval(d2.t);
	}
}

//Expand Timer is triggered as a setInterval to increase the height of the div exponentially.
function et2(d2){
	d2 = document.getElementById(d2);
	if(sh2(d2)<d2.maxh){
		v = Math.round((d2.maxh-sh2(d2))/d2.s);
		v = (v<1) ? 1 :v ;
		v = (sh2(d2)+v);
		sh2(d2,v+'px');
		d2.style.opacity = (v/d2.maxh);
		d2.style.filter= 'alpha(opacity='+(v*100/d2.maxh)+');';
	}else{
		sh2(d2,d2.maxh);
		clearInterval(d2.t);
	}
}

// Collapse Initializer
function cl2(d2){
	if(dsp2(d2)=='block'){
		clearInterval(d2.t);
		d2.t=setInterval('ct2("'+d2.id+'")',t);
	}
}

//Expand Initializer
function ex2(d2){
	if(dsp2(d2)=='none'){
		dsp2(d2,'block');
		d2.style.height='0px';
		clearInterval(d2.t);
		d2.t=setInterval('et2("'+d2.id+'")',t);
	}
}

// Removes Classname from the given div.
function cc2(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;
		}
	}
}

var ant;
var id1;
//Accordian Initializer
function Accordian2(d2,s,tc){
	// get all the elements that have id as content
	l=document.getElementById(d2).getElementsByTagName('div');
	c=[];
	for(i=0;i<l.length;i++){
		h=l[i].id;
		if(h.substr(h.indexOf('-')+1,h.length)=='content2'){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)=='header2'){
			d2=document.getElementById(h.substr(0,h.indexOf('-'))+'-content2');
			d2.style.display='none';
			d2.style.overflow='hidden';
			d2.maxh =sh2(d2);
			d2.s=(s==undefined)? 7 : s;
			h=document.getElementById(h);
			h.tc=tc;
			h.c=c;
			h.open = 0;
			
			//creo un ancla
//			ancla = document.createElement('a');
//			ancla.setAttribute('name','ancla_'+h.id);
//			h.appendChild(ancla);
			
			// 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+'-header2')==this.id){
						if (this.open == 0){
							if (ant != undefined){
								if (ant != this){
									//cierro el anterior
									ant.open = 0;
									cn2=this.c[i];
									n3=cn.substr(0,cn2.indexOf('-'));
									cl2(document.getElementById(n3+'-content2'));
									cc2(document.getElementById(n3+'-header2'),'');
//									alert('2')
								}
								//abro el actual
								this.open = 1;
								ex2(document.getElementById(n+'-content2'));
								n2=document.getElementById(n+'-header2');
								cc2(n2,'__');
								n2.className=n2.className+' '+n2.tc;
							} else {
								this.open = 1;
								ex2(document.getElementById(n+'-content2'));
								n2=document.getElementById(n+'-header2');
								cc2(n2,'__');
								n2.className=n2.className+' '+n2.tc;
//									alert('3')
							}
						} else {
							if (ant == this){
								this.open = 0;
								cl2(document.getElementById(n+'-content2'));
								cc2(document.getElementById(n+'-header2'),'');
//									alert('4')
							} else {
								//cierro el anterior
								ant.open = 0;
								cn2=this.c[i];
								n3=cn.substr(0,cn2.indexOf('-'));
								cl2(document.getElementById(n3+'-content2'));
								cc2(document.getElementById(n3+'-header2'),'');
								//abro el actual
								this.open = 1;
								ex2(document.getElementById(n+'-content2'));
								n2=document.getElementById(n+'-header2');
								cc2(n2,'__');
								n2.className=n2.className+' '+n2.tc;
//									alert('5')
							}
						}
						ant = this;
						id1 = this.id;
						setTimeout("location.href= '#top';",500);
					} else{
						cl2(document.getElementById(n+'-content2'));
						cc2(document.getElementById(n+'-header2'),'');
//						this.open = 0;
					}
//					n2 = document.getElementById(n+'-header2');
//					n2.innerHTML = n2.innerHTML.substr(0,n2.innerHTML.length-1) +  this.open;
				}
			}
			if(h.className.match(/selected+/)!=undefined){ sel=h;}
		}
	}
	if(sel!=undefined){sel.onclick();}
}