/* Author: 
	Enguin Design
	enguindesign.com
*/

/* General */
if (!Modernizr.input.placeholder) {
$('[placeholder]').focus(function() {
	  var input = $(this);
	  if (input.val() == input.attr('placeholder')) {
	    input.val('');
	    input.removeClass('placeholder');
	  }
	}).blur(function() {
	  var input = $(this);
	  if (input.val() == '' || input.val() == input.attr('placeholder')) {
	    input.addClass('placeholder');
	    input.val(input.attr('placeholder'));
	  }
	}).blur().parents('form').submit(function() {
	  $(this).find('[placeholder]').each(function() {
	    var input = $(this);
	    if (input.val() == input.attr('placeholder')) {
	      input.val('');
	    }
	  })
	});
}
$( ".plant-content, body#availability_page section[role=main] > div" ).tabs({ fx: { opacity: 'toggle' } });

	// Add tasty AJAX to the Contact form //
	$('#contact').attr('action','/contact/ajax/');

	var options = {   
	    success:  processXml,
	    dataType: 'xml',
	    beforeSubmit:  makeitso
    };

	$('#contact').ajaxForm(options);

	function makeitso(){
	    $('#contact > input[type="submit"]').attr('value','Sending.');
	    $('#contact label em').remove();
	};
	function processXml(responseXML) { 
	    var message = $('message', responseXML).text();
	    var subject = $('subject',responseXML).text();
	    var name = $('name', responseXML).text();
	    var email = $('email', responseXML).text();

	    if (message == 'success') {
	        $('#contact').resetForm();
	        apprise('Awesome, you will be hearing from us within the next few days.',{'animate':true,'textOk':'Yeah!'});
		    $('#contact > input[type="submit"]').attr('value','Sent!');
	    }

	    else {
	    	// If the result is an error show the form again and append appropriate fields //
	    	if (name == 'missing') { $('#contact label[for=contact-name]').append(' <em class="error">This field is required.</em>'); }
	    	if (name == '') { $('#contact label[for=contact-name]').append(' <em class="valid">Nice to meet you!</em>'); }
	    	if (email == 'missing') { $('#contact label[for=contact-email]').append(' <em class="error">This field is required.</em>'); }
	    	if (email == '') { $('#contact label[for=contact-email]').append(' <em class="valid">Looks good.</em>'); }
	    	if (email == 'invalid') { $('#contact label[for=contact-email]').append(' <em class="error">This email address looks funky. (Is it correct?)</em>'); }
	    	if (message == 'missing') { $('#contact label[for=contact-message]').append(' <em class="error">This field is required.</em>'); }
	    	if (message == '') { $('#contact label[for=contact-message]').append(' <em class="valid">We can\'t wait to read this.</em>'); }
	    	$('#contact label em').delay(1000).hide().fadeIn(1500);
	    	$('#contact > input[type="submit"],').attr('value','Send your message.');

	    	apprise('<p>Uh oh, we had a problem sending your message, please check it for errors.</p> <p>(If you continue to have issues sending your message, email us at <a href="mailto:info@northernpacificfarm.com">info@northernpacificfarm.com</a>.)</p>',{'animate':true,'textOk':'Darn.'});
	    };
	};



/* Small Screens */
if (document.documentElement.clientWidth < 768) {
	$('body > header nav').append('<select><option value="'+document.documentURI+'">Home</option></select>');
	$("header nav ul").each(function() {
		$('body > header nav li a').each(function() {
			if ($(this).parent().is("mark")) {
				$("header nav select").append('<option selected value="'+$(this).attr("href")+'">'+$(this).text()+"</option>");
			}
			else {
				$("header nav select").append('<option value="'+$(this).attr("href")+'">'+$(this).text()+"</option>");
			}
		});});	

	$('body > header nav select').change(function() {
		  window.location = $(this).val();
	});

	$("body > header nav ul, div.image, body > footer div[role=contentinfo], body > footer .social, body > footer .ascfg, body > footer .background-image").remove();
}
	
/* Anything larger than small screens */ 
if (document.documentElement.clientWidth > 767) {
$( "body#home_page section[role=main]").tabs({ fx: { opacity: 'toggle',duration:750 } }).tabs("rotate", 8000);
};

