var fontsLoaded = 0;

WebFontConfig = {
        google: { families: [ 'Ubuntu', 'Just Another Hand', 'Neuton' ] },
          loading: function() {
            window.setTimeout(function() {
              if (fontsLoaded == 0)
              {
                $('<div class=\"loading-pane\"><img src=\"\\images\\loading.gif\" /><br/>Web fonts are loading - please wait.<br/>I don\'t care <a href=\"javascript:showItems(2);\">show the text now!</a></div>').insertAfter('.top-menu');
              }
            }, 1000);
          },
          active: function() {
            fontsLoaded = 1;
            showItems(1);
          },
          inactive: function() {
            fontsLoaded = 2;
            showItems(0);
          }
      };
      (function() {
        var wf = document.createElement('script');
        wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
            '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
        wf.type = 'text/javascript';
        wf.async = 'true';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(wf, s);
      })();

function showItems(loaded)
{
  var loadMessage = "";
  if (loaded == 1)
  {
    loadMessage = 'Web fonts loaded successfully.';
  }
  else
  {
    if (loaded == 0)
    {
      loadMessage = 'There was a problem loading webfonts.';
    }
    else
    {
      loadMessage = 'You clicked the link!';
    }
  }
  
  $('.loading-pane').html(loadMessage);
  
  if (!$.browser.msie)
  {
    $('.hide').fadeIn('500');
    $('.loading-pane').delay('1000').fadeOut('1000');
  }
  else
  {
    $('.hide').show();
    $('.loading-pane').delay('1000').hide();
  }
  $('<div class=\"select-bar\">&nbsp;</div>').insertAfter('.top-menu');
}

$(document).ready(function() {
  $('#topNavigation li a').hover(
    function() {
      var selectBar = $('.select-bar');
      selectBar.css('top', '38px');
      selectBar.stop(true, true).animate({ 
        left: $(this).offset().left,
        width: $(this).outerWidth()
      }, 200
        );
      selectBar.fadeIn('500');
      //selectBar.css('left', $(this).offset().left + 'px');
      //selectBar.width($(this).outerWidth());
      
    }
  );
  
  if (fontsLoaded != 0)
  {
    showItems(1);
  }
  
});

$(window).resize(function() {
  var selectBar = $('.select-bar');
  selectBar.fadeOut('500');
});

