// mini'ed here: http://fmarcia.info/jsmin/test.html
function ModGMap(){this.map=null;this.geocoder=null;this.zoom=13;this.lat=null;this.lng=null;this.control=null;this.onComplete=null;this.markers=[];this.overlays=[];this.load=function(namespace,options){this.loadOptions(options);this.namespace=namespace;this.geocoder=new GClientGeocoder();this.map=new google.maps.Map2(document.getElementById("gmap_"+namespace));if(this.control){this.map.addControl(new this.control());}
this.setCenter(this.lat,this.lng);if(document.getElementById(this.namespace+"_location")&&!document.getElementById(this.namespace+"_location").value){document.getElementById(this.namespace+"_location").value=this.map.getCenter().toString();}
if(this.onComplete){this.onComplete();}};this.loadOptions=function(o){if(o.control){this.control=o.control;}
if(o.lat){this.lat=o.lat;}
if(o.lng){this.lng=o.lng;}
if(o.zoom){this.zoom=o.zoom;}};this.setCenter=function(lat,lng){if(!lng&&!lat){this.map.setCenter(this.Gspot,this.getZoom());return;}
this.map.setCenter(new google.maps.LatLng(lat,lng),this.getZoom());this.lat=lat;this.lng=lng;};this.getZoom=function(){if(document.getElementById(this.namespace+'_zoom')){return parseInt(document.getElementById(this.namespace+'_zoom').value,10);}
return parseInt(this.zoom,10);};this.findAddress=function(address){if(!this.onFindAddress){alert("Search for "+address+"failed. Please contact system support");}
this.geocoder.getLocations(address,this.onFindAddress);};this.addMarker=function(id,opt){var el,lat,lng,overs,info,drag,display_icon;el={lat:null,lng:null,info:null,remove:null};if(opt&&opt.lat){lat=opt.lat;}else{lat=this.map.getCenter().lat();}
if(opt&&opt.lng){lng=opt.lng;}else{lng=this.map.getCenter().lng();}
if(opt&&opt.info){info=opt.info;}else{info='';}
if(opt&&opt.icon){display_icon=opt.icon;}else{display_icon=null;}
if(!id){var d=new Date();id=d.getTime();}
var markerName=this.namespace+"_marker_"+id;var markerOptions={};overs=document.getElementById('overlays');if(overs){if(!document.getElementById(markerName+'_lat')){el.lat=document.createElement("input");el.lat.type='hidden';el.lat.name=markerName+'_lat';el.lat.value=lat;el.lat.id=markerName+'_lat';overs.appendChild(el.lat);}
if(!document.getElementById(markerName+'_lng')){el.lng=document.createElement("input");el.lng.type='hidden';el.lng.name=markerName+'_lng';el.lng.value=lng;el.lng.id=markerName+'_lng';overs.appendChild(el.lng);}
if(!document.getElementById(markerName+"_info")){el.info=document.createElement("input");el.info.type='text';el.info.name=markerName+'_info';el.info.id=markerName+'_info';el.info.className='marker_info';el.info.value=info;overs.appendChild(el.info);el.info.onblur=function(){this.style.display='none';};}
drag=true;markerOptions={draggable:drag};}else{drag=false;if(display_icon!=null){markerOptions={draggable:drag,icon:display_icon};}else{markerOptions={draggable:drag};}}
var marker=new GMarker(new google.maps.LatLng(lat,lng),markerOptions);marker.modName=markerName;if(overs){marker.editMarker=function(){if(document.getElementById(this.modName+"_info")){document.getElementById(this.modName+"_info").style.display='inline';document.getElementById(this.modName+"_info").focus();}};GEvent.addListener(marker,"dragend",function(){el.lat.value=marker.getLatLng().lat();el.lng.value=marker.getLatLng().lng();});GEvent.addListener(marker,"click",function(){this.editMarker();});GEvent.addListener(marker,"dblclick",function(){if(confirm("Delete this marker?")){if(document.getElementById(marker.modName+'_lng')){document.getElementById(marker.modName+'_lng').parentNode.removeChild(document.getElementById(marker.modName+'_lng'));}
if(document.getElementById(marker.modName+'_lat')){document.getElementById(marker.modName+'_lat').parentNode.removeChild(document.getElementById(marker.modName+'_lat'));}
if(document.getElementById(marker.modName+'_info')){document.getElementById(marker.modName+'_info').parentNode.removeChild(document.getElementById(marker.modName+'_info'));}
this.hide();}});}
this.map.addOverlay(marker);if(document.getElementById(markerName+'_info')&&document.getElementById(markerName+'_info').value){marker.openInfoWindowHtml(document.getElementById(markerName+'_info').value);}
this.markers.push(marker);};this.getMarker=function(marker_name){for(var i=0;i<this.markers.length;i++){if(this.markers[i].modName!=marker_name){continue;}
return this.markers[i];}};}