References = function() {
	return {
		init: function(length) {
			this.length = length;
			this.first = true;
			this.initEvents();
			this.dTask = new Ext.util.DelayedTask(this.next, this);
			this.activate(0);
			this.first = false;
			var logosCt = Ext.get('reference-logos');
			logosCt.on('mouseover', this.onLogoOver, this);
			this.coloredLogos = [];
		},
		initEvents: function() {
			for (var index = 0; index < this.length; index++) {
				var el = this.getThumb(index);
				el.on('click', this.onClick, this);
			}
		},
		delayDTask: function() {
			this.dTask.delay(10*1000);
		},
		next: function() {
			var index = this.activeIndex*1+1;
			if (index >= this.length) index = 0;
			this.activate(index);
		},
		activateRandom: function() {
			var index = Math.floor(Math.random()*this.length);
			this.activate(index);
		},
		activate: function(index) {
			if (index == this.activeIndex) return;
			if (this.activeIndex != null) {
				this.getLarge(this.activeIndex).hide(true);
				this.getThumb(this.activeIndex).removeClass('references-thumb-active')
			}
			this.activeIndex = index;
			this.getLarge(this.activeIndex).show(!this.first);
			this.getThumb(this.activeIndex).addClass('references-thumb-active')
			this.delayDTask();
		},
		onClick: function(e) {
			var index = this.indexOfEl(e.getTarget());
			this.activate(index);
		},
		indexOfEl: function(el) {
			el = Ext.fly(el);
			var thumbEl = el.findParent('.references-thumb');
			var index = thumbEl.id.replace(/^references-thumb-/, '');
			return index;
		},
		getLarge: function(index) {
			return Ext.get('references-large-'+index);
		},
		getThumb: function(index) {
			return Ext.get('references-thumb-'+index);
		},
		onLogoOver: function(e) {
			var t = Ext.fly(e.getTarget());
			var p = t.findParent('.reference-logos-item');
			if (!p) return;
			if (this.coloredLogos.inArray(p)) return;
			this.coloredLogos.push(p);
			p = Ext.fly(p);
			var grey = p.down('.reference-logo-grey');
			var color = p.down('.reference-logo-color');
			grey.hide(true);
			color.show(true);
		}
	}
}();

