function displayErrorMessage(data) {
	var resultsBox = new Boxy("<div style=\"width: 300px; height: 300px\">"+data+"</div>", {
		title: "Error",
		draggable: false,
		modal:true
	});
}

$(function() {							
	/* set global variable for boxy window */
	var contactBoxy = null;
	/* what to do when click on contact us link */
	$('.contact_us').click(function(){
		var boxy_content;
		
		boxy_content += "<div style=\"width:300px; height:300px \"><form id=\"feedbacked\">";
		boxy_content += "<p>Subject<br /><input type=\"text\" name=\"subject\" id=\"subject\" size=\"33\" /></p><p>Your E-Mail Address:<br /><input type=\"text\" name=\"your_email\" size=\"33\" /></p><p>Comment:<br /><textarea name=\"comment\" id=\"comment\" cols=\"33\" rows=\"5\"></textarea></p><br /><input type=\"submit\" name=\"submit\" value=\"Send >>\" />";
		boxy_content += "</form></div>";
		
		contactBoxy = new Boxy(boxy_content, {
			title: "Send feedback",
			draggable: false,
			modal:true,
			behaviours: function(c) {
				c.find('#feedbacked').submit(function() {
				
					var email = c.find("input[name='your_email']").val();
					
					// submit form by ajax using post and send 3 values: subject, your_email, comment
					$.post("PHP_Scripts/suggest.php", { subject: c.find("input[name='subject']").val(), your_email: c.find("input[name='your_email']").val(), comment: c.find("#comment").val()},
					function(data){
						if (email == "") {
							displayErrorMessage(data);
						} else {
							contactBoxy.setContent("<div style=\"width: 300px; height: 300px\">" +data+ "</div>");
						}
						
					});
					return false;
				});
			} 
		});
		return false;
		
		contactBoxy.hide();
	});
	
	$('#feedback-button').hover(
		function() {
			$(this).attr('src', 'Resources/home_images/feedback-hover.png');
		},
		function() {
			$(this).attr('src', 'Resources/home_images/feedback.png');
		}
	);
});
