//Fade In Content Viewer: By JavaScript Kit: http://www.javascriptkit.com
var globalFaders=[];
function initFader()
{
	var globalIndex = this._globalIndex;
	var faderheight=$("#"+this._containerId).css('height');
	$("."+this._contentClass).css('height',faderheight)
	$("."+this._contentClass).hover(function(){stopSlide(globalIndex)},function(){startSlide(globalIndex)});
	$("."+this._contentClass).hide();
	$("."+this._contentClass).eq(this._curIndex).fadeIn(this._fadeIn);
	$("#"+this._containerId + " .next" ).bind('click',function(){ moveNext(this,_globalIndex);});
	if (this._autoStart) this._slideTimeout = setTimeout('moveNext('+globalIndex+')',this._slideSpeed);
}

function _moveNext(){
	this._sliding = false;
	clearTimeout(this._slideTimeout);
	this.fadeContent(this._curIndex+1);
}

function moveNext(faderIndex){
	var faderObj = globalFaders[faderIndex];
	faderObj.fadeContent(faderObj._curIndex+1);
}
function stopSlide(faderIndex){
	var faderObj = globalFaders[faderIndex];
	if (faderObj._sliding) {
		clearTimeout(faderObj._slideTimeout);
	}
}

function startSlide(faderIndex){
	var faderObj = globalFaders[faderIndex];
	if (faderObj._sliding) {
		clearTimeout(faderObj._slideTimeout);
		faderObj._slideTimeout = setTimeout('moveNext('+faderIndex+')',faderObj._slideSpeed);
	}
}

function movePrev(faderIndex){
	var faderObj = globalFaders[faderIndex];
	faderObj.fadeContent(faderObj._curIndex-1);
}

	
function fadeContent(showIndex)
{
	if (showIndex > ($("."+this._contentClass).length) -1){
		if (this._circle) showIndex =0 ;
		else return false;
	}
	if (showIndex < 0){
		if (this._circle) showIndex =$("."+this._contentClass).length-1;
		else return false;
	}
	if (showIndex == this._curIndex) return false;
	
	$("."+this._contentClass).eq(this._curIndex).fadeOut(this._fadeOut);
	$("."+this._contentClass).eq(showIndex).fadeIn(this._fadeIn);
	this._curIndex = showIndex;
	if (this._sliding) 	this._slideTimeout = setTimeout('moveNext('+this._globalIndex+')',this._slideSpeed);

}
		

function ContentFader(containerId,contentClass,params)
{
	this._containerId 	= containerId;
	this._contentClass	= contentClass;
	this._curIndex	 	= setDefault(params["startIndex"],0);
	this._autoStart	 	= setDefault(params["autoStart"],false);
	this._circle	 	= setDefault(params["circle"],true);
	this._fadeIn	 	= setDefault(params["fadeIn"],"slow");
	this._fadeOut	 	= setDefault(params["fadeIn"],"slow");
	this._slideSpeed 	= setDefault(params["slideSpeed"],3000);

	this._sliding		= this._autoStart;
	this._slideTimeout	= 0;
	this._globalIndex	= globalFaders.length;
	globalFaders.push(this);
}
ContentFader.prototype.initFader	= initFader;
ContentFader.prototype.fadeContent	= fadeContent;
ContentFader.prototype.movePrev	= movePrev;
ContentFader.prototype._moveNext	= _moveNext;
