// VERTICALLY ALIGN FUNCTION
(function ($) {
$.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $(this).height();
	//alert(ah);
	var ph = $(this).parent().height();
	//alert(ph);
	var mh = (ph - ah) / 2;
	//alert(mh);
	$(this).css('padding-top', mh);
	});
};
})(jQuery);

$(document).ready(function(){
	$("#Top_Menu li").hover(
		function(){
			$("ul", this).show(500);
		},
		function(){
			$("ul", this).fadeOut('fast');
		}
	);
	
	
	$(".contactform").submit(function(){
									 submitForm(this);
									 return false;
									 });

	
	/* MENU EDITING */
	
	//menu buttons
	$("#Top_Menu").sortable({
		containment: $("#Top_Menu"),
		revert: true,
		stop: function(event, ui) {
					alert($("#Top_Menu").html());
					}
	}).disableSelection();
	
	//submenu buttons
	$("#Top_Menu ul").sortable({
		containment: 'parent',
		revert: true,
		stop: function(event, ui) {
					//DROPPED MENU ITEM
					}
	}).disableSelection();

});//doc ready

function submitForm(form){

	var error = false;
	$.each($(".required", $(form)), function(i, obj){
		if (!$(obj).val()){
			$(obj).css("background", "red");
			$(obj).css("color", "white");
			error = true;
			}
		else {
			$(obj).css("background", "#fff");
			$(obj).css("color", "#333");					
			}
		});//each required object
	
	if (error == true) 
		return false;
	else {
		$(":submit", $(form) ).replaceWith("<img class='formprogressicon' src='design/images/progress.gif' />");
		$.post( $(form).attr("action"), $(form).serialize(), function(data){
															if ($("input[name=redirect]'", $(form)).val())
																location.href = $("input[name]='redirect'", $(form)).val();
															else {
																$(".formprogressicon", $(form) ).replaceWith("<input type='submit' style='width:100%;' />");
															  	$(form).append("<p class='formmessage' style='text-align: center; font-size: 14px; font-weight: bold; display: none;'>Your request has been sent!<br />Expect a response very shortly!</p>");
															  	$(".formmessage", $(form) ).fadeIn(300);
															  	return false;
																}
															});
	}//no errors
	return false;
}//submitForm function 
