$(document).ready(function(){
  mostRead.init();
  mostCommented.init();
});

var mostRead = {
  init: function(){
    $("#mostReadNavigation a").live('click', function(ev){
      ev.preventDefault();
      if($(this).hasClass('previous')){
        switch($("#mostReadNavigation span").text()){
          case 'veckan':
            $("#mostReadNavigation span").text('månad');
              mostRead.getList('month');
            break;
          case 'månad':
            $("#mostReadNavigation span").text('veckan');
              mostRead.getList('week');
            break;
          case 'år':
            $("#mostReadNavigation span").text('månad');
              mostRead.getList('month');
            break;
          default:
            $("#mostReadNavigation span").text('månad');
              mostRead.getList('month');
            break;
        }
      } else {
        switch($("#mostReadNavigation span").text()){
          case 'veckan':
            $("#mostReadNavigation span").text('månad');
              mostRead.getList('month');
            break;
          case 'månad':
            $("#mostReadNavigation span").text('veckan');
              mostRead.getList('week');
            break;
          case 'år':
            $("#mostReadNavigation span").text('veckan');
              mostRead.getList('week');
            break;
          default:
            $("#mostReadNavigation span").text('månad');
              mostRead.getList('month');
            break;
        }
      }
    });
  },

  getList: function(type){
    $("#mostRead div.items").hide();
    $("#mostRead_" + type).show();
  }
};

var mostCommented = {
  init: function(){
    $("#hottestRightNowNavigation a").live('click', function(ev){
      ev.preventDefault();
      if($(this).hasClass('previous')){
        switch($("#hottestRightNowNavigation span").text()){
          case 'veckan':
            $("#hottestRightNowNavigation span").text('år');
              mostCommented.getList('year');
            break;
          case 'månad':
            $("#hottestRightNowNavigation span").text('veckan');
              mostCommented.getList('week');
            break;
          case 'år':
            $("#hottestRightNowNavigation span").text('månad');
              mostCommented.getList('month');
            break;
          default:
            $("#hottestRightNowNavigation span").text('år');
              mostCommented.getList('year');
            break;
        }
      } else {
        switch($("#hottestRightNowNavigation span").text()){
          case 'veckan':
            $("#hottestRightNowNavigation span").text('månad');
              mostCommented.getList('month');
            break;
          case 'månad':
            $("#hottestRightNowNavigation span").text('år');
              mostCommented.getList('year');
            break;
          case 'år':
            $("#hottestRightNowNavigation span").text('veckan');
              mostCommented.getList('week');
            break;
          default:
            $("#hottestRightNowNavigation span").text('månad');
              mostCommented.getList('month');
            break;
        }
      }
    });
  },

  getList: function(type){
    $("#hottestRightNow div.items").hide();
    $("#hottestRightNow_" + type).show();
  }
};
