/**
 * hscroll ( http://jquery.andelux.com/hscroll )
 * realiza scroll horizontal
 * 
 * @version	1.0
 *
 * @author	Javier Pérez <javier.perez@andelux.com>
 * 
 */
(function($){
	$.fn.hscroll = function(option){
		// parámetros
		var param = jQuery.extend({
			pixels: 10,
			interval_ms: 1
		}, option);
		
		$(this).each(function() {
			$(this)
			.mouseover(function(){
				var $this = $("span", this);

				if ($this.data("showing") == true) {
					return;
				}
				$this.data("showing", true);
				
				if ($this.data("interval")) {
					clearInterval($this.data("interval"));
					$this.data("interval", null);
					$this.data("hidding", false);
				}

				$this.data("interval", setInterval(function(){
					//console.log($this.width(), $this.get(0).scrollWidth);
					if ($this.width() >= $this.get(0).scrollWidth) {
						clearInterval($this.data("interval"));
						$this.data("interval", null);
						$this.data("showing", false);
					} else {
						$this.css("width", $this.width() + param.pixels);
					}
				}, param.interval_ms));
			})
			.mouseout(function(){
				var $this = $("span", this);

				if ($this.data("hidding") == true) {
					return;
				}
				$this.data("hidding", true);
				
				if ($this.data("interval")) {
					clearInterval($this.data("interval"));
					$this.data("interval", null);
					$this.data("showing", false);
				}
				
				$this.data("interval", setInterval(function(){
					//console.log($this.width(), $this.get(0).scrollWidth);
					if ($this.width() <= 0) {
						clearInterval($this.data("interval"));
						$this.data("interval", null);
						$this.css("width", 0);
						$this.data("hidding", false);
					} else {
						$this.css("width", $this.width() - param.pixels);
					}
				}, param.interval_ms));
			});
		});
		
	};
})(jQuery);
