// Holds the Current item that is open
var current, future, oHeight, cHeight, time, animType, items, startingPos, isAnimated;
// Closes all of the List Items then Opens one.
function setListItems(oh,oc,t){
	// Set the number of list items
	items = Number(YAHOO.util.Dom.getElementsByClassName('item', 'li', 'accord').length);
	// Holds the Current item that is open
	current = 0;
	// Holds the Future item that is closed
	future = 0;
	// Open position Height
	if(oh != undefined){
		oHeight = oh;
	}else {
		oHeight = 250;
	}
	// Closed Position Height
	if(oc != undefined){
		cHeight = oc;
	}else {
		cHeight = 40;
	}
	// Time of the Animation
	if(t != undefined){
		time = t;
	}else {
		time = .5;
	}
	// Type of Animation
	animType = YAHOO.util.Easing.easeBothStrong;
	// Starting Position
	startingPos = 1;
	// Is The Animation Running
	isAnimated = false;
	// Loop through and turn off the List Items
	for(i=1;i<=items;i++){
		var c = document.getElementById('i'+i);
		var dl = document.getElementById('i'+i).getElementsByTagName('dl')[0];
		YAHOO.util.Dom.addClass(c,'closed');
		YAHOO.util.Dom.setStyle( dl , 'opacity' , 0 );
	}
	// Set the Start Position
	//startFadeOut();
}
// Opens the first item
function startFadeOut(){
	isAnimated = true;
	future = startingPos;
	futureOpen();
}
// Achor tag function that manges clicks
function openNewItem(i){
	if(isAnimated == false && current != i){
		isAnimated = true;
		future = i;
		currentFadeOut();				
	}
}
// Fade out current item
function currentFadeOut(){
	if(current != 0)
	{
		var c = document.getElementById('i'+current).getElementsByTagName('dl')[0];
		var a = new YAHOO.util.Anim(c, {opacity: { to: 0 }}, time);
		a.onComplete.subscribe( function(){ currentClose(); } );
		a.animate();
	}
	else
	{
		futureOpen();
	}
}
// Close current item
function currentClose(){
	var c = document.getElementById('i'+current);
	var a = new YAHOO.util.Anim(c, {height: { to: cHeight }}, time, animType);
	a.onComplete.subscribe( function(){ YAHOO.util.Dom.removeClass('i'+current,'open'); futureOpen(); } );
	a.animate();
}
// Open next item
function futureOpen(){
	var dl = document.getElementById('i'+future).getElementsByTagName('dl')[0];
	YAHOO.util.Dom.setStyle( dl , 'opacity' , 0 );
	var c = document.getElementById('i'+future);
	var a = new YAHOO.util.Anim(c, {height: { to: oHeight }}, time, animType);
	a.onComplete.subscribe( function(){ futureFadeIn(); } );
	a.animate();
}
// Fade in next item
function futureFadeIn(){
	YAHOO.util.Dom.addClass('i'+future,'open');
	var c = document.getElementById('i'+future).getElementsByTagName('dl')[0];
	var a = new YAHOO.util.Anim(c, {opacity: { to: 1 }}, time);
	a.onComplete.subscribe( function(){ isAnimated = false; current = future; } );
	a.animate();
}