$(function(){
  // add analytics js
  if (typeof(MONITOR_TRAFFIC) != 'undefined' && MONITOR_TRAFFIC) {
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");

    $('head').append('<script type="text/javascript" src="' + gaJsHost + 'google-analytics.com/ga.js"></script>');
    //document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

    var ga_js_loaded = setInterval(function() {
      if (typeof(_gat) == "undefined") return;
      clearInterval(ga_js_loaded);
      var pageTracker = _gat._getTracker("UA-1146482-1");
      pageTracker._initData();
      pageTracker._trackPageview();
      if (typeof(LOGGED_IN) != 'undefined' && LOGGED_IN)
        pageTracker._setVar("logged in");
    }, 50);
  }

  // draw attention to any flash notices
  $('#notice').fadeIn(6000);

  // login form inputs have text in them by default
  $('input.default').one('focus', function(){
    $(this).addClass('defaulted');
    $(this).val('');
  });

  // highlight the gamer's tags
  if (typeof(tags) != 'undefined') {
    $('a.tag').each(function(){
      if (tags[$(this).html()]) $(this).addClass('shared');
    });
  }

  // click popular tags to add then to textarea
  $('div.suggested_tags ol.tag_list li span.name').click(function(event){
    $('textarea#tag_text').append("\n" + $(this).text() + "\n");
    event.preventDefault();
  });
});
