
// Menu
$(document).ready(function(){
						
				$("#top-menu li a").mouseover(function() {
					$(this).parent().find("ul.subnav").show();
			
					$(this).parent().hover(function() {
					}, function(){	
						$(this).parent().find("ul.subnav").stop().hide();
					});
				});

				$("#top-menu li ul").mouseover(function() {
					$(this).parent().addClass("on");
				});

				$("#top-menu li ul").mouseout(function() {
					$("#top-menu li").removeClass("on");
				});
			
			});

		
// swfobject
			var flashvars = {};
			var params = {};
			params.menu = "false";
			params.wmode = "transparent";
			var attributes = {};
			swfobject.embedSWF("/swf/banner.swf", "banner", "940", "306", "9.0.0", "swf/expressInstall.swf", flashvars, params, attributes);
		
//Forms		
function clearFields() {
	$('form#quick_contact input, form#quick_contact textarea').focus(function(){
			if ($(this).attr('rel') != 'cleared') {
				$(this).val('').attr('rel', 'cleared');
			}		
		});
	$('form#quick_contact input, form#quick_contact textarea').blur(function(){
			if($(this).val() == ""){	
				$(this).val(this.defaultValue).attr('rel', '');
				
			}		
		});		
}
function verifyErrors() {
	var ready = 1;
	$('.required_field').css('color', '#6b6b6b');
	$('.required_field').each(function(){			
			if(($(this).val() == "")||(!$(this).attr('rel'))) {
				$(this).css('color', '#d6041f');
				ready = 0;
			}		
		});
	$('input.email').each(function(){
			var email_val = $(this).val();
			if(email_val.indexOf('@') < 0) {
				$(this).css('color', '#d6041f');
				ready = 0;
			}		
		});
	/*$('input.security').each(function(){			
			if($(this).val() != "4") {
				$(this).css('color', '#d6041f');
				ready = 0;
			}		
		}); */
	if (ready == 0) {
		$('p.warning').text('* Please fill out the boxes highlighted in red and click submit').css('color', '#d6041f');
		return false;
	};
	return true;	
}
function formControl() {
	$('form#quick_contact').submit(function(){
		if (verifyErrors()) {
			action = $(this).attr('action');
			mesagetosend = $(this).serialize();			
			$.ajax({
					type: "POST",
					url: 'quick-contact-form.php',
					data: mesagetosend,
					dataType : "html",
					timeout:10000,
					error: function() {
						replaceContent();
					},
					success: function(msg){
						replaceContent(); 
					}
				});
			}
		return false;
	});
}
function replaceContent() {
	alert('Thank you for your enquiry, we will respond to you very shortly!');
	$('#quick_contact').innerHTML = '<div id="thank_you"><h2><strong>Thank You</strong><em>We appreciate your inquiry,<br />and will respond as soon as possible</em></h2></div>';
}
jQuery(function($) {
	clearFields();
	formControl();
});
