var SimpleHeroes = Class.create(MorphList, {
	
	initialize: function($super, menu, images, loader, options) {
		
		$super(menu, options);
			
		this.images = $(images);
		this.imagesitems = this.images.childElements();
		this.imagesitems.invoke('hide');
		
		this.loaded = false;
		this.treated = 0;
		
		$(loader).appear();
		
		var pictures = this.images.select('img');
		var count = pictures.length;
		
		pictures.each(function(img) {
			
			var image = new Image();
			
			Event.observe(image, 'load', function() 
			{
				this.treated++;
				
				if(this.treated == count)
				{
					this.loaded = true;
					$(loader).fade();
					if(this.current) this.show(this.menuitems.indexOf(this.current));
				}
				
			}.bindAsEventListener(this));
			
			image.src = img.src;
			
		}.bind(this));
	},
	
	click: function($super, ev, item) {
		$super(ev, item);
		Event.stop(ev);
		this.show(this.menuitems.indexOf(item));
	},
	
	show: function(index) {

		if(!this.loaded) return;
		
		var image = this.imagesitems[index].hide();
		
		if(image == this.curimage) return;

		var p = (this.curimage || this.images.firstDescendant());
		var position = this.curimage ? 'after' : 'before';
		
		$(this.images).insert(image);
		image.appear();
		//p.hide();
		
		this.curimage = image;
		
		return this;
	}
	
});
