(function ($) {
    var methods = {
        init: function (options) {
            var settings = {
                speed: 1000,
                tabHeight: 81,
                tabWidth: 62,
                tabSpacing: 20
            };
            return this.each(function () {
                if (options) {
                    $.extend(settings, options);
                }

                var variables = {
                    self: $(this)
                };
                methods.generateTabs(settings, variables);
                variables.self.addClass("tabified");
            });
        },
        generateTabs: function (settings, variables) {
            variables.self.find(">li").each(function () {
                var tab = $("<div class='tab'>");
                tab.click(function () {
                    var opened = variables.tabs.filter(".opened");
                    opened.parent().stop().animate({
                        left: -317
                    }, settings.speed, function () {
                        opened.removeClass("opened");
                    });
                    if (!$(this).hasClass("opened")) {
                        $(this).addClass("opened");
                        $(this).parent().animate({
                            left: 0
                        }, settings.speed);
                    }
                });
                if ($(this).attr("id") == "facebook") {
                    var faces = $('<iframe src="http://www.facebook.com/plugins/likebox.php?href=http://www.facebook.com/pages/Live-Inspired/187228094646818?colorscheme=light&amp;show_faces=true&amp;border_color&amp;stream=false&amp;header=false&amp;height=251" scrolling="no" frameborder="0"  allowTransparency="true"></iframe>');
                    $(this).append(faces);
                }
                $(this).append(tab);
            });
            variables.tabs = variables.self.find("div.tab");
            methods.positionTabs(settings, variables);
        },
        positionTabs: function (settings, variables) {
            var increment = settings.tabHeight + settings.tabSpacing;
            var offset = 0;
            var index = variables.tabs.length;
            variables.self.find(">li").each(function () {
                $(this).css({
                    top: offset,
                    "z-index": index
                });
                offset += increment;
                index--;
            });
        }
    };

    $.fn.tabify = function (method) {
        var variables;
        if (typeof method === 'object' || !method) {
            return methods.init.apply(this, arguments);
        } else {
            $.error('Method ' + method + ' does not exist on jQuery.tooltip');
        }
    }
})(jQuery);
