$.fn.tabs = function(index) {
    if(typeof(index) == 'undefined') index = 1;
    $(this).showTab(index);
    tabset = $(this);
    var tabs_selector = "#" + $(this).attr('id');
    $(".tab_bar .tab", this).click(function() {
        $(this).siblings().removeClass("active");
        $(this).addClass("active");
        var tab_id_parts = $(this).attr('id').split('_');
        tab_id_parts.shift();
        var content_selector = "#tab_content_" + tab_id_parts.join('_');
        $(tabs_selector + " .tab_contents .tab_content").hide();
        $(content_selector).show();
    });
    
    $(".tab_next_link").click(function() {
        index = $(this).attr('href').substr(-1)
        tabset.showTab(index);
    });
    
    hash = unescape(self.document.location.hash.substring(1));
    if(hash != '') {
        index = hash.substr(-1)
        tabset.showTab(index);
    }
}

$.fn.showTab = function(index) {
    $(".tab_bar .tab", this).removeClass("active");
    $(".tab_contents .tab_content", this).hide();
    $(".tab_bar .tab:nth-child("+index+")", this).addClass("active");
    $(".tab_contents .tab_content:nth-child("+index+")", this).show();
}
