/* 
 * jQuery.fn.SwitchTab
*/
Class(function(e, using, self){
    using("lib/jquery.min.js");

    jQuery.fn.SwitchTab = function(options) {
        var options = $.extend(true, {
            showObj : '.switchtab', //对象
            mouseEvent : "mouseover", //事件名字
            showEffect: "show", //效果 fade(渐隐渐现),slide（窗帘效果）
            currentClass: "on", //索引样式
            active: function(target){
            }
        }, options);
        var $elements = this;
        return this.each(function(i){
            $(this).on(options.mouseEvent, function(e){
                e.preventDefault();
                var showObj = options.showObj;
                var currentClass = options.currentClass;
                var showEffect = options.showEffect;
                var dfd = $.Deferred();
                $elements.removeClass(currentClass);
                $(this).addClass(currentClass);
                // 渐隐渐现
                if(showEffect=="fade"){
                    $(showObj).hide();
                    $(showObj).eq(i).fadeIn(
                        {
                            complete:function(){
                                dfd.resolve();
                            }
                        }
                    );
                    // 窗帘效果
                }else if(showEffect=="slide"){
                    $(showObj).hide();
                    $(showObj).eq(i).slideDown(
                        {

                            complete:function(){
                                dfd.resolve();
                            }
                        }
                    );
                    // 默认
                }else{
                    $(showObj).hide();
                    $(showObj).eq(i).show({
                        duration:0,
                        complete:function(){
                            dfd.resolve();
                        }
                    });
                }
                dfd.done(function(){
                    options.active($(showObj).eq(i))
                })

            })
        });
    }
})


