(function ($) {
   $.fn.labelOver = function (options) {

      var settings = $.extend( {}, $.fn.labelOver.settings, options )

      this.each(function () {
         var labels;
         if(settings.addClassName){
            $(this).addClass(settings.className);   
         }
         
         //Accept either labels themselves, or an element containing labels.
         if($(this).is('label')) {
            labels = $(this);
         } else {
            labels = $(this).find('label');
         }
         
         labels.each(function () {

            var $input = settings.inputFinder.apply(this).bind('focus', function () {
               //Hide corresponding label on focus
               labelFor = $(this).attr('id');
               $('label[for='+labelFor+']').hide();               
            }).bind('blur', function () {
               //If field is blank on blur, show label
               if($(this).val() == ""){
                  labelFor = $(this).attr('id');
                  $('label[for='+labelFor+']').show();                  
               }
            });
            //Hide the label by default for any pre-populated fields
            if ($input.val() != "") {
               $(this).hide();
            }
            //Make label look/act like input couterpart
            $(this).css('cursor', 'text').click(function () {
               $(this).hide();
               $input.focus();
            });
            
         });//end - each label
      });//end - each element
      
   }
   $.fn.labelOver.settings = {
      inputFinder: function () {
         var inputId = $(this).attr('for');
         return $('#'+inputId);
      },
      addClassName: true,
      className: "label-over"
   }
})(jQuery)

jQuery(document).ready(function ($) {
   $('#quick-contact').labelOver();
   $('#quick-contact:not(.error) .field:gt(1)').hide();
   $('#quick-contact :input').focus(function () {
      $('#quick-contact').addClass('focused').find('.field').show();
   }).blur(function () {
      setTimeout(function () {
         if(!$('#quick-contact').is('.focused')){
            $('#quick-contact .field:gt(1)').hide();
         }
      }, 1000);
      $('#quick-contact').removeClass('focused');
   });
   // $('#quick-contact :input').focus(function () {
      // $('#quick-contact').addClass('focused');
      // $(this).addClass('focused');
   // }).blur(function () {
      // $('#quick-contact').removeClass('focused');
      // $(this).removeClass('focused');
   // });
   // $('#quick-contact').hover(function () {
   //    $(this).find('.field').show();
   // },function () {
   //    $this = $(this)
   //    if(!$this.is('.focused')) {
   //       $this.find('.field:gt(1)').hide();
   //    }
   // });
});
