/**
 * @author Nicolas-Zhao
 * email: zhaoxiaodong713@hotmail.com
 * Version 1.0.4 (24-Apr-2009)
 * @requires jQuery v1.2.6 or later
 * (c)Coryright 2009 ZhaoXiaodong
 */
(function($){
	$.fn.slide = function(o){
		o = $.extend({
			btnPrev: null,
			btnNext: null,
			speed: 1000,
			auto: null,
			visible: 5
		}, o ||
		{});
		return this.each(function(){
			var div = $(this), li = $("li", div), img = $("li img", div), itemLength = li.size();
			var curr = 1;
			var bigImage = $(".big-image", div);
			bigImage.css({
				position: "relative",
				"text-decoration": "none"
			});
			/*$("<span class=\"title\"></span>").css({
				display: "block",
				width: (bigImage.outerWidth() - 20) + "px",
				height: "55px",
				padding: "10px",
				"line-height": "25px",
				"text-align": "left",
				"font-size": "18px",
				"font-weight": "bold",
				color: "#fff",
				background: "#000",
				filter: "alpha(opacity=70)",
				opacity: "0.7",
				position: "absolute",
				bottom: "0",
				left: "0",
				"z-index": "999"
			}).text(img.eq(0).attr("title")).hide().appendTo(bigImage);*/
			if (img.eq(0).attr("title") != "") 
				$(".title", ".big-image").show();
			li.find("a").click(function(e){
				e.preventDefault();
				go(curr);
			});
			li.find("a").mouseover(function(){
				curr = $("li a", div).index(this) + 1;
				go(curr);
			});
			if (o.btnPrev) 
				$(o.btnPrev).click(function(e){
					e.preventDefault();
					return go(curr - 1);
				});
			if (o.btnNext) 
				$(o.btnNext).click(function(e){
					e.preventDefault();
					return go(curr + 1);
				});
			if (o.auto) {
				var process;
				var start = function(){
					process = setInterval(function(){
						go(curr + 1);
					}, o.speed);
				};
				var stop = function(){
					clearInterval(process);
				};
				start();
				li.find("a").hover(function(){
					stop();
				}, function(){
					start();
				});
				$(".big-image", div).hover(function(){
					stop();
				}, function(){
					start();
				});
			}
			var go = function(to){
				if (to > itemLength) 
					to = 1;
				if (to < 1) {
					to = itemLength;
					for (var i = 0; i < itemLength - o.visible; i++) {
						li.eq(i).hide();
					}
				}
				curr = to;
				if (to > o.visible) {
					li.eq(to - o.visible - 1).hide();
				}
				li.eq(to - 1).show();
				if (to == 1) 
					li.show();
				$(".current", div).removeClass("current");
				$(li[to - 1]).find("a").addClass("current");
				var image = new Image();
				image.title = $(img[to - 1]).attr("title");
				image.alt = $(img[to - 1]).attr("alt");
				image.src = $(img[to - 1]).attr("src");
				var bigImage = $(".big-image", div);
				$("img", bigImage).remove();
				bigImage.attr("href", $(li[to - 1]).find("a").attr("href")).append(image);
				$(".title", ".big-image").text($(img[to - 1]).attr("title"));
				$(img[to - 1]).attr("title") == ""
					?$(".title", ".big-image").hide()
					:$(".title", ".big-image").show()
			};
		});
	};
})(jQuery);
