var mooGallery = new Class({
	options: {
		image_list: '',
		image_list_item: '',
		image_description: ''
	},

	initialize: function(image_container, options){
		this.setOptions(options)
    	this.image_container = image_container;
    	this.setEffects();
	},
	
	setEffects: function() {
		var width = 0;
		var cnt = 0;
		var curr_image = $E('img', this.image_container);
		//var description = $(this.options.image_description);
		//var parent = this;
		
		$$('.' + this.options.image_list_item).each(function(el){
			var new_image = $E('img', el);
			var fx = new Fx.Styles(el, {duration: 200, wait:false, transition: Fx.Transitions.Expo});
			var fx_img = new Fx.Styles(curr_image, {duration: 200, wait:false, transition: Fx.Transitions.Expo.easeOut});
			
			if(this.image_container != '') {
				el.addEvent('click', function(){
					var image = new Element('img', {
						'styles' : {
							'visibility' : 'hidden'
						},
						'events' : {
							'load': function(){
								fx_img.start({
									'opacity': 0
								}).chain(function(){
									curr_image.src = image.src;
									//description.setText(new_image.getProperty('opis'));
									this.start({
										'width' : image.width,
										'height' : image.height
									});
								}).chain(function(){
									this.start({
										'opacity': 1
									});
								});
								delete image;
							}
						},
						'src' : 'upl_images/' + new_image.title
					});
				});
			}
			
			el.addEvent('mouseenter', function(){
				fx.start({
					'background-color':'#F67C09'
				});
			});
			el.addEvent('mouseleave', function(){
				fx.start({
					'background-color':'#ffffff'
				});
			});
			
			width = width + el.getSize().size.x + 15;
			if(cnt == 0)
				el.fireEvent('click');
			cnt++;
		}.bind(this));
		
		var scroll = new Scroller(this.options.image_list, {area: 150, velocity: 0.2});
		$(this.options.image_list).addEvent('mouseenter', scroll.start.bind(scroll));
		$(this.options.image_list).addEvent('mouseleave', scroll.stop.bind(scroll));
		
		$(this.options.image_list + '_mask').setStyle('width', width + 15);	
		/*
		$(this.options.image_list).addEvent('mouseenter', function(){
			$(this.options.image_list).setStyle('border-bottom', '1px solid white');
			$(this.options.image_list).setStyle('border-top', '1px solid white');
		}.bind(this));
		$(this.options.image_list).addEvent('mouseleave', function(){
			$(this.options.image_list).setStyle('border-bottom', '1px solid black');
			$(this.options.image_list).setStyle('border-top', '1px solid black');
		}.bind(this));
		*/
	}
});
mooGallery.implement(new Options, new Events);
