/*
 * jQuery Slide Show Lite Plugin
 * version: 0.1 (18-FEB-2010)
 * @requires jQuery v1.3.2 or later
 * @author andyhu
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 */
(function($) {                                          // Compliant with jquery.noConflict()
$.fn.slideShowLite = function(o) {
	o = $.extend({
		btnPrev: null,
		btnNext: null,
		btnGo: null,
		auto: null,
		speed: 300,
		start: 0,
		selector: 'li'
	}, o || {});
	return this.each(function() {
		var ul = $(this);
		var curr = o.start, total = $("li", ul).size();
		$("li:not(li:eq(" + o.start + "))", ul).hide();
		$(o.btnGo + ":eq(" + o.start + ")").addClass("active");

		if(o.btnPrev) {
			$(o.btnPrev).click(function() {
				if(!$(o.btnPrev).attr("disabled")) {
					$(o.btnPrev).attr("disabled", true);
					return go(curr - 1);
				}
			});
		}

		if(o.btnNext) {
			$(o.btnNext).click(function() {
				if(!$(o.btnNext).attr("disabled")) {
					$(o.btnNext).attr("disabled", true);
					return go(curr + 1);
				}
			});
		}

		if (o.btnGo) {
			$.each($(o.btnGo), function(i, val){
				$(val).click(function(){
					if (!$(o.btnPrev).attr("disabled")) {
						$(o.btnPrev + "," + o.btnNext).attr("disabled", true);
						go(i);
						$(val).blur();
						return false;
					}
				});
			});
		}
		if(o.auto) {
			setInterval(function() {
				if(!$(o.btnPrev).attr("disabled")) {
					$(o.btnPrev + "," + o.btnNext).attr("disabled", true);
					go(curr + 1);
				}
			}, o.auto);
		}

		function go(pos) {
			if(pos >= total) {
				pos = 0;
			}
			else if(pos < 0) {
				pos = total -1;
			}
			$(o.selector+":eq(" + curr + ")", ul).fadeOut(o.speed, function(){
				$(o.selector+":eq(" + pos + ")", ul).fadeIn(o.speed, function(){
					$(o.btnNext + "," + o.btnPrev).removeAttr("disabled");
				});
			});
			curr = pos;
			$(o.btnGo).removeClass("active");
			$(o.btnGo+":eq(" + curr + ")").addClass("active");
	    $('.slider-m-dot a').blur();
		}
	});
};
})(jQuery);