/**
 * TabController 0.2
 *
 * Created by Flavio Sadeghi, insign gmbh, 2006
 */

tabController = Class.create();
tabController.instances = new Array();
Object.extend(tabController.prototype, {

    initialize: function() {
        this.tabs = new Array();
    },

    init: function(hideIfNoHash) {
	
		if (typeof hideIfNoHash == 'undefined') hideIfNoHash = true;
        
        hashs = document.location.hash.substring(1);
        if(hashs)
        {
            hashs = hashs.toQueryParams();
            if(hashs.maintab)
            {
                this.show(hashs.maintab);
            }
        }
        else
        {
            if (hideIfNoHash) this.hideall();
        }

    },

    selectFirst: function() {
        if(this.tabs[0]){
            this.tabs[0].show();
        }
    },

    add: function (tabObject) {
        if(!this.tabs[this.tabs.length])
        {
            this.tabs[this.tabs.length] = tabObject;
        }
        return this.tabs.length-1;
    },

    show: function (elementid) {
        for(var nc = 0 ; nc < this.tabs.length ; nc++) {
            if(elementid == this.tabs[nc].getId())
            {
                this.tabs[nc].show();
            }
            else
            {
                this.tabs[nc].hide();
            }
        }
    },

    hideall: function () {
        for(var nc = 0 ; nc < this.tabs.length ; nc++) {
            this.tabs[nc].hide();
        }
    },

    remove: function () {
       alert('not implemented yet');
    }

});

tabItem = Class.create();
tabItem.instances = new Array();
Object.extend(tabItem.prototype, {

    initialize: function(elementid, tabid, option) {
        this.elementid = elementid;
        this.tabid = tabid;
        this.styleActive = option.styleActive ? option.styleActive : '';
        this.styleInactive = option.styleInactive ? option.styleInactive : '';
    },

    getId: function() {
        return this.elementid;
    },

    show: function() {
        if(!$(this.elementid)) {
            alert("HTML-Element with id '"+ this.elementid +"' not found.");
            return;
        }
        $(this.elementid).style.display = '';
        $(this.tabid).className = this.styleActive;
    },

    hide: function() {
        if(!$(this.elementid)) {
            alert("HTML-Element with id '"+ this.elementid +"' not found.");
            return;
        }
        $(this.elementid).style.display = 'none';
        if ($(this.tabid)) $(this.tabid).className = this.styleInactive;
    }
})