var ie6 = $.browser.msie && $.browser.version < 7;

$(function() {
  $('input.default').actsAsDefault();
  
  $('#nav').removeClass('classic');
  $('#nav li:not(.selected) a').mouseenter(function() {
    $(this).append('<span></span>');
    $(this).find('span').css('display', 'none').fadeIn(500);
  }).mouseleave(function() {
    $(this).find('span').fadeOut(250, function() {
      $(this).remove();
    });
  });
  
  $('#contact form').submit(function() {
    var formValid = true;
    
    $('div.required input.text, div.required textarea').each(function() {
      if ($(this).hasClass('default') || $.trim($(this).val()).length < 5) {
        $(this).parent().parent().addClass('error');
        formValid = false;
      }
      
      if ($(this).parent().hasClass('email') && !(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/).test($.trim($(this).val()))) {
        $(this).parent().parent().addClass('error');
        formValid = false;
      }
    });
    
    return formValid;
  });
  
  $('#yt-cur').click(function() {
    $(this).replaceWith('<object width="314" height="254"><param name="movie" value="http://www.youtube.com/v/tIsX1-JErIA&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/tIsX1-JErIA&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="314" height="254"></embed></object>');
  });
});

$.fn.actsAsDefault = function() {
  $(this).each(function() {
    var defaultValue = $(this).val();
    $(this).focus(function() {
      if ($(this).val() === defaultValue) {
        $(this).removeClass('default').val('');
      }
    }).blur(function() {
      if ($.trim($(this).val()) === '') {
        $(this).addClass('default').val(defaultValue);
      }
    });
  });
};

$.fn.hover = function() {
  if (ie6) {
    $(this).mouseover(function() {
      $(this).addClass('hover');
    }).mouseout(function() {
      $(this).removeClass('hover');
    });
  }
  
  return $(this);
};