/*
 *   Paradise Kids
 *   Author: Joel Lopez
 *   Lightmaker USA
*/

/* = Functions
-------------------------*/
function hideCaption(currSlideElement, nextSlideElement, options, forwardFlag) {
	lm(currSlideElement).children('.caption').animate({
		top: 349
	}, 300);
}
function showCaption(currSlideElement, nextSlideElement, options, forwardFlag) {
	lm(nextSlideElement).children('.caption').animate({
		top: 299
	}, 300);	
}

var lm = jQuery.noConflict();
lm(document).ready(function() {
	
	// Featured Banner Slider
	lm('#featured_images ul').cycle({
			pager: 	'#change_featured ul',
			fx: 'scrollLeft',
			timeout: 5000,
			speed: 1000,
			before: hideCaption,
			after: showCaption
	});
	
	lm('#newsletter').click(function(e) {
		e.preventDefault();
		lm('#newsletter_modal').fadeIn(250, function() {
			lm('.overlay').show();
			lm('.overlay').click(function(e) {
				lm('#newsletter_modal').fadeOut(250);
				lm('.overlay').hide();
			});
		});
		e.stopPropagation();
	});
	
	// Dropdown
	lm('#jump_location').change(function() {
		 window.location.href = lm(this).val();
	});
	lm('#jump_location').sb({ maxHeight: 200 });
	
	// Riders Selector for Forms
	lm("div.rider").click(function() {				
		lm("div.rider").removeClass("active");
		lm(this).addClass("active");							
		lm(this).find("input").prop('checked', true);
	})
	
	//brandNav Resizer 
	var navSize = lm(".brandNav li").size();
	var navTotalSize = navSize * 117;
	
	lm("ul.brandNav").css("width",  " " + navTotalSize + "px" );
	
	
	// Newsletter Modal Signup
	lm('#subForm').submit(function(e) {
		e.preventDefault();
		// Grab form action
		  var formAction = this.action;
		  
		  // Hacking together id for email field
		  // Replace the xxxxx below:
		  // If your form action were http://mysiteaddress.createsend.com/t/r/s/abcde/, then you'd enter "abcde" below
		  var id = "btliry";
		  var emailId = id + "-" + id;
		  
		  /*// Validate email address with regex
		  if (!checkEmail(emailId)) {
			alert("Please enter a valid email address");
			return;
		  }*/
		  
		  // Serialize form values to be submitted with POST
		  var str = lm(this).serialize();
		  
		  // Add form action to end of serialized data
		  // CDATA is used to avoid validation errors
		  //<![CDATA[
		  var serialized = str + "&action=" + formAction;
		  // ]]>
		  
		  // Submit the form via ajax
		  lm.ajax({
			url: "/stage/wp-content/themes/paradisekids/_includes/proxy.php",
			type: "POST",
			data: serialized,
			dataType: 'html',
			success: function(data){
			  // Server-side validation
			  if (data.search(/invalid/i) != -1) {
				alert('The email address you supplied is invalid and needs to be fixed before you can subscribe to this list.');
			  } else {
				lm('#newsletter_modal .newsletterForm').fadeOut(250, function() { 
					lm('#newsletter_modal .thankyou').fadeIn(250);
				});
				//$("#theForm").hide(); // If successfully submitted hides the form
				//$confirmation.slideDown("slow");  // Shows "Thanks for subscribing" div
				//$confirmation.prop('tabIndex', -1);
				//$confirmation.focus(); // For screen reader accessibility
				// Fire off Google Analytics fake pageview
				//var pageTracker = _gat._getTracker("UA-XXXXX-X");
				//pageTracker._trackPageview("/newsletter_signup");
			  }
			}
		  });
	});
	
	

	
	
});
