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

(function(a){var d=function(){};a.extend(d.prototype,{name:"googlemaps",options:{lat:53.553407,lng:9.992196,marker:!0,popup:!1,text:"",zoom:13,mapCtrl:1,zoomWhl:!0,mapTypeId:"roadmap",typeCtrl:!0,directions:!0,directionsDestUpdate:!0,mainIcon:"red-dot",otherIcon:"blue-dot",iconUrl:"http://maps.google.com/mapfiles/ms/micons/"},initialize:function(b,c){this.options.msgFromAddress=a.trans.get("FROM_ADRESS");this.options.msgGetDirections=a.trans.get("GET_DIRECTIONS");this.options.msgEmpty=a.trans.get("FILL_IN_ADRESS");
this.options.msgNotFound=a.trans.get("ADRESS_NOT_FOUND");this.options.msgAddressNotFound=a.trans.get("LOCATION_NOT_FOUND");this.options=a.extend({},this.options,c);this.container=b;this.setupMap();this.options.directions&&this.setupDirections()},setupMap:function(){this.map=new google.maps.Map(this.container.get(0),{mapTypeId:this.options.mapTypeId,streetViewControl:this.options.mapCtrl?!0:!1,navigationControl:this.options.mapCtrl,scrollwheel:this.options.zoomWhl?!0:!1,mapTypeControl:this.options.typeCtrl?
!0:!1,navigationControlOptions:{style:this.options.mapCtrl==1?google.maps.NavigationControlStyle.DEFAULT:google.maps.NavigationControlStyle.SMALL}});this.infowindow=new google.maps.InfoWindow;this.options.marker&&(this.options.popup==0?(this.map.setCenter(new google.maps.LatLng(this.options.lat,this.options.lng)),this.map.setZoom(this.options.zoom)):this.addMarkerLatLng(this.options.lat,this.options.lng,this.options.text,!0));this.centerMap(this.options.lat,this.options.lng)},createMarker:function(b,
c,e){var a=this,d=this.map,i=this.infowindow,j=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)),g=new google.maps.Marker({position:b,icon:j,shadow:e,map:this.map});google.maps.event.addListener(g,
"click",function(){c.length&&(i.setContent(c),i.open(d,g));if(a.options.directionsDestUpdate)a.options.lat=g.getPosition().lat(),a.options.lng=g.getPosition().lng()});return g},centerMap:function(b,c){this.map.setCenter(new google.maps.LatLng(b,c));this.map.setZoom(this.options.zoom)},addMarkerLatLng:function(b,c,a,d,f){f=f||this.options.otherIcon;if(d)f=this.options.mainIcon;b=new google.maps.LatLng(b,c);f=this.createMarker(b,a,f);d&&(this.map.setCenter(b),this.map.setZoom(this.options.zoom));d&&
a&&a.length&&this.options.popup==2&&(this.infowindow.setContent(a),this.infowindow.open(this.map,f))},setupDirections:function(){var b=this;this.directionsService=new google.maps.DirectionsService;this.directionsDisplay=new google.maps.DirectionsRenderer;this.directionsDisplay.setMap(this.map);this.directionsDisplay.setPanel(a("<div>").addClass("directions").css("position","relative").insertAfter(this.container).get(0));var c=a("<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>");a('<form method="get" action="#">').append(c).insertAfter(this.container).bind("submit",function(c){c.preventDefault();c.stopPropagation();b.setDirections(a(this))})},setDirections:function(b){var a=this;this.container.parent().find("div.alert").remove();b=b.find('input[name="address"]').val();b===""?this.showAlert(this.options.msgEmpty):this.directionsService.route({origin:b,
destination:new google.maps.LatLng(this.options.lat,this.options.lng),travelMode:google.maps.DirectionsTravelMode.DRIVING},function(b,d){d==google.maps.DirectionsStatus.OK?a.directionsDisplay.setDirections(b):a.showAlert(a.options.msgNotFound)})},showAlert:function(b){a("<div>").addClass("alert").append(a("<strong>").text(b)).insertAfter(this.container)},cmd:function(){var a=arguments,c=a[0]?a[0]:null;this.map[c]&&this.map[c].apply(this.map,Array.prototype.slice.call(a,1))}});a.fn[d.prototype.name]=
function(){var b=arguments,c=b[0]?b[0]:null;return this.each(function(){var e=a(this);if(d.prototype[c]&&e.data(d.prototype.name)&&c!="initialize")e.data(d.prototype.name)[c].apply(e.data(d.prototype.name),Array.prototype.slice.call(b,1));else if(!c||a.isPlainObject(c)){var h=new d;d.prototype.initialize&&h.initialize.apply(h,a.merge([e],b));e.data(d.prototype.name,h)}else a.error("Method "+c+" does not exist on jQuery."+d.name)})}})(jQuery);

