/* MAYO AVIATION
   Google Maps JS
   Copr. 2009 */


$(document).ready(function(){
	
	// Contact form
	
	var lf = location.hash.substring(1);
	
	if (lf == "charter" || lf == "management" || lf == "maintenance" || lf == "parts" || lf == "employment" || lf == "thanks") {
		if (lf != "thanks") $("#topic").val(lf); 
		loadForm(lf); }
	
	$("#topic").bind('change',function(){
		loadForm($(this).val());
	});	
	
	// Google Map
	
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.setCenter(new GLatLng(39.60708168686832,-104.85823631286621), 12);
		var info = '<div class="marker"><h3>Mayo Aviation</h3>Centennial Airport<br/>7735 South Peoria St.<br/>Englewood, CO 80112 <span class="directions"><a id="getdir" onclick="loadDir(); return false;" href="http://maps.google.com/maps?f=d&hl=en&daddr=7735+South+Peoria+St,+Englewood,+CO+80112+(Mayo Aviation)&saddr=">Get Directions</a><div id="startadd" style="display: none;"><form id="startdir" onsubmit="googleDir(); return false;"><fieldset><label for="saddy">Start address</label><input id="saddy" type="text" /></fieldset></form></div></span></div>';
		var marker = new GMarker(new GLatLng(39.576916414865394,-104.84579086303711));
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(info);
		});
		map.addOverlay(marker);
		marker.openInfoWindowHtml(info);
	}

});

$(document).unload(function(){ GUnload(); });

function loadForm(topic){
	
	$(".cforms").hide();

	if (topic == "employment") {

		$("#contact h3").text("Apply now");
		$("#contact form").attr("action","?action=contact#employment");
		$("#contact .descript").html("<p>We appreciate your interest in a career with Mayo Aviation. To apply, please fill out the form below. Cover letters are not necessary and resumes will be kept for 6 months.</p><p>If you are applying for a pilot position, please review our <a href='/about/employment/'>Requirements for Pilot Employment</a> before submitting.</p>");
		$(".field-company").hide();
		$("#thanks").hide();
		$("#employment").show();
		
	} else if (topic == "thanks") {

		$("#contact h3").text("Contact us");
		$("#contact .descript").hide(); $("form h4").hide(); $("form fieldset").hide();
		$("#thanks").show();
		
	} else {
		
		var act = "?action=contact#" + topic;

		$("#contact h3").text("Contact us");
		$("#contact form").attr("action",act);
		$("#contact .descript").html("<p>Looking to charter a jet? Interested in our aircraft maintenance solutions? Please fill out the form below and a representative will be in touch.</p>");
		$(".field-company").show();
		$("#thanks").hide();
		
		if (topic != "charter" && topic != "management" && topic != "maintenance" && topic != "parts" && topic != "thanks") {
			$("#general").show();
		} else { $("#"+topic).show(); }
		
	}
	
	if (topic != "") {
		location.hash = "#"+topic;
	}

}

function loadDir(){
	if($("#startadd").is(":hidden")) {
		$("#getdir").hide();
		$("#startadd").show();
		$("#saddy").focus();
	}
}

function googleDir(){
	var startaddress = $("#saddy").val();
	location.href = "http://maps.google.com/maps?f=d&hl=en&daddr=7735+South+Peoria+St,+Englewood,+CO+80112+(Mayo Aviation)&saddr=" + startaddress;
}