$(document).ready(function(){
	/* :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
	if (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: "Veuillez entrer votre nom d'utilisateur",
					minlength: "Votre nom d'utilisateur doit comporter au moins 2 caract&egrave;res"
				},
				telephone:  "Veuillez entrer uniquement des chiffres sans espace",
				email: "Veuillez entrer une adresse e-mail valide",
				brochure: "Veuillez s&eacute;lectionner un choix de brochure "
			}
		});
		
		// 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;
		})
	})
}