(function($) {
    $.fn.slider = function(options) {
        var opts = $.extend({}, $.fn.slider.defaults, options);
		
		// 由 0 开始
		opts._num = 0;
		var _this = this;
		_this.obj = _this.find('a');
		
		var changImg = function()
		{
			if('undefined' == typeof(opts.images[opts._num]))
			{
				opts._num = 0;
			}
			_this.obj
				.append('<img style="display:none;"  src="' + opts.images[opts._num]['src'] + '" alt="' + opts.images[opts._num]['title'] + '" />')
				.attr({
					href : opts.images[opts._num]['href'],
					title :	opts.images[opts._num]['title'],
					target :　opts.images[opts._num]['target']
				});
			_this.obj.find('img').eq(0)
				.fadeOut(opts.switchSpeed)
				.remove(); 
			_this.obj.find('img').eq(0).fadeIn(opts.switchSpeed);
			opts._num++;
			_this.timeout = setTimeout(function(){
				changImg();
			}, opts.delay);
		}
		changImg();
		
		if('string' == typeof(opts.prevButton))
		{
			opts.prevButton = $(opts.prevButton);
		}
		if(null != opts.prevButton)
		{
			opts.prevButton.click(function(){
				clearTimeout(_this.timeout);
				opts._num = opts._num -2;
				changImg();
			});
		}
		
		if('string' == typeof(opts.nextButton))
		{
			opts.nextButton = $(opts.nextButton);
		}
		if(null != opts.nextButton)
		{
			opts.nextButton.click(function(){
				clearTimeout(_this.timeout);
				changImg();
			});
		}
    };

    $.fn.slider.defaults = {
        images : {},
		delay : 4000,
		switchSpeed: 600,
        prevButton : null,
        nextButton : null
    }
})(jQuery);