//<![CDATA[

$(document).ready(function() {
	if (!GBrowserIsCompatible()) {
		return;
	};
	
	var mapConfig = { lat: 33.4243526, lng: -111.9469515, zoom: 15 };
	var point = new GLatLng(mapConfig.lat, mapConfig.lng);
	var holder = $(".js-map").get(0);
	if (holder) {
		map = new GMap2(holder);
		map.addControl(new True_ZoomControl());
		map.addControl(new True_MapTypeControl());
		map.setCenter(point, mapConfig.zoom);

		var baseIcon = new GIcon();
		baseIcon.image = '/art/map_markerTrue.png';
		baseIcon.shadow = '/art/map_markerShadow.png';
		baseIcon.iconSize = new GSize(105, 33);
		baseIcon.shadowSize = new GSize(129, 38);
		baseIcon.iconAnchor = new GPoint(22, 33);
		baseIcon.infoWindowAnchor = new GPoint(47, 2);
	
		var options = { icon: new GIcon(baseIcon) };
		options.icon.image = baseIcon.image;
		var marker = new GMarker(new GLatLng(mapConfig.lat, mapConfig.lng), options);
		map.addOverlay(marker);
		var m = marker;
		var f = function() { m.openInfoWindowHtml($('div.js-mapPopup').html()); };
		//GEvent.addListener(m, "click", f);
		//f();
    }
});

function True_Control() { };

True_Control.prototype = new GControl();
True_Control.prototype._addButton = function(p_container, p_image, p_clickDelegate) {
    var anchor = document.createElement("a");
    $(anchor).attr("href", "javascript:;");
    $(anchor).html('<img src="/art/' + p_image + '" />');
    p_container.appendChild(anchor);

    GEvent.addDomListener(anchor, "click", p_clickDelegate);
}

function True_ZoomControl() { };

True_ZoomControl.prototype = new True_Control();

True_ZoomControl.prototype.initialize = function(map) {
    var container = document.createElement("div");

    this._addButton(container, "map_buttonZoomOut.png", function() { map.zoomOut(); return false; });
    this._addButton(container, "map_buttonZoomIn.png", function() { map.zoomIn(); return false; });
    map.getContainer().appendChild(container);

    return container;
};

True_ZoomControl.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(4, 4));
};

function True_MapTypeControl() {
};

True_MapTypeControl.prototype = new True_Control();

True_MapTypeControl.prototype.initialize = function(map) {
    var container = document.createElement("div");

    this._addButton(container, "map_buttonMap.png", function() { map.setMapType(G_NORMAL_MAP); return false; });
    this._addButton(container, "map_buttonSatellite.png", function() { map.setMapType(G_SATELLITE_MAP); return false; });
    this._addButton(container, "map_buttonHybrid.png", function() { map.setMapType(G_HYBRID_MAP); return false; });
    map.getContainer().appendChild(container);

    return container;
};

True_MapTypeControl.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(4, 4));
};

//]]>


function sendMail(){
	var vals = {email: "", name: "", howGotHere: "", reason: ""};
	for(var p in vals){
		vals[p] = $("#" + p).val();
	}
	$.post("/contact/contact", vals, function(data){
			$("#js-contactResult").html(data);
		}
	);
	
	$("#js-contactForm").hide();
	$("#js-contactResult").html("<img src='art/processingAnim.gif' />");
	return false;
};

function showContactForm(){
	$("#js-contactForm").show();
	$("#js-contactResult").html("");
};