/*
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

//BRIAN HACK: comento la siguiente funcion porque esta repetida en el modulo de top panel y se cruzan, mientras el top panel este publicado la va a ir a buscar alla.
/*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='block';
	}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
	//v='auto';
	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=10;
t=10;
secondid="";
//Collapse Timer is triggered as a setInterval to reduce the height of the div exponentially.
function ct(d){
	d = $(d);
	if(sh(d)>0){
		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);
		if(secondid!=""){
			dsp(secondid,'none');
			secondid="";
		}
						
	}
}

//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);
		if(secondid!=""){
			$(secondid).style.display='block';
			secondid="";
		}
	}
}

// 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' || d.style.height != 'auto'){
		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,extra){
	s=n.className.split(/\s+/);
	for(p=0;p<s.length;p++){
		if(s[p]==v+n.tc || s[p]==v+n.tc+extra){
			s.splice(p,1);
			n.className=s.join(' ');
			break;
		}
	}
}
//Accordian Initializer
function Accordian(d,s,tc,ind,divid){

	// get all the elements that have id as content
	if(document.getElementById(d)){
		var l = $(d).getElementsByTagName('div');
		//c=[];
		var c = new Array(); 
		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 =sh(d);
				d.maxh ="auto";
				
				d.s=(s==undefined)? 7 : s;
				h=$(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('-'));
						num = (n.substr(n.length - 1,n.length));
						  if(divid){
							
								$(divid + num).style.display='none';

							}
						
						
						
						if((n+'-header')==this.id){
							//alert(cn);
							cont=true;
							if (ind)
							{
								n2=$(n+'-header');
								
								if (n2.className!='tab_headings1 tab_highlight1' && n2.className!='tab_headings2 tab_highlight2' && n2.className!='tab_headings2 selected tab_highlight2' && n2.className!='tab_headings3 tab_highlight3')
								{
								   
									 cont=true;
									
									/* JULIAN
									for (var i2=0;i2<this.c.length;i2++)
								    {
									 //alert(this.c[i2].name)
									 if (i==0)								     
									   {//alert(i);
									     dsp(this.c[1],'none');
										 dsp(this.c[2],'none');
									   }
								     }*/
								}
								else								   
									cont=false;								
								
							}
							
							if (cont)
							{
							
								if (divid)
									{
										secondid=divid + num;
									}

										
								if(this.className.match(tc+num) != undefined){
									cl($(n+'-content'));
									cc($(n+'-header'),'',num);
									//hideDivid()
								}else{
									if(this.className.match(tc) != undefined ){
										cl($(n+'-content'));
										cc($(n+'-header'),'');
									}else{					
										ex($(n+'-content'));
										n=$(n+'-header');
										cc(n,'__');
										if(ind){
											n.className=n.className+' '+n.tc+num;
										}else{
											n.className=n.className+' '+n.tc;
										}
										
								
									}
								}
							}
						}else{
						  
							cl($(n+'-content'));
							if(ind){
								cc($(n+'-header'),'',num);
							}else{
								cc($(n+'-header'),'');
							}
						}
					}
					
				}
				if(h.className.match(/selected+/)!=undefined){ sel=h;}
			}
			
		}
		if(sel!=undefined){sel.onclick();}
	}
}


function showContent(name, cant, child, num){
	var id2 = name + '2';
	var id4 = name + '4';
	var id6 = name + '6';
	var childId = 'test' + child + '-content';
	var inputId = 'child' + child + num;
	var cantAct = document.getElementById(inputId).value;

	var height= parseInt( String(document.getElementById(childId).style.height).substring(0,String(document.getElementById(childId).style.height).length-2));


	if(cant == 2){
		document.getElementById(id4).style.display = 'none';
		document.getElementById(id6).style.display = 'none';
		if(cantAct == 4){
			document.getElementById(childId).style.height = (height - 220)+'px';
		}else{
			if(cantAct == 6){
			document.getElementById(childId).style.height = (height - 340)+'px';
			}
		}
		document.getElementById(inputId).value = 2;
	}else{
		if(cant == 4){
			document.getElementById(id4).style.display = 'block';
			document.getElementById(id6).style.display = 'none';
			if(cantAct == 2){
			document.getElementById(childId).style.height = (height + 220)+'px';
			}else{
				if(cantAct == 6){
				document.getElementById(childId).style.height = (height - 220)+'px';
				}
			}
			document.getElementById(inputId).value = 4;
		}else{
			document.getElementById(id4).style.display = 'block';
			document.getElementById(id6).style.display = 'block';
			if(cantAct == 2){
			document.getElementById(childId).style.height = (height + 340)+'px';
			}else{
				if(cantAct == 4){
				document.getElementById(childId).style.height = (height + 220)+'px';
				}
			}
			document.getElementById(inputId).value = 6;
		}
	}
}
