var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-16965938-2']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();


$(document).ready(function() { 
  $.post('/musicati/public/index', {referrer: document.referrer, location: document.location.href});

  $("#login_container label").inFieldLabels();

  $('#main_nav li').append('<div class="hover"></div>').each(function () {
    $('#main_nav li').hover(
      //Mouseover, fadeIn the hidden hover class
      function() {
        $(this).children('div').fadeIn('500');
      },
      //Mouseout, fadeOut the hover class
      function() {
        $(this).children('div').fadeOut('500');
      }
    );
  });
  
  $('#sub_nav li').append('<div class="hover"></div>').each(function () {
    $('#sub_nav li').hover(
      //Mouseover, fadeIn the hidden hover class
      function() {
        $(this).children('div').fadeIn('500');
      },
      //Mouseout, fadeOut the hover class
      function() {
        $(this).children('div').fadeOut('500');
      }
    )
  });

  var url = document.location.href
  var abs_protocol = (/\.net/.test(url)) ? 'https' : (/localhost/.test(url)) ? 'http' : 'https'
  var params = $.url.parse(url)
  
  if (params.params && params.params.hl) {
    $('#login_container').hide();
  }
  
  var prefix = $.url.build({protocol: abs_protocol, host: params.host, port: params.port})
  $("form[action^='/musicati/']").each(function() {
    var action = prefix + $(this).attr('action')
    $(this).attr('action', action)
  })
  $("a[href^='/musicati/']").each(function() {
    var href = prefix + $(this).attr('href')
    $(this).attr('href', href)
  })
});

