/*
adRotator javascript
*/

function AdRotator(id,time){
	
	/* Attributes */
	this.container = $(id);
	this.divs = container.children('div');
	this.ttimer = null;
	this.ttime = time;
	this.current = null;
	
	this.init = function(){
		
		this.current = $(divs.get(0));
		
		divs.removeClass('active').hide();
		this.current.addClass('active').show();
		
		this.ttimer = setTimeout(this.rotater,this.ttime);
	}
	
	this.rotater = function(){
	
		this.nextad();
	
	}
	
	this.nextad = function(){
		
		clearTimeout(this.ttimer);	// could be called asynchronously
		
		var nextdiv = current.next();
		
		if (nextdiv.size() == 0){
			nextdiv = $(divs.get(0)); // start back at the beginning
		}
		
		current.fadeOut('slow').removeClass('active');
		nextdiv.fadeIn('slow').addClass('active');
		
		this.current = nextdiv;
		this.ttimer = setTimeout(this.rotater, this.ttime);
	
	}
	
	
	this.init();
	return this;

}


