Design = function() {
	return {
		init: function() {
			this.currencyEl = Ext.get('top-currency');
			if (this.currencyEl) {
				this.currencyList = Ext.get('currency-list-layer');
				this.currencyEl.addClassOnOver('top-select-hover');
				this.currencyEl.on('click', this.showList, this);
				this.currencyEl.unselectable();
			}
		},
		showList: function(e) {
			this.hideLists();
			var el = Ext.fly(e.getTarget());
			var list, alignEl;
			if (e.getTarget().id == this.currencyEl.id || e.within(this.currencyEl)) {
				list = this.currencyList;
				alignEl = this.currencyEl;
			} else {
				return;
			}
			this.onListShow.defer(1, this);
			list.setStyle('width', '');
			list.setWidth(Math.max(list.getWidth(), alignEl.getWidth()));
			list.alignTo(alignEl, 'tl-bl', [0,-1]);
			list.show();
		},
		onListShow: function() {
			Ext.get(document.body).on('click', this.onDocClick, this);
		},
		hideLists: function() {
			Ext.get(document.body).un('click', this.onDocClick, this);
			if (this.currencyList) this.currencyList.hide();
		},
		onDocClick: function(e) {
			var el = Ext.fly(e.getTarget());
			if (el.findParent('.top-select-list', 5)) return;
			this.hideLists();
		}
	}
}();
Ext.onReady(Design.init, Design);

Frontpage = function() {
	return {
		init: function() {
			this.ct = Ext.get('frontpage-img-carrousel');
			if (!this.ct) {
				return;
			}
			this.activeIndex = 0;
			this.wait();
		},
		wait: function() {
			window.setTimeout(this.next.createDelegate(this), 7*1000);
		},
		next: function() {
			var prev = Ext.get(this.ct.dom.childNodes[this.activeIndex]);
			this.activeIndex++;
			if (this.activeIndex >= this.ct.dom.childNodes.length) {
				this.activeIndex = 0;
			}
			var next = Ext.get(this.ct.dom.childNodes[this.activeIndex]);
			next.setStyle('z-index', 100);
			prev.setStyle('z-index', 101);
			next.show();
			prev.hide({
				duration: 1,
				callback: function() {
					this.wait();
				},
				scope: this
			});
		}
	}
}();
Ext.onReady(Frontpage.init, Frontpage);

