$(document).ready(function(){
	$(".rollover-jpg").hover(
		function(){
			if($(this).attr("src").indexOf("_over") == -1) {
				var newSrc = $(this).attr("src").replace(".jpg","_over.jpg#hover");
				$(this).attr("src",newSrc);
			}
		},
		function(){
			if($(this).attr("src").indexOf("_over.jpg#hover") != -1) {
				var oldSrc = $(this).attr("src").replace("_over.jpg#hover",".jpg");
				$(this).attr("src",oldSrc);
			}
		}
	);
});

$(document).ready(function(){
	$(".rollover-gif").hover(
		function(){
			if($(this).attr("src").indexOf("_over") == -1) {
				var newSrc = $(this).attr("src").replace(".gif","_over.gif#hover");
				$(this).attr("src",newSrc);
			}
		},
		function(){
			if($(this).attr("src").indexOf("_over.gif#hover") != -1) {
				var oldSrc = $(this).attr("src").replace("_over.gif#hover",".gif");
				$(this).attr("src",oldSrc);
			}
		}
	);
});


$(document).ready(function(){
	$(".rollover").hover(
		function(){
			if($(this).attr("src").indexOf("_over") == -1) {
				var newSrc = $(this).attr("src").replace(".png","_over.png#hover");
				$(this).attr("src",newSrc);
			}
		},
		function(){
			if($(this).attr("src").indexOf("_over.png#hover") != -1) {
				var oldSrc = $(this).attr("src").replace("_over.png#hover",".png");
				$(this).attr("src",oldSrc);
			}
		}
	); 

});
 
function validateEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
      return false;
   } else {
	   return true;
   }
}



$(document).ready(function(){

	$("#navigation li.parents:not(:last-child)").after("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)
	
	$("#navigation li.drop").mouseover(function() { //When trigger is clicked...
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").fadeIn(200); //Drop down the subnav on click
 
		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").fadeOut("fast"); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
			$(this).parent().find("ul.subnav").hide(); //When the mouse hovers out of the subnav, move it back up
	});

}); 


function makeContact() {
	var firstname = $("#firstname").val();
	var lastname = $("#surname").val();
	var email = $("#email").val();
	var enquiry = $("#enquiry").val();
	var subject = $("#subject").val();
	
	if (!firstname || firstname == '') {
		alert('Please enter your firstname');
		return false;
	}
	if (!lastname || lastname == '') {
		alert('Please enter your lastname');
		return false;
	}

	if (validateEmail(email) == false) {
		alert('Please enter valid email address');
		return false;
	}
	
	if (!enquiry || enquiry == '') {
		alert('Please enter your question');
		return false;
	}
	
	
	if (!subject || subject == '') {
		alert('Please enter subject');
		return false;
	}
	
	
	if (enquiry && subject && firstname && lastname && email) {
		input_box = confirm("Is all information correct?");	
		if (input_box == true)	{
			//$("#wrap").css('height','20px');
			$.ajax({
			   type: "POST",
			   url: "/sendform.php",
			   data: "subject="+subject+"&email="+email+"&enquiry="+enquiry+"&firstname="+firstname+"&lastname="+lastname,
			   error: function(){
					alert('Sorry, we cannot complete your request.\nPlease try again.');
			   },
			   success: function(data){
				   if (data == "OK") {
						$("#firstname").val('');
						$("#email").val('');
						$("#lastname").val('');
						$("#enquiry").val('');
						$("#subject").val('');
						
						alert('Thank you for your request, someone will respond in due course');
				   } else if (data == 'ERROR') {
						alert('Sorry, we cannot complete your request.\nPlease try again.');
				   } else {
						alert(data);
				   }
			   }
			});	
			//$("#wrap").css('height','0px');
			return true;
		} else {
			return false; 	
		}
	} 
	
	
} 
