/*
 *  $Id: baicff.js,v 1.3 2011/11/02 03:24:20 dmaszle Exp $
 */

/* this is included inline

//----------------------------------------------------------------------
// slideshow: chapter_04/07_slideshow_cross_fade/script.js

$(document).ready(function(){
  rotatePics(1);
});

function rotatePics(currentPhoto) {
  var numberOfPhotos = $('#photos div').length;
  currentPhoto = currentPhoto % numberOfPhotos;
	
  $('#photos div').eq(currentPhoto).fadeOut(function() {
		// re-order the z-index
    $('#photos div').each(function(i) {
      $(this).css(
        'zIndex', ((numberOfPhotos - i) + currentPhoto) % numberOfPhotos
      );
    });
    $(this).show();
    setTimeout(function() {rotatePics(++currentPhoto);}, 8000);
  });
}

*/



//----------------------------------------------------------------------
// email validation: chapter_07/05_validation_plugin/script.js

/*
$(document).ready(function(){
  $('#frmSubscribe').validate({

  rules: {
    email: {
      email: true
    },
  },

  success: function(label) {
    label.text('').addClass('valid');
  }

  });
});
*/


// ----------------------------------------------------------------------
// : chapter_07/07_form_hints/script.js

// get that cute background value

$('input.clear').each(function() {
  $(this)
    .data('default', $(this).val())
    .addClass('inactive')
    .focus(function() {
      $(this).removeClass('inactive');
      if ($(this).val() == $(this).data('default') || '') {
        $(this).val('');
      }
    })
    .blur(function() {
      var default_val = $(this).data('default');
      if ($(this).val() == '') {
        $(this).addClass('inactive');
        $(this).val($(this).data('default'));
      }
    });
});


// ----------------------------------------------------------------------
// validation: chapter_07/01_simple_validation/script.js

$(document).ready(function(){
  $(':submit').click(function(e) {
    $(':text').each(function() {
      if($(this).val().length == 0) {
        $(this).css('border', '2px solid red');
      }
    });
    e.preventDefault();
  });
});

// ----------------------------------------------------------------------
// blur editing: chapter_07/09_inline_editing/script.js

$(document).ready(function(){
  $('.editable, .editable-area')
    .hover(function() {
      $(this).toggleClass('over-inline');
    })

    .click(function(e) {
      // start the inline editing
      var $editable = $(this);
      if($editable.hasClass('active-inline')) {
        return;
      }
      var contents = $.trim($editable.html());
      $editable
        .addClass('active-inline')
        .empty();
      
      // Determine what kind of form element we need
      var editElement = $editable.hasClass('editable') ? 
        '<input type="text" />' : '<textarea></textarea>';

      // Replace the target with the form element
      $(editElement)
        .val(contents)
        .appendTo($editable)
        .focus()
        .blur(function(e) {
          $editable.trigger('blur');
        });
    })
    
.blur(function(e) {
  // end the inline editing
  var $editable = $(this);
  
  var contents = $editable.find(':first-child:input').val();
  $editable.contents().replaceWith('<em class="ajax">Saving ... </em>');
  
  // post the new value to the server along with its ID
  $.post('save',
    {id: $editable.attr('id'), value: contents},
    function(data) {
      $editable
        .removeClass('active-inline')
        .contents()
        .replaceWith(contents);
    });
});
});
/* */


function sendemail() {
    var el = document.getElementById("inSubscribe");
    el.parentNode.submit();
    $('#frmSubscribe:input').css('background-color', 'orange')
    window.alert('Thank you for subscribing to our newsletter! You will receive a confirmation email.');
}
