/*
DezinerFolio.com Simple Accordians.

Author  : G.S.Navin Raj Kumar
Website : http://dezinerfolio.com
*/

// global variables
var accHeaders	= [];		// all accordion headers (for timer)
var accCurrent	= 0;		// current open bar (for timer)
var accStop		= false;	// flag to stop timer
var accTimeoutObj;			// 

/*
* The Variable names have been compressed to achive a higher level of compression.
*/


// Prototype Method to get the element based on ID
// REMOVED TO WORK WITH JQUERY
/*
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=10;

//Collapse Timer is triggered as a setInterval to reduce the height of the div exponentially.
function ct(d){
//	d = $(d);	// FRAMEWORK INDEPENDANT
	d = document.getElementById(d);
	dp = document.getElementById(d + 'p');	// image
	if(sh(d)>0){
		v = Math.round(sh(d)/d.s);
		v = (v<1) ? 1 :v ;
		v = (sh(d)-v);
		sh(d,v+'px');
//		dp.style.opacity = (v/d.maxh);
//		dp.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);	// FRAMEWORK INDEPENDANT
	d = document.getElementById(d);
	dp = document.getElementById(d + 'p');	// image
	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');
//		dp.style.opacity = (v/d.maxh);
//		dp.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;
		}
	}
}

// timer to rotate the accordion
function accTimer() {

	var rotatedOnce = false;

	// restart when end is reached
	if (accCurrent >= accHeaders.length) {
		accCurrent	= 0;
		rotatedOnce	= true;
		return;		// stop at the last ad 2009-02-15
	}

	h = accHeaders[accCurrent];
	accCurrent++;

	// update contents
	updateBar(h);

	if (!rotatedOnce && !accStop)
		accTimeoutObj = setTimeout("accTimer();", 2000);
}

// Updates the contents on mouse over
function updateBar(obj) {

	for(i=0;i<obj.c.length;i++){
		cn=obj.c[i];
		n=cn.substr(0,cn.indexOf('-'));
		if((n+'-header')==obj.id){
//			ex($(n+'-content'));	// FRAMEWORK INDEPENDANT
//			n=$(n+'-header');		// FRAMEWORK INDEPENDANT
			ex(document.getElementById(n+'-content'));
//			n=document.getElementById(n+'-header');
//			cc(n,'__');
//			n.className=n.className+' '+n.tc;
		}else{
//			cl($(n+'-content'));	// FRAMEWORK INDEPENDANT
			cl(document.getElementById(n+'-content'));
//			cc($(n+'-header'),'');
//			$(n+'-header').className = 'accordion_headings';	// reset all classes!
			document.getElementById(n+'-header').className = 'accordion_headings';	// reset all classes!
		}
	}
}

//Accordian Initializer
function Accordian(d,s,tc){
	// get all the elements that have id as content
//	l=$(d).getElementsByTagName('div');	// FRAMEWORK INDEPENDANT
	l = document.getElementById(d).getElementsByTagName('div');
	c=[];	// all contents divs
	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');	// FRAMEWORK INDEPENDANT
			d=document.getElementById(h.substr(0,h.indexOf('-'))+'-content');
			d.style.display='none';							// set from css too to prevent flashing on page load
			d.style.overflow='hidden';
			d.maxh =sh(d);
			d.s=(s==undefined)? 7 : s;
//			h=$(h);	// FRAMEWORK INDEPENDANT
			h=document.getElementById(h);
			h.tc=tc;
			h.c=c;

			// add all header objects to global array
			accHeaders.push(h);

			// set the onclick function for each header.
			h.onmouseover = function(){

				// fix stupid bug
				document.getElementById('basic-accordian').style.backgroundPosition = "0 115px";

				// stop timer on mouse over (header only)
				accStop = true;
				// cancel set timers
				clearTimeout(accTimeoutObj);
				// update contents
				updateBar(this);
			}
//			if(h.className.match(/selected+/)!=undefined){ sel=h;}
		}
	}

//	if(sel!=undefined){sel.onmouseover();}

	// start timer
	accTimer();
}