
/* Home Slideshow */
$(function() {

$(".slidetabs").tabs(".homeimages > div", {
	// enable "cross-fading" effect
	effect: 'fade',
	fadeOutSpeed: "slow",

	// start from the beginning after the last tab
	rotate: true

// use the slideshow plugin. It accepts its own configuration
 }).slideshow({autoplay: true, clickable:false, interval: 3500}); 
 
});



/* Topnav Dropdowns */
$(document).ready(function() {
      
	// Setup the nav drop-downs
	$('#nav').nmcDropDown({
    show: {height: 'show', opacity: 'show'}
	});

});


// NEWSLETTER SIGNUP

  function checkEmail(email) { 
    var pattern = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var emailVal = $("#" + email).val();
    return pattern.test(emailVal);
  }
  $(function() {
    $("#subForm input:image").click(function() { 
      
      // First, disable the form from submitting
      $('form#subForm').submit(function() { return false; });
      
      // Grab form action
      var formAction = $("form#subForm").attr("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 = "http://popgun.createsend.com/t/y/s/uyhhir/";
      var emailId = id + "-" + id;
      
      
      // Serialize form values to be submitted with POST
      var str = $("form#subForm").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
      $.ajax({
        url: "/proxy.php",
        type: "POST",
        data: serialized,
        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
          {
            $("#theForm").hide(); // If successfully submitted hides the form
            $("#confirmation").slideDown("slow");  // Shows "Thanks for subscribing" div
            $("#confirmation").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");
          }
        }
      });
    });
  });
  
// PLACEHOLDERS

	function activatePlaceholders() {
		var detect = navigator.userAgent.toLowerCase(); 
		if (detect.indexOf("safari") > 0) return false;
		var inputs = document.getElementsByTagName("input");
		for (var i=0;i<inputs.length;i++) {
			if (inputs[i].getAttribute("type") == "text") {
				var placeholder = inputs[i].getAttribute("placeholder");
				if (placeholder.length > 0) {
					inputs[i].value = placeholder;
					inputs[i].onclick = function() {
						if (this.value == this.getAttribute("placeholder")) {
							this.value = "";
						}
						return false;
					}
					inputs[i].onblur = function() {
						if (this.value.length < 1) {
							this.value = this.getAttribute("placeholder");
						}
					}
				}
			}
		}
	}
	
	window.onload = function() {
		activatePlaceholders();
	}
	
	


