general.namespace('SW.Controls');

// class RegionDataTab
(function() {
    var RegionDataTab = SW.Controls.RegionDataTab = function(label, name, isSelected, collection) {
        /// <summary>ctor</summary>
        /// <param name=""></param>
        /// <returns></returns>
        // set up dom elements
        var li = document.createElement("li");
        this.tab = document.createElement("a");
        this.tab.innerHTML = label;
        this.tab.href = "javascript:void(0);";
        li.appendChild(this.tab);
        this.content = document.createElement("div");

        // set props
        this.collection = collection; // needed for hiding other tabs
        this.name = name;

        // config handlers
        YAHOO.util.Event.addListener(this.tab, "click", this.clickHandler, this, true);
        this.onShow = new YAHOO.util.CustomEvent("onShow", this, false, YAHOO.util.CustomEvent.FLAT);
        this.onHide = new YAHOO.util.CustomEvent("onHide", this, false, YAHOO.util.CustomEvent.FLAT);

        // call show/hide in order to set classNames and props
        if (isSelected) this.show();
        else this.hide();

        // add tab and content to collection container elements
        collection.tabList.appendChild(li);
        collection.tabContentContainer.appendChild(this.content);
    };
    RegionDataTab.prototype.constructor = RegionDataTab;

    RegionDataTab.prototype.clickHandler = function(e) {
        YAHOO.util.Event.preventDefault(e);        
        this.collection.select(this.name);
    };

    RegionDataTab.prototype.show = function() {
        this.isSelected = true;
        // show content
        this.content.style.display = "block";
        // select tab
        this.tab.className = "tab active";
        this.onShow.fire();
    };


    RegionDataTab.prototype.hide = function() {
        this.isSelected = false;
        // hide content
        this.content.style.display = "none";
        // deselect tab
        this.tab.className = "tab";
        this.onHide.fire();
    };
})();

