var activity ={};

activity.onWindowLoad = function(){ 
    var wtl=document.getElementById('whats_this_link');
    YAHOO.util.Event.on(wtl,'click', activity.showDialog);
    YAHOO.util.Event.on('dlg_whats_this_close','click', activity.hideDialog);

    var dlg=document.getElementById('dlg_whats_this');
    dlg.parentNode.removeChild(dlg);
    document.body.appendChild(dlg);
    wtl.title='';
    if(YAHOO.widget && YAHOO.widget.Overlay){
        activity.wtl_dlg = new YAHOO.widget.Overlay('dlg_whats_this', { 
            fixedcenter:true, 
            constraintoviewport:false,
            context:wtl,
            visible:false, 
            width:"300px" 
        });
        activity.wtl_dlg.render();
    }

    activity.do_activity_switch();
}

activity.do_activity_switch = function() {
    container = document.getElementById('activity_switch');

    if(!container){
        return;
    }
    links = container.getElementsByTagName('a');
    for(i=0;i<links.length;i++){
        YAHOO.util.Event.on(links[i], 'click', activity.switch_click, links);
    }
}

activity.showDialog = function(e){
    activity.wtl_dlg.show();
    activity.dialog_open = true;
    YAHOO.util.Event.stopEvent(e);
    return false;
}
activity.hideDialog = function(e){
    activity.wtl_dlg.hide();
}
activity.switch_click = function(evt, links){
    this.blur();
    showClass = this.show_class || this.getAttribute('show_class');
    for(i=0;i<links.length;i++){
        link = links[i];
        if(link == this){
            link.className = 'selected';
        } else {
            link.className = '';
        }
    }
    YAHOO.util.Dom.getElementsByClassName('count', 'span', 'activities', function(item){
            if(YAHOO.util.Dom.hasClass(item, showClass)){
                item.style.display = '';
            } else {
                item.style.display = 'none';
            }
    });
    YAHOO.util.Event.preventDefault(evt);
    
}
YAHOO.util.Event.on(window, 'load', activity.onWindowLoad);

