$(document).ready(function () {	
	//hover function for navigation dropdown
	$('#menu>#center>ul>li').hover(
		function(){
			$(this).children('ul').show();
		},
		function(){
			$(this).children('ul').hide();
		}
	);
	
	$('#menu>#center>ul>li>ul>li>a').hover(
		function(){
			$(this).parent().css('background-image','url(images/navigation/drop_down_list_background.png)');
		},
		function(){
			$(this).parent().css('background-image','none');
		}
	);


	//hover functionality for the home page square navigation 
	$('#home_square_navigation>li>a').hover(
		
		function(){
			var imgSrc = $(this).children('img').attr('src');
			imgSrc = imgSrc.replace('_bg' , '_bg_over');
			$(this).children('img').attr('src', imgSrc);
		},
		function(){
			var imgSrc = $(this).children('img').attr('src');
			imgSrc = imgSrc.replace('_bg_over','_bg');
			$(this).children('img').attr('src' , imgSrc);
		}
	);
	
	$("#submit_form").click(function() {
		//reset errors
		$('.error').fadeOut(300);
		//Gather information 
		var name = $('input#user_name').val();
		var email = $("input#user_email").val(); 
		var comments = $('textarea#comments').val();
	
		//Validate entries
		if(name == ""){
			$("input#user_name").select().focus();
			$("input#user_name").next('.error').fadeIn(300);
			return false;
		}
		
		var regexMatch = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/
		if(email.search(regexMatch) != 0){
			$("input#user_email").select().focus();
			$("input#user_email").next('.error').fadeIn(300);
			return false;
		};
		
		if(comments == ""){
			$("textarea#comments").select().focus();
			$("textarea#comments").next('.error').fadeIn(300);
			return false;
		}
		
		
			
		var dataString = 'email=' + email +'&name=' + name + '&comments=' + comments;
		
		  $.ajax({
		  type: "POST",
		  url: "bin/relumen_email.php",
		  data: dataString,
		  success: function(){
			    $('#right_content').fadeOut(600,function(){$(this).html('<p style="margin-bottom:374px;">Thank you for your inquiry, your comments/questions have been submitted.</p><p>T  780-435-5739</p><p>F  780-426-2935 </p><p>Suite 200, 10047 - 81 Ave</p><p>Edmonton, Alberta, Canada</p><p>T6E 1W7</p>') }).fadeIn(600);
			  //if its succesfull replace email with the text Email Submitted 
			 
			  
		  
		  }});
		    return false;
	});


}); // End document.ready

