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

(function(c){var d=function(){};c.extend(d.prototype,{name:"Googlemaps",options:{lat:53.553407,lng:9.992196,marker:!0,popup:!1,text:"",zoom:13,mapCtrl:2,zoomWhl:!0,mapType:0,typeCtrl:!0,overviewCtrl:!0,directions:!0,directionsDestUpdate:!1,directionsTravelMode:0,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!"},initialize:function(a,b){this.options=c.extend({},this.options,b);this.container=a;this.setupMap();this.options.directions&&this.setupDirections()},setupMap:function(){this.map=new google.maps.Map(this.container.get(0),{mapTypeId:google.maps.MapTypeId.ROADMAP});this.map.setOptions({navigationControl:this.options.mapCtrl==1||this.options.mapCtrl==2?!0:!1});this.map.setOptions({navigationControlOptions:{style:this.options.mapCtrl==1?google.maps.NavigationControlStyle.SMALL:
google.maps.NavigationControlStyle.DEFAULT}});this.map.setOptions({scrollwheel:this.options.zoomWhl?!0:!1});this.options.mapType==1&&this.map.setOptions({mapTypeId:google.maps.MapTypeId.SATELLITE});this.options.mapType==2&&this.map.setOptions({mapTypeId:google.maps.MapTypeId.HYBRID});this.map.setOptions({mapTypeControl:this.options.typeCtrl?!0:!1});this.infowindow=new google.maps.InfoWindow;this.options.marker?this.addMarkerLatLng(this.options.lat,this.options.lng,this.options.text,!0):this.centerMap(this.options.lat,
this.options.lng)},createMarker:function(a,b,e){var c=this,d=this.map,h=this.infowindow,i=new google.maps.MarkerImage(this.options.iconUrl+e+".png",new google.maps.Size(32,32),new google.maps.Point(0,0),new google.maps.Point(16,32)),e=e.match("pushpin")?this.options.iconUrl+"pushpin_shadow.png":this.options.iconUrl+"msmarker.shadow.png",e=new google.maps.MarkerImage(e,new google.maps.Size(56,32),new google.maps.Point(0,0),new google.maps.Point(16,32)),f=new google.maps.Marker({position:a,icon:i,shadow:e,
map:this.map});(b||this.options.directionsDestUpdate)&&google.maps.event.addListener(f,"click",function(){b&&(h.setContent(b),h.open(d,f));if(c.options.directionsDestUpdate)c.options.lat=f.getPosition().lat(),c.options.lng=f.getPosition().lng()});return f},centerMap:function(a,b){this.map.setCenter(new google.maps.LatLng(a,b));this.map.setZoom(this.options.zoom)},addMarkerLatLng:function(a,b,e,c){var d=this.options.otherIcon;if(c)d=this.options.mainIcon;a=new google.maps.LatLng(a,b);d=this.createMarker(a,
e,d);c&&(this.map.setCenter(a),this.map.setZoom(this.options.zoom));c&&e&&this.options.popup&&(this.infowindow.setContent(e),this.infowindow.open(this.map,d))},setupDirections:function(){var a=this;this.directionsService=new google.maps.DirectionsService;this.directionsDisplay=new google.maps.DirectionsRenderer;this.directionsDisplay.setMap(this.map);this.directionsDisplay.setPanel(c("<div>").addClass("directions").css("position","relative").insertAfter(this.container).get(0));var b=c("<p>").append('<label for="from-address">'+
this.options.msgFromAddress+"</label>").append('<input type="text" name="address" style="margin:0 5px;" />').append('<button type="submit">'+this.options.msgGetDirections+"</button>");c('<form method="get" action="#"></form>').append(b).insertAfter(this.container).bind("submit",function(b){b.preventDefault();b.stopPropagation();a.setDirections(c(this))})},setDirections:function(a){var b=this;this.container.parent().find("div.alert").remove();a=a.find('input[name="address"]').val();a===""?this.showAlert(this.options.msgEmpty):
this.directionsService.route({origin:a,destination:new google.maps.LatLng(this.options.lat,this.options.lng),travelMode:google.maps.DirectionsTravelMode.DRIVING,region:this.options.locale},function(a,c){c==google.maps.DirectionsStatus.OK?b.directionsDisplay.setDirections(a):b.showAlert(b.options.msgNotFound)})},showAlert:function(a){c("<div>").addClass("alert").append(c("<strong>").text(a)).insertAfter(this.container)}});c.fn[d.prototype.name]=function(){var a=arguments,b=a[0]?a[0]:null;return this.each(function(){var e=
c(this);if(d.prototype[b]&&e.data(d.prototype.name)&&b!="initialize")e.data(d.prototype.name)[b].apply(e.data(d.prototype.name),Array.prototype.slice.call(a,1));else if(!b||c.isPlainObject(b)){var g=new d;d.prototype.initialize&&g.initialize.apply(g,c.merge([e],a));e.data(d.prototype.name,g)}else c.error("Method "+b+" does not exist on jQuery."+d.name)})}})(jQuery);
