/* Author: Jonathon Hallett

*/

/* Declare functions */
// Replace the home page images with rollovers
	function rolloverHoverImage(){
		$("#web").hover(
			function(){
				$("img", this).attr('src', 'img/www2_hover2.png');
			},
			function(){
				$("img", this).attr('src', 'img/www2.png');
			}
		);
		$("#droid").hover(
			function(){
				$("img", this).attr('src', 'img/android_hover5.png');
			},
			function(){
				$("img", this).attr('src', 'img/android.png');
			}
		);
	};
	
// hover effect for menu buttons
	function hoverEffect(){
		// back arrow
		$("#back").hover(
			function(){
				$("img", this).attr('src', 'img/back_arrow_hover3.png');
			},
			function(){
				$("img", this).attr('src', 'img/back_arrow.png');
			}
		);
		// back text
		$('#back').hover(
			function(){
				$('.back').fadeTo(0, 0.9);
			},
			function(){
				$('.back').fadeTo(0, 0.4);
			}
		)
		// contact bubble
		$("#contact").hover(
			function(){
				$("img", this).attr('src', 'img/contact_bubble_hover.png');
			},
			function(){
				$("img", this).attr('src', 'img/contact_bubble.png');
			}
		)
		// contact text
		$("#contact").hover(
			function(){
				$(".contact").fadeTo(0, 0.9);
			},
			function(){
				$(".contact").fadeTo(0, 0.4);
			}
		);
		// about text
		$("#about").hover(
			function(){
				$(".about").fadeTo(0, 0.9);
			},
			function(){
				$(".about").fadeTo(0, 0.4);
			}
		);
		// about image
		$("#about_img").hover(
			function(){
				$("img", this).attr('src', 'img/about_img_hover.png');
			},
			function(){
				$("img", this).attr('src', 'img/about_img.png');
			}
		);
		// visit site link
		// about text
		$(".visit").hover(
			function(){
				$(this).fadeTo(0, 0.9);
			},
			function(){
				$(this).fadeTo(0, 0.4);
			}
		);
		
		// close button
		$(".close").hover(
			function(){
				$("img", this).attr('src', 'img/close_hover3.png');
			},
			function(){
				$("img", this).attr('src', 'img/close2.png');
			}
		);
		
	};// end hover effect
	
// close the drop down form content
	function closeFormDropDown(){
		$(".close_btn").click(function(){
			event.preventDefault();
			$("#contact_form form").slideUp(400);
		});
		return false;
	}	

// show the contact form
	function showForm(){
		$("#contact").click(function(){
			event.preventDefault();
			$("#contact_form form").slideToggle(400);
		});
		return false;
	};
	

// show about us description
	function showAbout(){
		$("#about").click(function(){
			event.preventDefault();
			$("#about_box").slideToggle(400);
		});
		return false;
	};
// close the drop down about content
	function closeAboutDropDown(){
		$(".close_btn").click(function(){
			event.preventDefault();
			$("#about_box").slideUp(400);
		});
		return false;
	}
	
// Show WWW drop content page
	function showWWWContent(){
		$("#web").click(function(){
			event.preventDefault();
			$("#www_content").slideToggle(600);
		});
		return false;
	};
// close  www content drop down
	function closeWWWContent(){
		$(".close_btn").click(function(){
			event.preventDefault();
			$("#www_content").slideUp(600);
		});
		return false;
	}

// Show Android drop content
	function showAndroidContent(){
		$("#droid").click(function(){
			event.preventDefault();
			$("#android_content").slideToggle(600);
		});
		return false;
	};
// close Android content
	function closeAndroidContent(){
		$(".close_btn").click(function(){
			event.preventDefault();
			$("#android_content").slideUp(600);
		});
		return false;
	}
	
// Ajax form submition (Thanks to Ryan Olson)
	function sendForm(){
		$('#contact_form #submit').click(function(){
			// Hide any errors on first load
			$('#contact_form .error').hide();
			// get name from input and check it's not empty, display error if it is
			var name = $('input#name').val();
			if(name == "" || name == " "){
				$('input#name').focus().after('<div id="input_name" class="error">Please Enter Your Name</div>');
				return false;
			}
			// get email and test for validity, display error if not
			var email_test = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
			var email = $('input#email').val();
			if(email == "" || email == " "){
				$('input#email').focus().after('<div id="input_email" class="error">Please Enter Your Email address</div>');
				return false;
			}else if (!email_test.test(email)) {
				$('input#email').focus().after('<div id="input_email" class="error">Please Enter a Valid Email Address</div>')
				return false;
			};
			// get message and test for validity
			var message = $('#message').val();
			if(message == "" || message == " "){
				$('#message').focus().after('<div id="input_message" class="error">Please Enter Your Message</div>');
				return false;
			}
			// set up form data to be read by send_mail.php
			var form_data = $('#contact_form form').serialize();
			// send form data and show success message
			$.ajax({
				type: 		"POST",
				url: 		"send_mail.php",
				data: 		form_data,
				success: 	function(){
					$('#contact_form form').slideUp('fast').before('<div id="success" class="drop_content"></div>');
					$('#success').html('<h1>Success!</h1><p>Your Email has been sent, we will contact you as soon as possible.</p>').slideDown('slow', function(){setTimeout(function(){$("#success").slideUp('slow')}, 2000)});
							}				
			})
			
			return false;
			
			
			
		})			
		
	}// end sendMail	


$(document).ready(function (){
	
	/* Call the functions */
	
	// Image replacement for mouseover on main page
	rolloverHoverImage();
	
	// hover effect for menu items
	hoverEffect();
	
	// hide form on document load
	//$("#contact_form").hide();
	// show the contact form
	showForm();
	
	// show the about us box
	showAbout();
	
	// show www content
	showWWWContent();
	
	// show android content
	showAndroidContent();
	
	// close the drop down boxes	
	closeFormDropDown();
	closeAboutDropDown();
	closeWWWContent();
	closeAndroidContent();
	
	
	// send the form
	sendForm();
	
});























