function resize_window() {
  var dh = $(document).height();
  var wh = $(window).height();
  if (wh < dh) {
    $('#footer').css('position','static');
  } else {
    $('#footer').css('position','absolute');
  }
  var cw = $('#container').width();
  var mw = Math.ceil($('#header .right').width() + (($(window).width() - cw) / 2));
  $('body.blog #header .right .masthead').width(mw);
  $('#footer').show();
}
$(document).ready(function(){
  $('#footer').hide();
  $(window).resize(resize_window);
  $(window).load(resize_window);
  $('form.validate').validate({
    errorElement: "p",
    errorPlacement: function(error, element) {
      if (element.attr('tabindex') == '-1') return;
      element.val(error.text());
      var focus = function() { 
        $(this).val(''); 
        $(this).unbind('focus',focus); 
      };
      element.bind('focus',focus);
    },
    focusCleanup: false,
    focusInvalid: false,
    onkeyup: false,
    messages: {
     name: "required",
     author: "required",
     message: "required",
     comment: "required",
     email: {
       required: "required",
       email: "invalid email"
     }
   }
  });
  $('form.validate input').click(function() {
    var f = $(this).closest('form');
    var k = f.find('#key');
    if (k.size() < 1) {
      f.append('<input id="key" type="hidden" name="formkey" value="'+f.attr('action')+'" />');
    }
  });
  $('#submit, .blog-teaser, ul.nav li').hover(function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); });

  heightArray = new Array();
  $('#execphp-5 ul').each(function(i) {
    $(this).data('index',i);
    heightArray[i] = $(this).height();
  });
  $('#execphp-5 h1').click(function() {
    $(this).parent().children('ul').css('height', heightArray[$(this).parent().children('ul').data('index')]);
    $(this).parent().children('ul').slideToggle('normal');
    $(this).parent().toggleClass("closed");
  });
});
