var centerLatitude = 34.9;
var centerLongitude = 33;
var startZoom = 9;

var map;
var marker;

$(document).ready(function(){

    var iconMole = new GIcon(); 
    iconMole.image = '/images/gmap/icon.png';
    iconMole.shadow = '/images/gmap/shicon.png';
    iconMole.iconSize = new GSize(15, 27);
    iconMole.shadowSize = new GSize(35, 27);
    iconMole.iconAnchor = new GPoint(7, 26);
    iconMole.infoWindowAnchor = new GPoint(7, 1);
									
    if (GBrowserIsCompatible()) {	
		map = new GMap2(document.getElementById("map"));
		var location = new GLatLng(centerLatitude, centerLongitude);
		map.setCenter(location, startZoom);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setMapType(G_HYBRID_MAP);
		
		G_HYBRID_MAP.getMinimumResolution = function () { return 8 };
		G_HYBRID_MAP.getMaximumResolution = function () { return 18 };

		marker = new GMarker(location, {icon:iconMole, draggable: true});
		
		GEvent.addListener(marker, "dragend", function() {
		  document.getElementById('lat').value = marker.getLatLng().lat();
		  document.getElementById('lng').value = marker.getLatLng().lng();
		});
		
		map.addOverlay(marker);
		
		GEvent.addListener(map, "click", function(overlay, latlng) { 
			if(!overlay){
				marker.setLatLng(latlng);
				document.getElementById('lat').value = marker.getLatLng().lat();
				document.getElementById('lng').value = marker.getLatLng().lng();
			}
		});
		
    }
	 window.onunload = GUnload;
});

//Tabs
function newLocation(){
	$('#presetLocationTab').removeClass('tabcurrent');
	$('#newLocationTab').addClass('tabcurrent');
	$('#newLocation').show();
	$('#presetLocation').hide();
	$('#locChoice').val('1');
	$('#presetLocationTab').blur();
	map.checkResize(); // huck to show the map in Firefox
	return false;
}
function presetLocation(){
	$('#newLocationTab').removeClass('tabcurrent');
	$('#presetLocationTab').addClass('tabcurrent');
	$('#presetLocation').show();
	$('#newLocation').hide();
	$('#locChoice').val('0');
	$('#newLocationTab').blur();	
	return false;
}
$(document).ready(function(){
	
	$('#newLocation').hide();
	$('#newLocationTab').click(newLocation);
	$('#presetLocationTab').click(presetLocation);
	
});
								

