$(function() {
  // Fix for Gecko 1.9 in FF3 (doesn't seem to hurt other versions) where the centerline of the page is calculated strangely.
  // Otherwise, "margin: 0 auto" centered elements get shifted right by 1px for odd-width windows.
  var ffRoundingFix = function() {
    if (window.outerWidth && window.outerWidth % 2 == 0) {
      javascript:void(window.outerWidth-=1);
    }
  };
  if (navigator.product == 'Gecko') {
    window.onresize = ffRoundingFix;
  }
  ffRoundingFix();
  
  $('#nav li').hover(
    function() { $(this).addClass('hover'); },
    function() { $(this).removeClass('hover'); }
  );

  var showLangSelect = function() {
    var $this = $(this);

    var speed = 'normal';
    if ($.browser.safari) speed = undefined;
    $this.addClass('active').find('div.item').show(speed);

    $this.find('div.root').click(clearLangSelect);
    $(document).click(clearLangSelect);
    return false;
  };
  
  var clearLangSelect = function() {
    $('#nav li.langSelect div.root').unbind('click', clearLangSelect);
    $(document).unbind('click', clearLangSelect);
    
    var speed = 'normal';
    if ($.browser.safari) speed = undefined;
    $('#nav li.langSelect').removeClass('active').find('div.item').hide(speed);
    return false;
  };
  
  $('#nav li.langSelect').click(showLangSelect);
  $('#nav li.langSelect div.item').click(function() {
    window.location = $(this).attr('rel');
  });
  
  
  /* Contact form: */
  $('.contactForm').submit(function() {
    var success = true;
    $(this).find('input[type=text]').each(function() {
      if ($(this).val() == '') {
        success = false;
        return false;
      }
    });
    if (success) return true;
    $('.contactForm .error').css('visibility', 'visible');    
    return false;
  });
  /*
  $('.contactForm input[type=text]:first').each(function() {
    this.focus();
  });
  */
});

