var J = jQuery.noConflict();

(function(J){
    J.fn.tabs = function(){
        var s = {
            "start": null,
            "return": false,
            "click": null
        };
        for (var i = 0; i < arguments.length; ++i) {
            var n = {}, a = arguments[i];
            switch (typeof a) {
                case "object":
                    J.extend(n, a);
                    break;
                case "number":
                case "string":
                    n.start = a;
                    break;
                case "boolean":
                    n["return"] = a;
                    break;
                case "function":
                    n.click = a;
                    break
            };
            J.extend(s, n)
        }
        var self = this;
        var list = J("a[@href^='#']", this).click(function(){
            if (J("a.selected", self)[0] == this) 
                return s["return"];
            var id = "#" + this.href.split('#')[1];
            var aList = [];
            var idList = [];
            J("a", self).each(function(){
                if (this.href.match(/#/)) {
                    aList[aList.length] = this;
                    idList[idList.length] = "#" + this.href.split('#')[1]
                }
            });
            if (s.click && !s.click(id, idList, self)) 
                return s["return"];
            for (i in aList) 
                J(aList[i]).removeClass("selected");
            for (i in idList) 
                J(idList[i]).hide();
            J(this).addClass("selected");
            J(id).fadeIn();
            return s["return"]
        });
        var test;
        if (typeof s.start == "number" && (test = list.filter(":eq(" + s.start + ")")).length) 
            test.click();
        else 
            if (typeof s.start == "string" && (test = list.filter("[@href='#" + s.start + "']")).length) 
                test.click();
            else 
                if ((test = list.filter(".selected")).length) 
                    test.removeClass("selected").click();
                else 
                    list.filter(":first").click();
        return this
    };
    J(function(){
        J(".tabs").each(function(){
            J(this).tabs()
        })
    })
})(jQuery);