function isValidEmailAddress(emailAddress) {
						
var pattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;

return pattern.test(emailAddress);

}

$(document).ready(function(){ 

$('#container').css({'margin': '0px auto'});
// Search Label Replacement 

  var searchLabel = $('#searchForm label').remove().text();
  $('#keyword').addClass('placeholder').val(searchLabel).focus(function() {
  	if (this.value == searchLabel) {
  		$(this).removeClass('placeholder').val('');
  		};
  	
  }).blur(function() {
  	if (this.value == '') {
  		$(this).addClass('placeholder').val(searchLabel)
  	};
  });
  
}); 

////////////////////////////////////////////////////////////////////////////////////////
//START CONTACT FORM
////////////////////////////////////////////////////////////////////////////////////////
$(function() { /*place jQuery actions here*/ 
						//email validation


	$('.error').hide();
	$("#contactForm #contactSubmitButton").click(function() {
								
	// validate code	
	$('.error').hide(); 
	
    var firstName = $("input#firstName").val();
    	if (firstName == "") {  
	      	$("#firstName-error").show();
	      	$("input#firstName").focus();  
	      	return false;  
    	}
    var lastName = $("input#lastName").val();
    	if (lastName == "") {  
	      	$("#lastName-error").show();
	      	$("input#lastName").focus();  
	      	return false;  
    	}
    var email = $("input#email").val();
    	if (email == "") {  
	      	$("#email-error").show();
	      	$("input#email").focus();  
	      	return false;  
    	}
    var phone = $("input#phone").val();
    	if (phone == "") {  
	      	$("#phone-error").show();
	      	$("input#phone").focus();  
	      	return false;  
    	}
    var fax = $("input#fax").val();
    
    var company = $("input#company").val();
    	if (company == "") {  
	      	$("#company-error").show();
	      	$("input#company").focus();  
	      	return false;  
    	}
    var address1 = $("input#address1").val();
    
    var address2 = $("input#address2").val();
    
    var city = $("input#city").val();
    
    var state = $("input#state").val();
    
    var zip = $("input#zip").val();
    
    var comments = $("textarea#comments").val();
		if (comments == "") {  
	      	$("#comments-error").show();
	      	$("input#comments").focus();  
	      	return false;  
    	}
    	
	var dataString = 'firstName=' + firstName + '&lastName=' + lastName + '&company=' + company + '&email=' + email + '&phone=' + phone + '&fax=' + fax + '&address1=' + address1 + '&address2=' + address2 + '&city=' + city + '&state=' + state + '&zip=' + zip + '&comments=' + comments;  
	
	
	// alert (dataString); return false;
	
	$.ajax({
		type: "POST",
		url: "inc/contact-process.php",
		data: dataString,
		success: function()	{
			$('#contactFormBox').fadeOut(1000, function() {
				$('#contactFormBox').replaceWith("<div id='message'></div>");
				$('#message').html("<h3 class='h3'>Information Sent!</h3>")
				.append("<p>Your information has been sent to Jamieson Equipment Company and you will be contacted as soon as possible. If you would like, feel free to contact us directly by phone at any time.</p>")
				.append("<h4 class='h4'>Thank you, " + firstName + "</h4>")
			});
		},
		error: function() {
    			$('#contact-form').append("<h4 class='h4'>There was an error sending your form. Call us at 904.437.7022.</h4>")
    		}
	
	});
	return false;
	
	});

});

////////////////////////////////////////////////////////////////////////////////////////
//END CONTACT FORM
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////
//START REQUEST INFO
////////////////////////////////////////////////////////////////////////////////////////
$(function() {

	$('.error').hide();
	$("#requestForm #requestSubmitButton").click(function() {
								
	// validate code	
	$('.error').hide(); 
	
    var firstName = $("input#firstName").val();
    	if (firstName == "") {  
	      	$("#firstName-error").show();
	      	$("input#firstName").focus();  
	      	return false;  
    	}
    var lastName = $("input#lastName").val();
    	if (lastName == "") {  
	      	$("#lastName-error").show();
	      	$("input#lastName").focus();  
	      	return false;  
    	}
    var email = $("input#email").val();
    	if (email == "") {  
	      	$("#email-error").show();
	      	$("input#email").focus();  
	      	return false;  
    	}
    var phone = $("input#phone").val();
    	if (phone == "") {  
	      	$("#phone-error").show();
	      	$("input#phone").focus();  
	      	return false;  
    	}
    var fax = $("input#fax").val();
    
    var company = $("input#company").val();
    	if (company == "") {  
	      	$("#company-error").show();
	      	$("input#company").focus();  
	      	return false;  
    	}
    var address1 = $("input#address1").val();
    
    var address2 = $("input#address2").val();
    
    var city = $("input#city").val();
    
    var state = $("input#state").val();
    
    var zip = $("input#zip").val();
    
    var comments = $("textarea#comments").val();
		if (comments == "") {  
	      	$("#comments-error").show();
	      	$("input#comments").focus();  
	      	return false;  
    	}
    	
	var dataString = "firstName=" + firstName + "&lastName" + lastName + "&email" + email + "&phone" + phone + "&fax" + fax + "&company" + company + "&address1" + address1 + "&address2" + address2 + "&city" + city + "&state" + state + "&zip" + zip + "&comments" + comments;  
	
	
	// alert (dataString); return false;
	
	$.ajax({
		type: "POST",
		url: "inc/quote-request-process.php",
		data: dataString,
		success: function()	{
			$('#contactFormBox').fadeOut(1000, function() {
				$('#contactFormBox').replaceWith("<div id='message'></div>");
				$('#message').html("<h3 class='h3'>Information Sent!</h3>")
				.append("<p>Your information has been sent to Jamieson Equipment Company and you will be contacted as soon as possible. If you would like, feel free to contact us directly by phone at any time.</p>")
				.append("<h4 class='h4'>Thank you, " + firstName + "</h4>")
			});
		}
	
	});
	return false;
	
	});


 

////////////////////////////////////////////////////////////////////////////////////////
//END REQUEST INFO
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////

}); 



/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch() {
    var $active = $('#slideshow img.active');

    if ( $active.length == 0 ) $active = $('#slideshow img:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow img:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 700, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});

//Megadrop-down
$(document).ready(function() {
	//On Hover Over
function megaHoverOver(){
    $(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
    (function($) {
        //Function to calculate total width of all ul's
        jQuery.fn.calcSubWidth = function() {
            rowWidth = 0;
            //Calculate row
            $(this).find("ul").each(function() { //for each ul...
                rowWidth  += $(this).width(); //Add each ul's width together
            });
        };
    })(jQuery); 

    if ( $(this).find(".row").length > 0 ) { //If row exists...

        var biggestRow = 0;	

        $(this).find(".row").each(function() {	//for each row...
            $(this).calcSubWidth(); //Call function to calculate width of all ul's
            //Find biggest row
            if(rowWidth > biggestRow) {
                biggestRow = rowWidth;
            }
        });

        $(this).find(".sub").css({'width' :biggestRow}); //Set width
        $(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin

    } else { //If row does not exist...

        $(this).calcSubWidth();  //Call function to calculate width of all ul's
        $(this).find(".sub").css({'width' : rowWidth}); //Set Width

    }
}
 
//On Hover Out
function megaHoverOut(){
  $(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
      $(this).hide();  //after fading, hide it
  });
}
var config = {
     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
     interval: 100, // number = milliseconds for onMouseOver polling interval
     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
     timeout: 200, // number = milliseconds delay before onMouseOut
     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
};

$("#nav ul li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
$("#nav ul li").hoverIntent(config); //Trigger Hover intent with custom configurations

});

// Jamieson Lightbox by Fancybox
////////////////////////////////////////////////////////////////////////////////

$(document).ready(function(){
	$(".lightbox").fancybox({
		'overlayShow': true,
		'overlayColor': '#111',
		'titlePosition': 'over',
		//'titleShow': false,
		'overlayOpacity': .8
	});

});

$(document).ready(function(){
	$(".video").click(function() {
		$.fancybox({
			'overlayColor'	: '#111',
			'overlayOpacity': .8,
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'fade',
			'transitionOut'	: 'fade',
			'title'			: this.title,
			'width'			: 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf'
		});
	
		return false;
	});
});

////////////////////////////////////////////////////////////////////////////////
// end Lightbox by Fancybox

