// JavaScript Document 
$(function(){ 
  /* pretty photo start */
    $(document).ready(function(){
      $("a[rel^='prettyPhoto']").prettyPhoto();
    });

  /* pretty photo end */

  $("#cdelivery_date").datepicker();
		   
	$("#fader").innerfade({ speed: 1000, timeout: 4000, type: 'sequence', containerheight: '206px' });   
	
	$('a[rel*=facebox]').facebox({ close_image : 'images/closelabel.gif' });
	
//  setTimeout(function(){
//	  $("h2, h3:not('.newsletter'), h4:not('.stay'), h5, h6").dropShadow({ color: "#5f5233", left: 0, top: 0, blur: 1 });
//  }, 250);
  
  $('#homepage_howto_video').click(function(){
    swfobject.embedSWF("/flash/player_flv_maxi.swf", "homepage_howto_video", "345", "225", "8.0.0", "", {
      flv:'/flv/movie1.flv',
      autoplay: 1, 
      width: 345, 
      height: 225,
      showvolume: 1,
      showtime: 1
    });  
    return false;
  });

	// Navigation - hover effect
		$("#mainNav a span.effect").css("opacity","0");
		// on mouse over
		$("#mainNav a").hover(function () {
			// animate opacity to full
			$(this).find('span.effect').stop().animate({
				opacity: 1
			}, 'slow');
		},
		// on mouse out
		function () {
			// animate opacity to nill
			$(this).find('span.effect').animate({
				opacity: 0
			}, 'slow');
		});
		
	// Homepage Promo - hover effect
		$("#promos a span.effectPromo").css("opacity","0");
		// on mouse over
		$("#promos a").hover(function () {
			// animate opacity to full
			$(this).find('span.effectPromo').stop().animate({
				opacity: 1
			}, 'slow');
		},
		// on mouse out
		function () {
			// animate opacity to nill
			$(this).find('span.effectPromo').animate({
				opacity: 0
			}, 'slow');
		});
    
    // add zebra tables
    $('table tr:even').addClass('even');
		
    /* validating forms */
   $('.validated').validate();
   
   
   // newsletter subscribe form validation
    $("form#frmContact").live('submit', function(){
      
      if ( $( 'input[name=name]', this).val() == 'Your name' || $( 'input[name=name]', this).val() == '' )
      {
        alert( 'Please provide your name in the field provided' );
        $( 'input[name=name]', this).focus();
        return false;
      }
      
      if ( $( 'input[name=email]', this).val() == 'Your email address' || $( 'input[name=email]', this).val() == '' || (!is_valid_email( $( 'input[name=email]', this).val() )))
      {
        alert( 'Please provide your email address in the field provided' );
        $( 'input[name=email]', this).focus();
        return false;
      } 
      
      $.post("/newsletter_subscribe", $("form#frmContact").serialize(), function( html ){
          $("#info div.faceboxForm").html(html);
      });
      
      setTimeout( "$.facebox.close()", 4000); 
      return false;
    
    });

}); 


function is_valid_email( address )
{
 var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
 if( !emailReg.test( address ) )
  return false;
 else
  return true;
}