
// Get the element based on its id.
function $(id)
	{
	return(document.getElementById(id));
	}

// Set or get the current display style of the span.
function dsp(id, v)
	{
	if(v == undefined)
		{
		return(id.style.display);
		}
	else
		{
		id.style.display = v;
		}
	}

// Set or get the height of a span.
function sh(id, v)
	{
	if(v == undefined)
		{
		if(dsp(id) != 'none' && dsp(id) != '')
			{
			return(id.offsetHeight);
			}
		viz = id.style.visibility;
		id.style.visibility = 'hidden';
		o = dsp(id);
		dsp(id, 'block');
		r = parseInt(id.offsetHeight);
		dsp(id, o);
		id.style.visibility = viz;
		return(r);
		}
	else
		{
		id.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 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);
	}
}

//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(id)
	{
	if(dsp(id) == 'block')
		{
		clearInterval(id.t);
		id.t = setInterval('ct("' + id.id + '")', t);
		}
	}

// Expand initializer.
function ex(id)
	{
	if(dsp(id) == 'none')
		{
		dsp(id, 'block');
		id.style.height = '0px';
		clearInterval(id.t);
		id.t = setInterval('et("' + id.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 showhidetext(d, s, tc){
	// get all the elements that have id as content
	l=$(d).getElementsByTagName('span');
	c=[];
	z=[];
	q=0;
	for(i=0;i<l.length;i++){
		h=l[i].id;
		if(h.substr(h.indexOf('-')+1,h.length)=='Text'){c.push(h);z.push(0);}
	}
	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)=='Title'){
			d=$(h.substr(0,h.indexOf('-'))+'-Text');
			d.style.display='none';
			d.style.overflow='hidden';
			d.maxh =sh(d);
			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('-'));
					if((n + '-Title') == this.id)
						{
					  if (z[i] == 0)
					  	{
							ex($(n + '-Text'));
							n = $(n + '-Title');
							cc(n, '__');
							n.className = n.className + ' ' + n.tc;
							z[i] = 1;
							}
						else
							{
							cl($(n + '-Text'));
							cc($(n + '-Title'), '');
							z[i] = 0;
							}
						}
					else
						{
					  if (z[i] == 1)
					  	{
							cl($( n + '-Text'));
							cc($(n + '-Title'), '');
							z[i] = 0;
							}
						}
					}
			}

			if(h.className.match(/selected+/)!=undefined){ sel=h;}
		}
	}
	if(sel!=undefined){sel.onclick();}
}
