// begin email signup form (this should be turned into a jQuery plugin)
$(document).ready(function(){

  $('#emailform label').hide(); // we'll be doing the labels within the form fields directly

  $('#emailform').submit(function(){
    $('#emailform input[type="text"]').each(fieldlabelfocus); // to unset the field labels for submission

    var fail = false;
    $('#emailform input[type="text"]').each(function(){ // test for empty fields
      if (!$(this).val())
      {
        fail = true;
        $(this).each(fieldlabel); // to re-init the field label
        $(this).css('color', '#FF6666'); // should use classes instead
      }
    });

    return !fail; // return un-fail status to allow/deny the form submit
  });

  function fieldlabel()
  {
    var $this = $(this);
    var thisval = $this.val();
    thisval = thisval.replace(/^\s+/, ''); // strip head spaces
    thisval = thisval.replace(/\s+$/, ''); // strip tail spaces
    thisval = thisval.replace(/\s+/g, ' '); // undouble spaces
    $this.val(thisval);
    if (!$this.val() || $this.val().toLowerCase() == $this.attr('title').toLowerCase())
    {
      $this.val(' ' + $this.attr('title'));
      $this.css('color', '#999999'); // should use classes instead
      $this.css('font-style', 'italic'); // should use classes instead
    }
  }

  function fieldlabelfocus()
  {
    var $this = $(this);
    var thisval = $this.val();
    thisval = thisval.replace(/^\s+/, ''); // strip head spaces
    thisval = thisval.replace(/\s+$/, ''); // strip tail spaces
    thisval = thisval.replace(/\s+/g, ' '); // undouble spaces
    $this.val(thisval);
    if ($this.val().toLowerCase() == $this.attr('title').toLowerCase()) $this.val('');
    $this.css('color', '#000000'); // should use classes instead
    $this.css('font-style', 'normal'); // should use classes instead
  }

  $('#emailform input[type="text"]').each(fieldlabel); // to init the field labels
  $('#emailform input[type="text"]').change(fieldlabel);
  $('#emailform input[type="text"]').blur(fieldlabel);
  $('#emailform input[type="text"]').focus(fieldlabelfocus);

}); // end email signup form

// begin praise box transition
$(document).ready(function(){

  $('#praise .box-content').mgFadeTransitionPrep();

  function doFadeTransition()
  {
    clearTimeout(fadeTransitionInterval);
    fadeTransitionInterval = setTimeout(doFadeTransition, fadeTransitionIntervalDelay);
    $('#praise .box-content').mgFadeTransition(150);
  }
  var fadeTransitionIntervalDelay = 10000;
  var fadeTransitionInterval = setTimeout(doFadeTransition, fadeTransitionIntervalDelay);

}); // end praise box transition

