var SpringRoll = function(container,config) {
	Ext.apply(this,config);
	
	this.imageList = config.imageList||[];
	
	this.container = Ext.get(container);
	
	var dh = Ext.DomHelper;
	this.container.update('');
	
	this.el = dh.append(this.container,{tag:'div',html:'<a href="#"><img src="sImages/s.gif" alt=""></a>'},true);
	
	if(this.randomStart !== false) {
		this.pos = Math.round(Math.random()*(this.imageList.length-1));
	}
	
	this.render();
}

SpringRoll.prototype = {
	pos : 0,
	time : 5000,

	render : function() {
		if(this.timer) {
			clearTimeout(this.timer);
		}
		
		var img = this.el.child('img');
		var a = this.el.child('a');
		
		img.dom.src = this.imageList[this.pos].img;
		a.dom.href = this.imageList[this.pos].url||'javascript:void()';
		
		this.timer = this.next.defer(this.imageList[this.pos].defer||this.time,this);
	},
	next : function() {
		if(this.pos < this.imageList.length-1) {
			this.pos++;
		} else {
			this.pos = 0;
		}
		this.render();
	},
	previous : function() {
		if(this.pos > 0) {
			this.pos--;
		} else {
			this.pos = this.imageList.length-1;
		}
		this.render();
	}
}

Application = {
	init : function(){
		if(Ext.isIE) {
			var el = Ext.get(document.body);
			el.addClass('frm-ie');
		}
		
		if(Ext.get('SpringRollContainer')) {
			var sr = new SpringRoll('SpringRollContainer',{
				imageList : imageList,
				randomStart : true,
				time : 6000
			});
		}
	}
}

Ext.onReady(Application.init,Application);
