// Define topic/opinion data referesh handler
// this refeshes the data that is effected by login/logout status
_log_in_out_data_refesh = function () {
  
  // Refresh the data
  Veri.Home.loadContent();

};

_show_main_loading_message = function() { showLoading('homeContent'); };


// Create new Veri.Home Namespace
if (Veri.Home == null || typeof(Veri.Home) != "object") { Veri.Home = new Object(); }

// Begin Definition
Veri.Home = {


    /*
     * load() - Load all teh data    
     * 
     * @param reloadPolls - Should we reload the polls list also?
     */
    load : function(opts, firstRun, refresh, isDefault, changed)
    {
        
        var pageToLoad = opts['_pg'];
        var sortBy     = opts['_vw'];
        var period     = opts['_pd'];
        var pollId     = opts['_pl'];
        var catId      = opts['_ct'];

        // Scroll To Top Smoothly
        scrollToTopSmooth();

        // If the poll change, just update the display of the selected poll
        if (changed['_pl']) {
            Veri.Home.updateSelectedPoll(pollId);
        }
    
        // Category Changed
        if (changed['_ct']) {
            Veri.Home.gotoCategoryTab(catId);
        }

        if (refresh || !firstRun || !isDefault) {

             // Load The Category
             $("#homeContent").fillFromAjax(base_url + '/HomeService/homeContent/'
                                                + '?category=' + ((typeof catId == "undefined")?'-1':catId)
                                                + '&period='   + period
                                                + '&page='     + pageToLoad
                                                + '&sort='     + sortBy
                                                + '&poll='     + pollId,
                                             function() { 
                                                 Veri.Home.enableInteractivity(); 
                                                 Veri.Vote.enableInteractivity();
                                             },
                                             $.SHOW_LOADING_MESSAGE);

              // Track This Topic View With Google
              //pageTracker._trackEvent('Category View', ((typeof catId == "undefined")?'-1':catId), "/page="+pageToLoad+"/sort="+sortBy+"/poll="+pollId+"/period="+period);
              pageTracker._trackPageview("/ajax/category_"+catId+"/page="+pageToLoad+"/sort="+sortBy+"/poll="+pollId+"/period="+period);
         }

    },


    /*
     *  Load Data For New Poll Selection
     */
    loadByPoll : function(pollId){
        if (!isNaN(pollId)){
            HashListener.rebuildHash({'_pg':1,'_pl':pollId});
        }
    },


    /*    
     *  Update the display of the selected poll summary
     */    
    updateSelectedPoll : function(pollId){

        // Reset All the View By Polls To Non-Selected
        $("#viewby_polls").find("a.cat_poll").each(function(intIndex){
            $(this).removeClass("selected");
        });

        // Set Selected
        $("#viewby_poll_"+pollId).addClass("selected");

    },


    /* 
     *  Go To Category Tab Selector
     */
    gotoCategoryTab : function(categoryId){

        if(categoryId == "-1"){
            categoryId = '';
        }
        $(".categoryTab").removeClass("active");
        $("#categoryTab"+categoryId).addClass("active");

    },

    /*  
     *  Enable Mouse Overs
     */
    enableInteractivity : function(){

       // Mouse over for home buttons
       $("#homeButton_learn").mouseover(function(){
          $(this).addClass("over");
       }).mouseout(function(){
          $(this).removeClass("over");
       });
       $("#homeButton_publishers").mouseover(function(){
          $(this).addClass("over");
       }).mouseout(function(){
          $(this).removeClass("over");
       });

    }

}
// End Veri.Home Definition
// Define topic/opinion data referesh handler
// this refeshes the data that is effected by login/logout status
_log_in_out_data_refesh = function () {
    HashListener.refresh();
};
// End Veri.Category Namespace

