(function($) {
	$.fn.slider = function() {
		var _sp = 0;
		var timerID = slideTimer(this);
		var _ts = this;
		var _mo = false;
		var _ivid = -1;
		this.sliding = 0;

		var mouseOut = function() {
			if (!_mo) {
				timerID = slideTimer(_ts);
			}
		}
		function slideTimer(t) {
			return setTimeout(function() {
				t.slide();
			}, 4000);
		}
		;
		this.each(function(index) {
			var _t = $(this);
			_t.css( {
				left : index * 100 + "%"
			})
			_t.bind("mouseover", function() {
				_mo = true;
				clearTimeout(timerID);
			})
			_t.bind("mouseout", function() {
				_mo = false;
				clearTimeout(_ivid);
				_ivid = setTimeout(mouseOut, 100);
			})
		});
		this.doSlide = function() {
			clearTimeout(_ivid);
			clearTimeout(timerID);
			if (this.sliding == 0) {
				this.slide();
			} else
				_ts.sliding++;
		}
		this.checkState = function() {
			_ts.sliding--;
			if (_ts.sliding == 0) {
				timerID = slideTimer(_ts);
			} else {
				_ts.sliding--;
				_ts.slide();
			}
		}
		this.slide = function() {
			this.sliding++;
			if (_sp == this.length - 1) {
				var _t = $(this[_sp].parentNode);
				_t.animate( {
					left : (parseInt(_t.css("left")) + (100 * _sp) + "%")
				}, 750, this.checkState);
				_sp = 0;
			} else {
				var _t = $(this[_sp].parentNode);
				_t.animate( {
					left : (parseInt(_t.css("left")) - 100 + "%")
				}, 1000, this.checkState);
				_sp++;
			}
		};

		return this;
	};
})(jQuery);
