(function ($) {
	$.fn.fastSlider = function (options) {
		var slider = this;
		var offsetx = 0;
		var button;
		var slideWidth;
		var maxWidth = slider.width() - slider.parent().width();

		if (typeof options == 'undefined') {
			options = {};
		}

		if (options.prev) {
			var moveLeft = function () {
				button = $(this);
				offsetx = Math.abs(parseInt(slider.css('left')));

				slideWidth = options.slideWidth;
				if (offsetx < slideWidth) {
					slideWidth = offsetx;
				}

				if (offsetx > 0) {
					slider.animate({
						'left' : '+=' + slideWidth + 'px'
					}, {
						'complete' : function () {
							button.one('mousedown', moveLeft);
						}
					});
				} else {
					button.one('mousedown', moveLeft);
				}
				button.blur();
			};
			options.prev.one('mousedown', moveLeft);
		}

		if (options.next) {
			var moveRight = function () {
				button = $(this);
				offsetx = Math.abs(parseInt(slider.css('left')));

				slideWidth = options.slideWidth;
				if (options.slideWidth > (maxWidth - offsetx)) {
					slideWidth = maxWidth - offsetx;
				}

				if (offsetx < maxWidth) {
					slider.animate({
						'left' : '-=' + slideWidth + 'px'
					}, {
						'complete' : function () {
							button.one('mousedown', moveRight);
						}
					});
				} else {
					button.one('mousedown', moveRight);
				}
				button.blur();
			};
			options.next.one('mousedown', moveRight);
		}
	};
})(jQuery);
