Frontpage = function() {
	return {
		getPressEl: function(id) {
			return Ext.get('frontpage-box-press-'+id); 
		},
		pressLeft: function(id) {
			this.pressMove(id, 1);
		},
		pressRight: function(id) {
			this.pressMove(id, -1);
		},
		pressMove: function(id, factor) {
			if (this.pressAnimating === true) return;
			var el = this.getPressEl(id);
			var delta = (85)*2;
			var distance = delta * factor;
			var left = el.getLeft(true);
			var w = el.getWidth();
			if (left + distance > 0) {
				distance = - w + delta;
			} else if (left + distance <= -w) {
				distance = w - delta;
			}
			this.pressAnimating = true;
			el.move('r', distance, {
	  		callback: function(){
	  			this.pressAnimating = false;
	  		},
	  		scope: this
	  	});
		}
	}
}();

FrontpageImgRotator = function(id) {
	this.el = Ext.get('frontpage-img-rotator-'+id);
	this.dTask = new Ext.util.DelayedTask(this.rotate, this);
	this.delay();
	this.index = 0; 
}
FrontpageImgRotator.prototype = {
	delay: function() {
		this.dTask.delay(5000);
	},
	rotate: function() {
		var c = this.el.dom.childNodes;
		var curEl = Ext.get(c[this.index]);
		this.index++;
		if (this.index > c.length - 1) {
			this.index = 0;
		}
		var nextEl = Ext.get(c[this.index]);
		curEl.hide(true);
		nextEl.show(true);
		this.delay();
	}
}
