$(document).ready(function() {
  /*$('#ad a').css('opacity', 0.1).hover(function() {
    $(this).stop().fadeTo('normal', 0.5);
  }, function() {
    $(this).stop().fadeTo('normal', 0.1);
  });*/
  
  $('#searchform').click(function() {
    $('#search').focus();
  });
  
  $('.site h2 a, .site .thumb a').hover(function() {
    $('.site h2 span').css('color', '#888888');
  }, function() {
    $('.site h2 span').css('color', '#EAEAEA');
  });
  
  $('.controls a').click(function() {
    $('.controls a').css('background-color', 'white');
    $(this).css('background-color', '#EAEAEA');
    
    $('.code-box, .links-box').hide();
    $('.' + $(this).attr('class') + '-box').show();
    
    return false;
  });
  
  $('.links-box').height($('.code-box').height());
  
  $('.expand').click(function() {
    if(!$('#fullsource').html()) {
      $('body').append('<div id="overlay"></div>').append('<div id="fullsource"><pre><code>' + $('.code-box code').html() + '</code></pre><a href="#close" class="close">close</a></div>');
      
      $('#overlay').css({
        'height'    : $(document).height(),
        'width'     : $(window).width(),
        'opacity'   : 0.8
      });
      
      $('#fullsource pre').css({
        'height'    : $(window).height() - 200,
        'width'     : $(window).width() - 200,
      });
    }
    
    $('#fullsource').css('padding-top', $(document).scrollTop() + 100);
    
    $('#overlay, #fullsource').fadeIn('slow', function() {
      $('.close').click(function() {
        $('#overlay, #fullsource').fadeOut('slow');
        return false;
      });
    });

    return false;
  });
  
  if($('#errorExplanation').text()) {
    $('form p').not('#errorExplanation').each(function() {
      if($(this).text().length < 10) $(this).remove();
    });
    
    $('.fieldWithErrors input:first').focus();
  } else {
    $('#submit_site_title').focus();
  }
});