/*** Front feature animated banner ***/

var anim = false;
var animSmall = false;
var iid = false;

function Anim() {
	this.wrapper = false;
	this.trigger = false;
	this.animating = false;	
	this.activeIndex = 0;
	this.elements = new Array();
	this.origX = 0;
	this.targetX = 0;
	this.shift = 0;
	this.interval = 5000;
}

Anim.prototype.init = function() {
	if( this.elements.length > 0 ){
		this.activeIndex = this.elements.length - 1;
		this.shift = jQuery( this.elements[0] ).outerWidth();
		//alert( "Shift: " + this.shift  + ", length: " + this.elements.length );		
		//this.animate();
	}	
}


Anim.prototype.animate = function(){
	var cai = this.activeIndex;
	var animh = this;
	this.activeIndex++;	
	if( this.activeIndex >= this.elements.length )
		this.activeIndex = 0;

	var activeElement = jQuery( this.elements[this.activeIndex] );
	var inactiveElement = jQuery( this.elements[cai] );
	
	if( inactiveElement.css( "display" ) != "none" ){
		this.animating = true;		
		inactiveElement.fadeOut( "slow", function(){			
			animh.trigger.attr( "href", activeElement.attr( "href" ) );
			animh.trigger.attr( "title", activeElement.attr( "title" ) );			
			activeElement.fadeIn( "slow", function(){
				animh.animating = false;
			});
		});
	}else{
		animh.animating = true;
		animh.trigger.attr( "href", activeElement.attr( "href" ) );
		animh.trigger.attr( "title", activeElement.attr( "title" ) );
		activeElement.fadeIn( "slow", function(){
			animh.animating = false;
		});		
	}	
	
	
	//this.targetX = this.wrapper.position().left - this.shift;
	//alert( this.targetX );
	//jQuery( this.wrapper ).animate( {"left": this.targetX + "px"} );
}

