new Namespace("eu.mckinley.products.tab");
eu.mckinley.products.tab = Class.create({

    initialize : function (elems) {
        this.tabentries = elems;
        this.tablayer = new Array();
        this.actual = 0;

        if (this.tabentries.length == 1) {
            return;
        }

        for (var i = 0; i < this.tabentries.length; i++) {

            myi = (this.tabentries[i].id.replace("tabbox_", ""));

            this.tablayer[i] = $('tab_' + myi);
            this.tabentries[i].observe('click', this.click.bind(this, this.tablayer[i]));
            this.tabentries[i].tabindex = myi;
            /**
             * Set Active Layer
             */
            try {
                var tabentry = this.tabentries[i];
                var link = tabentry.firstChild.href;
                var anker = link.split('#')[1];
                var activehash = document.location.hash.split('#')[1];

                if (anker == activehash) {
                    this.click(this.tablayer[i]);
                }
            }
            catch (e) {
            }

        }
        if (typeof(producttabactive) != "undefined") {
            this.actual = producttabactive;
            this.clickid(producttabactive);
        }
    },
    click : function (el) {
        try {

            for (var i = 0; i < this.tablayer.length; i++) {

                this.tablayer[i].removeClassName("active");
                this.tabentries[i].removeClassName("active");
            }
            i = (el.id.replace("tab_", ""));

            $('tab_' + i).addClassName("active");
            $('tabbox_' + i).addClassName("active");
            return false;
        }
        catch (e) {
        }
    },
    clickid : function (y) {
        try {
            for (var i = 0; i < this.tablayer.length; i++) {
                this.tablayer[i].removeClassName("active");
                this.tabentries[i].removeClassName("active");
            }
            $('tab_' + y).addClassName("active");
            $('tabbox_' + y).addClassName("active");
            return false;
        }
        catch (e) {
        }
    }
});

