/* Copyright (C) 2007 - 2010 YOOtheme GmbH, YOOtheme License (http://www.yootheme.com/license) */

var YOOmaps=new Class({initialize:function(a,b){this.setOptions({lat:53.553407,lng:9.992196,marker:false,popup:false,text:"",zoom:13,mapCtrl:2,zoomWhl:true,mapType:0,typeCtrl:true,overviewCtrl:true,directions:true,directionsDestUpdate:false,locale:"en",mainIcon:"red-dot",otherIcon:"blue-dot",iconUrl:"http://maps.google.com/mapfiles/ms/micons/",msgFromAddress:"From address: ",msgGetDirections:"Get directions",msgEmpty:"Please fill in your address.",msgNotFound:"Sorry, address not found!",msgAddressNotFound:", not found!"},
b);if(GBrowserIsCompatible()){this.container=$(a);this.map=new GMap2(this.container);this.geocoder=new GClientGeocoder;this.baseIcon=new GIcon;this.baseIcon.shadow=this.options.iconUrl+"msmarker.shadow.png";this.baseIcon.iconSize=new GSize(32,32);this.baseIcon.shadowSize=new GSize(56,32);this.baseIcon.iconAnchor=new GPoint(16,32);this.baseIcon.infoWindowAnchor=new GPoint(16,0);this.baseIcon.infoShadowAnchor=new GPoint(18,25);this.setupMap();this.options.directions&&this.setupDirections()}},setupMap:function(){this.options.marker?
this.addMarkerLatLng(this.options.lat,this.options.lng,this.options.text,true):this.centerMap(this.options.lat,this.options.lng);this.options.mapCtrl==1&&this.map.addControl(new GSmallMapControl);this.options.mapCtrl==2&&this.map.addControl(new GLargeMapControl);this.options.zoomWhl&&this.map.enableScrollWheelZoom();this.options.mapType==1&&this.map.setMapType(G_SATELLITE_MAP);this.options.mapType==2&&this.map.setMapType(G_HYBRID_MAP);this.options.typeCtrl&&this.map.addControl(new GMapTypeControl);
this.options.overviewCtrl&&this.map.addControl(new GOverviewMapControl);typeof GUnload==="function"&&$E("body").addEvent("unload",GUnload)},createMarker:function(a,b,e){var d=new GIcon(this.baseIcon);d.image=this.options.iconUrl+e+".png";if(e.match("pushpin"))d.shadow=this.options.iconUrl+"pushpin_shadow.png";var c=new GMarker(a,{icon:d});if(b||this.options.directionsDestUpdate)GEvent.addListener(c,"click",function(){b&&c.openInfoWindowHtml(b);if(this.options.directionsDestUpdate){this.options.lat=
c.getLatLng().lat();this.options.lng=c.getLatLng().lng()}}.bind(this));return c},centerMap:function(a,b){this.map.setCenter(new GLatLng(a,b),this.options.zoom)},addMarkerLatLng:function(a,b,e,d){var c=this.map,f=this.options.otherIcon;if(d)f=this.options.mainIcon;a=new GLatLng(a,b);f=this.createMarker(a,e,f);d&&c.setCenter(a,this.options.zoom);c.addOverlay(f);d&&e&&this.options.popup&&f.openInfoWindowHtml(e)},setupDirections:function(){var a=(new Element("div",{id:"directions"})).injectAfter(this.container);
this.directions=new GDirections(this.map,a);GEvent.addListener(this.directions,"error",function(){this.showAlert(this.options.msgNotFound)}.bind(this));a='<p><label for="from-address">'+this.options.msgFromAddress+'</label><input id="from-address" type="text" name="address" style="margin:0 5px;" /><button type="submit">'+this.options.msgGetDirections+"</button></p>";(new Element("form",{method:"get",action:"#",events:{submit:this.setDirections.bindWithEvent(this)}})).setHTML(a).injectAfter(this.container)},
setDirections:function(a){(new Event(a)).stop();this.clearAlert();a=$("from-address").getValue();a===""?this.showAlert(this.options.msgEmpty):this.directions.load("from: "+a+" to: "+this.options.lat+","+this.options.lng,{locale:this.options.locale})},showAlert:function(a){var b=new Element("div",{"class":"alert"});(new Element("strong")).setText(a).injectInside(b);b.injectAfter(this.container)},clearAlert:function(){this.container.getParent().getElements("div.alert").each(function(a){a.remove()})}});
YOOmaps.implement(new Options); 

