// JavaScript Document
// Adaptado a jQuery por: Jose Barragán

(function($) {

	$.fn.Accordian = function(options){
	
		l=getElmt(options.d).getElementsByTagName("div");
		
		a=[];
		for(i=0;i<l.length;i++){
			options.d=l[i];
			if(options.d.id.substr(options.d.id.indexOf("-"),options.d.id.length)=="-content"){
				a.push(options.d)
			}
		}

		x=null;
		for(i=0;i<l.length;i++){
			(function(h){
					  c=h.id.substr(0,h.id.indexOf("-"));
					  if(c+"-header"==h.id){
						  c=getElmt(c+"-content");
						  c.style.display="none";
						  c.style.overflow="hidden";
						  c.h=g(c);
						  c.s=(options.s==undefined)?7:options.s;
						  h.f=options.f;
						  h.c=a;
						  if(h.className.match(new RegExp(options.f+"+"))){
							  x=h
						  }
						  h.onclick=function(){
							  for(j=0;j<this.c.length;j++){
								  n=this.c[j].id;
								  n=n.substr(0,n.indexOf("-"));
								  options.d=getElmt(n+"-header");
								  n=getElmt(n+"-content");
								  s=options.d.className.split(new RegExp("\\s+"));
								  for(p=0;p<s.length;p++){
									  if(options.s[p]==""+options.d.f){
										  options.s.splice(p,1);
										  options.d.className=options.s.join(" ");
										  break
									  }
								  }
								  clearInterval(n.t);
								  if(options.d.id==this.id){
									  if(n.style.display=="none"){
										  g(n,0);
										  
										  //n.t=this.setInterval(PageMethod("e",[n.id]),9)
										  n.t=setInterval('e("'+n.id+'")',9);
									  }
									  options.d.className+=" "+options.d.f
								  } else {
									  if(n.style.display=="block"){
										  n.t=setInterval('b("'+n.id+'")',9);
									  }
								  }
							  }
						   }
						}
					})(l[i])
		}
		if(x!=null){
			x.onclick()
		}
	}
	
})(jQuery);


//Funciones auxiliares
function getElmt(d){
	return document.getElementById(d)
};

function of(d,v){
	g(d,v);
	v=v/d.h;
	d.style.opacity=v;
	d.style.filter="alpha(opacity="+v*100+")"
};

function g (d,v){
	if(v==undefined){
		if(d.style.display!="none"&&d.style.display!=""){
			return d.offsetHeight
		}
		o=d.style.display;
		d.style.display="block";
		v=parseInt(d.offsetHeight);
		d.style.display=o;
		return v
	} else {
		d.style.height=v+"px"
	}
};

function b(d){
	d=getElmt(d);//$(d);
	z=g(d);
	x=d.h;
	if(z>0){
		v=Math.round(z/d.s);
		v=(v<1)?z-1:z-v;
		of(d,v)
	} else {
		g(d,0);
		d.style.display="none";
		clearInterval(d.t)
	}
};

function e(d){
	d=getElmt(d);//$(d);
	z=g(d);
	x=d.h;
	d.style.display="block";
	if(z<x){
		v=Math.round((x-z)/d.s);
		v=(v<1)?z+1:v+z;
		of(d,v)
	} else {
		g(d,x);
		clearInterval(d.t)
	}
};