var articleTabs = {
        currentContent:null,
        newContent:null,

        init:function(){
            this.newContent = 'ALL';
            this.changeContent();
        },

        changeContent:function(){
            if(this.currentContent != null){
                var oldContent = yuiDom.get(this.currentContent);
                oldContent.style.display = 'none';
                var oldTab = yuiDom.get(this.currentContent + "_tab");
                yuiDom.removeClass(oldTab, "locked");
            }
            var newContent = yuiDom.get(this.newContent);
            newContent.style.display = 'block';
            var newTab = yuiDom.get(this.newContent + "_tab");
            yuiDom.addClass(newTab, "locked");

            this.currentContent = this.newContent;
        },

        initBridge:function(){
            var self = articleTabs;
            self.init();
        }
    };

    function changeContentBridge(newContentId){
        var self = articleTabs;
        self.newContent = newContentId;
        self.changeContent();
    }


    // top ten select box
    var topTenSelect = {
        init:function() {

            var currentTopTenList = 'topTenRecent';

            var menuConfig = [
                { text: "Most Recent", value: "topTenRecent" },
                { text: "Most Watched", value: "topTenWatched" },
                { text: "Most Rated", value: "topTenRated" },
                { text: "Most Viewed", value: "topTenViewed" },
                { text: "Most Commented", value: "topTenCommented" },
            ];

            //Create a Button instance, wrapping the text label in an <EM> tag that will be given a fixed width of 10em.
            var trigger = new YAHOO.widget.Button({
                                            type: "menu",
                                            id:"topTenTrigger",
                                            label: "<em>Most Recent</em>",
                                            menu: menuConfig,
                                            container: "buttoncontainer" });

            // Set click event for the trigger
            trigger.on("appendTo", function () {
                trigger.getMenu().subscribe("click", onMenuClick);
            });

            function onMenuClick(p_sType, p_aArgs) {
                var oMenuItem = p_aArgs[1];
                if (oMenuItem) {
                    trigger.set("label", ("<em>" + oMenuItem.cfg.getProperty("text") + "</em>"));
                    if(currentTopTenList != null){
                        var oldTopTenList = yuiDom.get(currentTopTenList);
                        yuiDom.removeClass(oldTopTenList, 'show');
                    }
                    var newTopTenList = yuiDom.get(oMenuItem.value);
                    yuiDom.addClass(newTopTenList, 'show');
                    currentTopTenList = newTopTenList.id;
                }
            };
        }
    }

yuiEvent.onDOMReady(articleTabs.initBridge);    
yuiEvent.onDOMReady(topTenSelect.init);