//runs after the contact form is sent to see if newsletter sign up occurs
function signUp() {
	var message = '';
	if(mailersignup) {
		jQuery('form .ajax-loader').css('visibility','visible');
		jQuery.ajax({
		  type: "POST",
		  url: "http://printrestaurant.com/blog/wp-content/themes/print/cc_form.php",
		  data: {
		  	adr_1 : 		'',
			adr_2 : 		'',
			adr_3 : 		'',
			city : 			'',
			country	: 		'',
			email_address :	maileremail,
			first_name : 	'',
			home_num : 		'',
			last_name : 	'',
			lists :	    [ 'http://api.constantcontact.com/ws/customers/printrestaurant/lists/14' ],
			middle_name	: 	'',
			postal_code	: 	'',
			state : 		'',
			state_name	: 	'',
			sub_postal	: 	'',
			submit : 		'Add Contact'
		  } 
		}).done(function( msg ) {
			if( msg.indexOf( '<div class="success">' ) > -1 )
		   		message = "Your email has been added to our mailing list.";
		   	else if ( msg.indexOf( '<div class="error">This contact already exists.' ) > -1 )
		   		message = "Your email already exists in our mailing list.";
		   	else if ( msg.indexOf( '400' ) > -1 )
		   		message = "Sorry, your email could not be added to our mailing list at this time.";
		   	else
		   		message = "Sorry, your email could not be added to our mailing list at this time.";
		   	
			text = jQuery('.wpcf7-response-output').html();
			jQuery('.wpcf7-response-output').html( text + "<br/>" + message );
			jQuery('form .ajax-loader').css('visibility','hidden');
		});
	}
}

var submenutimer; var submenu; var mailersignup = false; var maileremail;

jQuery(document).ready( function($) {

	//sub menu slidedown
	$('#access .sub-menu').parent().hover(
	  function () {
	  	clearTimeout(submenutimer);
	  	
		if( $(this).children('.sub-menu:hidden').length )  {
			submenu = $(this).children('.sub-menu:hidden');
	  		submenutimer = setTimeout( function() {
	  			submenu.slideDown();
	  		}, 200 );
	  	}
	  },
	  function () {
	  	clearTimeout(submenutimer);
	    $(this).children('.sub-menu').slideUp('fast');
	  }
	);	
	
	//check join constant contact mailer
	$('#wpcf7-f765-p343-o1 input[type="checkbox"]').prop("checked", true);
	
	//join constant contact mailer
	$('.wpcf7-submit').click( function() {
		mailersignup = Boolean(jQuery('.wpcf7-checkbox :checked').length);
		maileremail = jQuery('input[name="your-email"]').val();
	});	
	
	//make galleries
	$('.gallery a').attr('rel','prettyPhoto[ga]');
				
	//gallery lightbox 
    $("a[rel^='printPhotos'], a[rel^='prettyPhoto'], article a:has(img[class*='wp-image'])").prettyPhoto({
    	show_title: false, /* true/false */
    	social_tools:''
    });
    
    //home page rotator
    if( $('.slides').length ) {
	    $('.slides').cycle({
	        fx:      'fade',
	        //timeout:  0,
	        prev:    '.left',
	        next:    '.right',
	        pause:	 true
	    });
    }

}); 
