
var productTabs = {

    body: null,

    moduleHref: null,
    productId: null,

    init: function(moduleHref, productId) {
        this.moduleHref = moduleHref;
        this.productId = productId;

        this.body = $("#product-tabs-body").css("display", "none");
        
        this.initHead();
        this.initTab();
    },


    initHead: function() {

        $("#product-tabs-head a").each(function() {

            $(this).attr("href", "javascript:;;");

            this.onclick = function() {
                productTabs.showTab($(this).attr("product_tab"));
            };
        });
    },


    initTab: function() {
        if (document.location.href.match(/#([a-z]+)/i)) {
            var tab = document.location.href.match(/#([a-z]+)/i);
                tab = tab[1];

            if (tab && tab.length)
                return this.showTab(tab);
        }

        this.body.css("display", "block");
    },


    showTab: function(tab) {

        var self = this;
        var href = this.moduleHref + "/show-product-" + tab + "-tab";
        var product_id = this.productId;

        $("#product-tabs-head a").attr("id", "");
        $("#product-tabs-head a@[product_tab='"+tab+"']").attr("id", "tabs_active");

        $.post(href, {product_id: product_id}, function(data) {
            self.body.html(data).css("display", "block");
            document.location.href = document.location.pathname + "#" + tab;
        });
    }

};

