$(document).ready(function() {

    $('#nav ul > li').hover(function() {
        var $this = $(this);
        
        if($this.data('timeout')) {
            clearTimeout($this.data('timeout'));
        }
        
        $this.data('timeout', setTimeout(function() {
            $this.find('ul').slideDown(200);
        }, 200));
    }, function() {
        var $this = $(this);

        if($this.data('timeout')) {
            clearTimeout($this.data('timeout'));
        }

        $this.data('timeout', setTimeout(function() {
            $this.find('ul').slideUp(300);
        }, 500));
    });
    
    
    $('#header input[type="text"]').focus(function() {
        if($(this).val() == '') {
            $(this).prev('label').stop().animate({ opacity: 0.4 }, 200);
        }
    }).blur(function() {
        if($(this).val() == '') {
            $(this).prev('label').stop().animate({ opacity: 1 }, 200);
        }
    }).keydown(function() {
        if($(this).css('opacity')) {
            $(this).prev('label').stop().animate({ opacity: 0 }, 200);
        }
    });
    $('#header input[type="text"]').each(function() {
        if($(this).val() != '') {
            $(this).prev('label').stop().animate({ opacity: 0 }, 200);
        }
    });
    
});

$(window).load(function() {
  $('#nav li ul').hide().each(function() {
      // fixes IE6
      var $this = $(this);
      $this.width($this.parent('li').width());
  });
});
