var ShowCase = new Class({
	
	Implements: Options,
	
	moContainer: null,
	moChildren: null,
	
	options: {
		'loopDelay': 2000,
		'search': 'small',
		'replace': 'normal',
		'activeClass': 'active'
	},
	
	initialize: function(oContainer, options){
		this.moContainer = $(oContainer);
		
		this.setOptions(options);
		this.build();
	},
	
	build: function(){
		this.moChildren = this.moContainer.getChildren('a');
		if (this.moChildren.length === 0){
			return;
		}
		
		this.moCurrent = this.moContainer.getElement('div');
		if ($type(this.moCurrent) === false){
			return;
		}
		
		this.moChildren.each((function(oA){
			oA.addEvent('mouseenter', (function(oEvent){
				this.setBig($(oEvent.target));
				this.stopLoop();
			}).bind(this)).addEvent('mouseleave', (function(oEvent){
				this.startLoop();
			}).bind(this));
		}).bind(this));
		
		// init showcase
		this.nextItem();
		this.startLoop();
	},
	
	setBig: function(oEl){
		try {
			this.moCurrent.getElement('span').set('text', oEl.get('text'));
		} catch (oEx){}
		
		try {
			this.moCurrent.setStyle('background-image', oEl.getStyle('background-image'));
		} catch (oEx){}
		
		if (arguments.length > 1 && arguments[1] === true){
			// remove highlighting from others
			this.moContainer.getChildren('a.' + this.options.activeClass).each((function(oEl){
				oEl.removeClass(this.options.activeClass);
			}).bind(this));
			oEl.addClass(this.options.activeClass);
		}
	},
	
	startLoop: function(){
		this.oLoopEvent = this.nextItem.periodical(this.options.loopDelay, this);
	},
	
	stopLoop: function(){
		$clear(this.oLoopEvent);
	},
	
	nextItem: function(){
		if ($type(this.miItemCounter) === false || this.miItemCounter === this.moChildren.length){
			this.miItemCounter = 0;
		}
		
		var o_cur_item = this.moChildren[this.miItemCounter];
		
		this.setBig(o_cur_item, true);
		this.miItemCounter += 1;
	}
});