/*
圖片輪播
2011.03.15
Colin1124x@gmail.com
問題
1.需不需要作圖片載入判斷?
2.圖片說明需不需要作動畫效果?
*/
;(function($){
	if (!$) {return;}
	var options_default = {
		mouse_hover : false,
		speed : 500,
		delay : 3000
	};
	$.fn.extend({
		'slider': function(options){
			options = $.extend({}, options_default, options);
			var main_box = $(this);
			var timer;
			var system = true;
			main_box.children().each(function(){$(this).css('position', 'absolute');});
			if (options.mouse_hover)
			{
				main_box.hover(function(){system = false;}, function(){system = true;});
			}
			function next()
			{
				if (timer) {clearTimeout(timer);}
				timer = setTimeout(fade, options.delay);
			}
			function fade(){
				if (system)
				{
					main_box.children(':last').animate({'opacity':0}, options.speed, function(){
						$(this).insertBefore(main_box.children(':first'));
						$(this).css('opacity', 1);
						next();
					});
				}
				else
				{
					next();
				}
			}
			next();
		}
	});
})(jQuery);
