/**
 * @author Ben.Allen
 */

$(document).ready( function() {
    
    function init(){
        $('caption').addClass('hidden');
        $('.month').addClass("hidden");
        var currentMonth = gup('month');
        
        if (currentMonth === ''){
            currentMonth = $('.currentMonth').text();
        }
         
        showFixtureMonth(currentMonth);
    }
    
    function showFixtureMonth(month){ 
        if ($('#' + month)) {
            $('.month').addClass("hidden");
            $('#' + month).removeClass('hidden');
        }else{
            $('.month').addClass("hidden");
            $('.currentMonth').removeClass('hidden');
        }
        return false;
    }
    
    if ($('#fixturesNav')) {
        init();
    }
    
    $('#fixturesNav li a').click(function(){
        textVal = $(this).text();
        $('#fixturesNav li a').removeClass('selected');
        $(this).addClass('selected');
        showFixtureMonth(textVal);
        return false;
    });
       
   function gup( name ){
      name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
      var regexS = "[\\?&]"+name+"=([^&#]*)";
      var regex = new RegExp( regexS );
      var results = regex.exec( window.location.href );
      if( results == null )
        return "";
      else
        return results[1];
   }
});