/**
 * @author luq <luq_10@o2.pl>
 */
 
var ImageScroll = new Class({
	config: {},
	speed: 2,
	timer: null,
	
	/**
	 * @param hash $config
	 *		.elem DOM elements
	 *		.speed int [optional]
	 */
	initialize: function(config){
		this.config = config;
		if(config.speed){
			this.speed = config.speed;
		}
		
		this.config.elem.addEvent('mouseover', function(){
			if(this.timer){
				return;
			}
			//console.log('mouseover');
			this.scrollerStart();
		}.bind(this));
		
		this.config.elem.addEvent('mouseout', function(e){
			//console.log(e.target);
			this.scrollerStop();
		}.bind(this));
		
		/*
		this.config.elem.getElements('ul').addEvent('mouseout', function(e){
			e.stopPropagation();
		});
		*/
	},
	
	scrollerStart: function(){
		var actScroll = this.config.elem.scrollLeft;
		this.config.elem.scrollLeft += this.speed;
		
		if(this.config.elem.scrollLeft == actScroll){
			var first = this.config.elem.getElement('ul li');
			var width = first.getElement('img').getStyle('width').toInt() - this.speed;
			this.config.elem.getElement('ul').adopt(first.clone());
			first.destroy();
			
			this.config.elem.scrollLeft -= width;
		}
			
		this.timer = setTimeout(function(){
			this.scrollerStart();
		}.bind(this),30);
	},
	
	scrollerStop: function(){
		clearTimeout(this.timer);
		this.timer = null;
	},
});
