﻿/*  
jQuery 自动切换插件 AutoSwitch  
      
此插件将所有匹配的元素以固定的时间进行切换，实现幻灯片效果  
      
用法：  
1. $(' 选择符 ').autoSwitch();  
2. $(' 选择符 ').autoSwitch({  
speed: 'fast',  
keeptime: 2000  
});  
*/  

(function($) {   
    $.fn.autoSwitch = function(options) {   
        options = jQuery.extend({   
            speed: 'normal', // 切换速度，可选值: slow, normal, fast   
            keeptime: 10000  //每一个的停留时间，毫秒   
        }, options);   
        var _this = this;   
        var _count = _this.length;   
        var _currentIndex = 0;   
        if (_count > 1) {   
            _this.hide();   
            _this.eq(0).show();   
            window.setInterval(function() {   
                _currentIndex = ++_currentIndex % _count;   
                _this.filter(':visible').hide();   
                _this.eq(_currentIndex).fadeIn(options.speed);   
            }, options.keeptime);   
        }   
        return this;   
    }   
})(jQuery);

