﻿
jQuery.fn.Tabs = function(config) {

    //参数
    config = jQuery.extend({
        id: null,
        showN: null,
        callback: function() { return false; }

    }, config || {});

    return this.each(function() {

        var me = $(this);

        var tabs = null;
        var subs = null;
        var curt = null;

        init = function() {
            tabs = me.find('li');
            subs = $(".subTab");
            $.each(tabs, function(i, o) { if (config.showN == i) curt = $(o); $(o).click(function() { showTab($(this)); }); });

            showTab(curt);
        };

        showTab = function(w) {

            if (w) {
                tabs.removeClass("tabs-selected");
                w.addClass("tabs-selected");

                $.each(tabs, function(i, o) { if ($(o).hasClass("tabs-selected")) config.showN = i; });

                var sub = $(w.find('a').attr("render"));
                showSub(sub);
            }
            else
                showSub(w);
        };

        showSub = function(w) {
            subs.hide();
            if (w) w.show();
            config.callback(w, config.showN);
        };

        init();
    });
}