$(document).ready(function(){
	

$("a.external").attr("target","_blank");


/* :hover */
	$(function(event) {
	  $("img.hover").hover(function(event) {
			$(this).attr("src", $(this).attr("src").split(".").join("_on."));  // adds -hover to the name of the image
	  }, function(event) {
			$(this).stop(true,false); // prevents the creation of stacked actions
			$(this).attr("src", $(this).attr("src").split("_on.").join("."));  // removes -hover from the name of the image
	  });
	});
	
	/* subContent slide */
	$(".sectionHeader a, .sectionHeader h3, .subToggle").click(function() {
		$(".sectionHolder").slideToggle("slow");
		$(".sectionHeader").toggleClass("active"); return false;
	});
	
	//define smooth scroll
	$("a.smoothScroll").anchorAnimate();
	
	//dimensions table styles
	$("table.dimensions tr").find(":nth-child(1)").addClass("tableMenu");
	$("table.dimensions tr").find(":nth-child(4)").addClass("tableMenu");	
	$("table.dimensions td").parent().parent().children(":nth-child(2)").addClass("tableMenu");
	
	//lightbox
	if (lightBox) {
		$('body a.lightBox').lightBox();
	}
	
	//form validate
	// validate contact form on keyup and submit
		$("#contact").validate({
			rules: {
				name: {
					required: true,
					minlength: 2
				},
				telephone: {
					digits: true
				},
				email: {
					required: true,
					email: true
				},
				brochure: { 
					required: true 
				}
			},
			messages: {
				name: {
					required: "Please enter your name",
					minlength: "Your name must consist of at least 2 characters"
				},
				telephone:  "Please enter only digits no spaces",
				email: "Please enter a valid email address",
				brochure: "Please select a brochure option"
			}
		});
		
		
		//Address Hide
		$(".address").hide();
		
		$("#brochure").change(function() { 
	        var brochure = $("#brochure").val(); 
	        if (brochure == 'yes') {
	        	$(".address").slideDown("slow");
	        } else {
	        	$(".address").slideUp("slow");
	        }
	    }); 
	
		
		//How did you hear about us?
		$(".research_specific").hide();
		
		$("#research").change(function() { 
	        var research = $("#research").val(); 
	        if (research == '') {
	        	$(".research_specific").slideUp("slow");
	        } else {
	        	$(".research_specific").slideDown("slow");
	        }
	    })


});


//smooth scroll function
jQuery.fn.anchorAnimate = function(settings) {

 	settings = jQuery.extend({
		speed : 1100
	}, settings);	
	
	return this.each(function(){
		var caller = this
		$(caller).click(function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = $(caller).attr("href")
			
			var destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
				window.location.hash = elementClick
			});
		  	return false;
		})
	})
}