var _map=null;var Map=Class.create({initialize:function(d,c,a,b){this.id=d;this.lat=c;this.lng=a;this.zoom=12;this.markers=[];this.polylines=[];this.bounds=[];if(GMap2){if(GBrowserIsCompatible()){this.gMap=new GMap2(document.getElementById(d));this.gMap.addControl(new GSmallMapControl());this.gMap.addControl(new GScaleControl());this.gMap.addControl(new GHierarchicalMapTypeControl());this.gMap.enableScrollWheelZoom();this.geocoder=new GClientGeocoder();this.setCenter(c,a,this.zoom);this.setBounds(b);_map=this}else{alert("Browser n&atilde; e&acute; compati&iacute;vel")}}else{alert("API de mapa n&atilde; foi importada")}},addMarker:function(a){this.markers.push(a);if(a.polygon!=null){if(a.immediatePolygon==true){this.gMap.addOverlay(a.polygon.gPolygon)}}this.gMap.addOverlay(a.gMarker);if(a.gMarker.label!=null){this.gMap.addOverlay(a.gMarker.label.instance)}if(Boolean(a.warning)){a.showContent()}},addPolyline:function(a){this.polylines.push(a);this.gMap.addOverlay(a.gPolyline);if(a.isEnableEditing){a.enableEditing()}},centralize:function(e){if(this.markers.length>0){var c=new GLatLngBounds();for(var a=0,d=this.markers.length;a<d;a++){c.extend(this.markers[a].gMarker.getLatLng())}var b=this.gMap.getBoundsZoomLevel(c);if(e!="undefined"&&e<b){this.gMap.setZoom(e)}else{this.gMap.setZoom(b)}this.gMap.setCenter(c.getCenter())}else{if(e!="undefined"&&e<b){this.setCenter(this.lat,this.lng,e)}else{this.setCenter(this.lat,this.lng,this.zoom)}}},centralizePolylines:function(){if(this.polylines.length>0){var d=new GLatLngBounds();for(var b=0,e=this.polylines.length;b<e;b++){var f=this.polylines[b].gPolyline;for(var a=0,c=f.getVertexCount()-1;a<c;a++){d.extend(f.getVertex(a))}}this.gMap.setZoom(this.gMap.getBoundsZoomLevel(d));this.gMap.setCenter(d.getCenter())}else{this.centralize()}},clear:function(){this.markers=[];this.polylines=[];this.gMap.clearOverlays()},checkResize:function(){this.gMap.checkResize();this.centralize()},isInBounds:function(c,a){var b=new GLatLng(c,a);if(this.bounds.containsLatLng(b)){return true}return false},moveMarker:function(a,d,b,c){a.move(d,b)},removeMarker:function(a){var b=[];while(this.markers.length>0){_marker=this.markers.pop();if(a.id==_marker.id){this.gMap.removeOverlay(_marker.gMarker);if(_marker.gMarker.label!=null){_marker.gMarker.label.remove()}if(_marker.polygon!=null){this.gMap.removeOverlay(_marker.polygon.gPolygon)}break}else{b.push(_marker)}}this.markers=this.markers.concat(b)},removePolyline:function(a){var b=[];while(this.polylines.length>0){_polyline=this.polylines.pop();if(a==_polyline){this.gMap.removeOverlay(_polyline.gPolyline);break}else{b.push(_polyline)}}this.polylines=this.polylines.concat(b)},removeAllPolylines:function(){var a=[];while(this.polylines.length>0){_polyline=this.polylines.pop();this.gMap.removeOverlay(_polyline.gPolyline)}this.polylines=[]},panTo:function(a,b){this.gMap.panTo(a.gMarker.getLatLng());if(Boolean(b)){a.showContent()}},setBounds:function(b){var d=new GLatLngBounds();for(var a=0,c=b.length;a<c;a++){d.extend(b[a])}this.bounds=d},setCenter:function(c,a,b){this.gMap.setCenter(new GLatLng(c,a),b)}});var Marker=Class.create({initialize:function(a,g,j,h,k,c){this.id=a;this.lat=g;this.lng=j;this.gIcon=getGIcon(h);this.warning=c.warning;this.infoWindowContent=c.content;this.polygon=null;this.immediatePolygon=c.immediatePolygon;this.polygonShown=false;this.editablePolygon=false;var b={};b.draggable=c.draggable;b.icon=this.gIcon;this.gMarker=new GMarker(new GLatLng(g,j),b);this.gMarker.bindInfoWindowHtml(this.infoWindowContent);if(k!=null){k.setMarker(this);this.gMarker.label=k;var d=this.gMarker;GEvent.addListener(d,"dragstart",function(){d.label.hide()});GEvent.addListener(d,"dragend",function(){d.label.redraw();d.label.show()})}if(Boolean(c.draggable)){var d=this.gMarker;GEvent.addListener(d,"dragstart",function(){getMap().gMap.closeInfoWindow()})}if(c.latListener!=null&&c.lngListener!=null){var d=this.gMarker;$(c.latListener).value=this.gMarker.getLatLng().lat();$(c.lngListener).value=this.gMarker.getLatLng().lng();GEvent.addListener(this.gMarker,"dragend",function(){$(c.latListener).value=d.getLatLng().lat();$(c.lngListener).value=d.getLatLng().lng()})}if(Boolean(c.geofenceEnabled)){var f=this.id+"P";this.polygon=new Polygon(f,c);var e=this;GEvent.addListener(this.gMarker,"dragend",function(){e.lat=e.gMarker.getLatLng().lat();e.lng=e.gMarker.getLatLng().lng();e.refreshPolygon()});if(this.immediatePolygon==false){var e=this;GEvent.addListener(this.gMarker,"click",function(){if(e.polygonShown==true){e.hidePolygon()}else{e.showPolygon()}e.showContent()})}}},addPanOnDragListener:function(){var a=this;GEvent.addListener(this.gMarker,"dragend",function(){getMap().panTo(a,false)})},refreshPolygon:function(){if(this.polygon!=null){getMap().gMap.removeOverlay(this.polygon.gPolygon);this.polygon.redraw(this.lat,this.lng)}},move:function(b,a){this.gMarker.setLatLng(new GLatLng(b,a));if(this.gMarker.label!=null){this.gMarker.label.redraw(true)}},setContent:function(a){this.gMarker.bindInfoWindowHtml(a)},setImage:function(a){this.gMarker.setImage(getImagesPath()+a)},showContent:function(){if(this.infoWindowContent!=null){this.gMarker.openInfoWindowHtml(this.infoWindowContent)}},showLabel:function(){this.gMarker.label.show()},hideLabel:function(){this.gMarker.label.hide()},showPolygon:function(){if(this.polygon!=null){getMap().gMap.addOverlay(this.polygon.gPolygon);this.polygonShown=true;this.polygon.enableEditing(this.editablePolygon)}},hidePolygon:function(){if(this.polygon!=null){getMap().gMap.removeOverlay(this.polygon.gPolygon);this.polygonShown=false;if(this.polygon.listeners.length>0){for(var a=0;a<this.polygon.listeners.length;a++){GEvent.removeListener(this.polygon.listeners[a])}}}},setEditablePolygon:function(a){this.editablePolygon=a}});var GeocodeMarker=Class.create({initialize:function(d,a,b,c){if(getMap().geocoder){getMap().geocoder.getLatLng(a,function(e){if(e){var f=new GMarker(e);lat=f.getLatLng().lat();lng=f.getLatLng().lng()}if(!e||!getMap().isInBounds(lat,lng)){c.warning="true";c.draggable="true";c.content="<b>"+a+" n&atilde;o foi localizado no mapa.</b><br>Arraste o marcador at&eacute; o local desejado.";lat=getMap().lat;lng=getMap().lng}w=new Marker(d,lat,lng,b,c);getMap().removeMarker(w);getMap().addMarker(w)})}}});var Polyline=Class.create({initialize:function(a,b,d,f,g,h,j){this.id=a;this.geographicPoints=b;this.isEnableEditing=j.isEnableEditing;if(h==PolylineType.straight){this.gPolyline=new GPolyline(b,d,f,g);this.refreshVertexes()}else{if(h==PolylineType.walk){for(var e=0,c=b.length;e<c-1;e++){this.addPolylineByWalk(a,d,f,g,b[e],b[e+1])}}}if(j.lengthListener!=null){this.lengthListener=j.lengthListener}},addPolylineByWalk:function(a,b,e,f,h,j){var c=[];var g="from: "+h.lat()+","+h.lng()+" to: "+j.lat()+","+j.lng();var d=new GDirections(null,document.getElementById("gDirDiv"));d.load(g,{getPolyline:"true",travelMode:G_TRAVEL_MODE_WALKING,avoidHighways:"true"});GEvent.addListener(d,"load",function(){var k=d.getPolyline();for(i=0;i<k.getVertexCount();i++){c.push(k.getVertex(i))}getMap().addPolyline(new Polyline(a,c,b,e,f,PolylineType.straight,{}))})},addGeographicPoint:function(b,a){this.geographicPoints.push(b);this.gPolyline.insertVertex(a,b)},removeGeographicPoint:function(a){var c=this.gPolyline.getVertex(a);var b=[];while(this.geographicPoints.length>0){_geographicPoint=this.geographicPoints.pop();if((c.lat()==_geographicPoint.lat())&&(c.lng()==_geographicPoint.lng())){break}else{b.push(_geographicPoint)}}this.geographicPoints=this.geographicPoints.concat(b);if(this.geographicPoints.length<=1){getMap().removePolyline(this)}this.gPolyline.deleteVertex(a)},refreshVertexes:function(){this.path="";this.length=0;this.geographicPoints=[];for(var a=0,b=this.gPolyline.getVertexCount();a<b;a++){var c=this.gPolyline.getVertex(a);this.path+=c.lat()+","+c.lng()+";";this.geographicPoints.push(c)}if(this.path!=""){this.path=this.path.substring(0,this.path.lastIndexOf(";"))}if(this.gPolyline.getLength()>0){this.length=(this.gPolyline.getLength()/1000)}if(this.lengthListener){$(this.lengthListener).value=this.length}},deleteVertex:function(a){if(typeof a=="number"){this.gPolyline.deleteVertex(a);this.refreshVertexes()}},enableEditing:function(){_gPolyline=this.gPolyline;_gPolyline.enableEditing({onEvent:"mouseover"});_gPolyline.disableEditing({onEvent:"mouseout"});_polyline=this;GEvent.addListener(_gPolyline,"click",function(b,a){_polyline.deleteVertex(a)});GEvent.addListener(_gPolyline,"lineupdated",function(){_polyline.refreshVertexes()})},enableDrawing:function(){_gPolyline=this.gPolyline;_gPolyline.enableDrawing();_polyline=this;GEvent.addListener(_gPolyline,"lineupdated",function(){_polyline.refreshVertexes()})}});var Polygon=Class.create({initialize:function(c,b){this.id=c;this.type=b.type;this.radius=0;this.vertices={};this.gPolygon=null;this.lineColor=b.lineColor;this.lineWidth=b.lineWidth;this.lineOpacity=b.lineOpacity;this.fillColor=b.fillColor;this.fillOpacity=b.fillOpacity;this.listeners=[];this.editionEnabled=false;var a=[];if(this.type==PolygonType.circular){this.radius=b.radius;this.drawGPolygon(PolygonProperties.circularNodes,a,b.lat,b.lng)}else{if(this.type==PolygonType.irregular){this.vertices=b.vertices;for(i=0;i<this.vertices.length;i++){a.push(new GLatLng(this.vertices[i][0],this.vertices[i][1]))}}}this.createGPolygon(a,true)},createGPolygon:function(b,a){if(b.length>3){if(a==true){b.push(b[0])}this.gPolygon=new GPolygon(b,this.lineColor,this.lineWidth,this.lineOpacity,this.fillColor,this.fillOpacity)}},drawGPolygon:function(c,k,h,b){var l=this.radius/1000;var a=new GLatLng(h,b);var f=a.distanceFrom(new GLatLng(a.lat()+0.1,a.lng()))/100;var j=a.distanceFrom(new GLatLng(a.lat(),a.lng()+0.1))/100;var d=parseInt(360/c)||10;for(var g=0;g<=360;g+=d){var e=new GLatLng(a.lat()+(l/f*Math.cos(g*Math.PI/180)),a.lng()+(l/j*Math.sin(g*Math.PI/180)));k.push(e)}},redraw:function(b,c){var a=[];if(this.type==PolygonType.circular){this.drawGPolygon(PolygonProperties.circularNodes,a,b,c);this.createGPolygon(a,true)}else{this.radius=PolygonProperties.defaultRadius;this.drawGPolygon(PolygonProperties.blankIrregularNodes,a,b,c);this.createGPolygon(a,false)}getMap().gMap.addOverlay(this.gPolygon);if(this.type==PolygonType.irregular){this.enableEditing(this.editionEnabled)}},enableEditing:function(a){_gPolygon=this.gPolygon;var b=this;if(a==true&&this.type==PolygonType.irregular){_gPolygon.enableEditing({onEvent:"mouseover"});_gPolygon.disableEditing({onEvent:"mouseout"});this.listeners.clear();this.listeners.push(GEvent.addListener(_gPolygon,"click",function(d,c){b.deleteVertex(c)}))}else{_gPolygon.disableEditing()}this.editionEnabled=a},deleteVertex:function(a){if(typeof a=="number"){this.gPolygon.deleteVertex(a)}},getIrregularVertices:function(){var currentVertex;var latLngArray=new Array(this.gPolygon.getVertexCount());if(this.type==PolygonType.irregular){for(var i=0;i<this.gPolygon.getVertexCount();i++){currentVertex=this.gPolygon.getVertex(i);latLngArray[i]=new Array(2);latLngArray[i][0]=currentVertex.lat();latLngArray[i][1]=currentVertex.lng()}}return eval(JSON.stringify(latLngArray))}});var Label=new Class.create({initialize:function(f,d,b,c,e,a){this.Overlay=function(){this.id=f;this.content=d;this.backgroundColor=b;this.fontColor=c;this.fontSize=e;this.fontWeight=a;this.padding=5;this.div=null;this.map=null;this.marker=null};this.Overlay.prototype=new google.maps.Overlay();this.Overlay.prototype={initialize:function(g){this.div=document.createElement("div");this.div.id=this.id;this.div.className="label";this.div.style.position="absolute";this.div.style.padding="2px";this.div.style.zIndex="-1";this.div.style.visibility="visible";this.div.style.lineHeight=this.fontSize+"px";this.div.style.opacity="0.8";this.div.style.MozOpacity="0.8";this.div.style.filter="alpha(opacity=80)";this.div.style.color=this.fontColor;this.div.style.fontSize=this.fontSize+"px";this.div.style.fontWeight=this.fontWeight;this.div.style.fontFamily="Arial";this.div.style.backgroundColor="#FFFFFF";this.div.style.border="2px solid "+this.backgroundColor;this.div.appendChild(document.createTextNode(this.content));g.getPane(G_MAP_FLOAT_PANE).appendChild(this.div);this.map=g},redraw:function(k){var h=this.map.fromLatLngToDivPixel(this.marker.gMarker.getPoint());var g=this.marker.gMarker.getIcon().iconAnchor;var l=Math.round(h.x-this.div.clientWidth/2);var j=h.y-g.y-this.div.clientHeight-this.padding;this.div.style.top=j+"px";this.div.style.left=l+"px"},copy:function(){return new this.Overlay(this.id,this.content,this.backgroundColor,this.fontColor,this.fontSize,this.fontWeight)},remove:function(){this.div.parentNode.removeChild(this.div)}};this.instance=new this.Overlay(f,d,b,c,e,a)},redraw:function(a){this.instance.redraw(a)},copy:function(){return this.instance.copy()},remove:function(){this.instance.remove()},show:function(){this.instance.div.style.visibility="visible"},hide:function(){this.instance.div.style.visibility="hidden"},setMarker:function(a){this.instance.marker=a}});PolylineType={straight:1,walk:2};PolygonType={circular:1,irregular:2};PolygonProperties={circularNodes:40,blankIrregularNodes:4,defaultRadius:100};function getMap(){return _map}function getGIcon(b){var a=null;if(b!=null){a=new GIcon();a.image=getImagesPath()+b;if(b.substring(0,2)=="bn"||b.substring(0,2)=="bs"){if(b.search(/bn/)!=-1){width=20;height=30;a.shadow=getImagesPath()+"bns.png";a.shadowSize=new GSize(35,30)}else{width=14;height=22;a.shadow=getImagesPath()+"bss.png";a.shadowSize=new GSize(25,22)}a.iconSize=new GSize(width,height);a.iconAnchor=new GPoint(width/2,height);a.infoWindowAnchor=getInfoAnchor(height)}else{if(b.substring(0,2)=="bi"){width=32;height=32;a.iconSize=new GSize(width,height);a.iconAnchor=new GPoint(0,32);a.infoWindowAnchor=new GPoint(30,1);a.shadow=getImagesPath()+"bis.png";a.shadowSize=new GSize(48,32)}else{if(b.substring(0,5)=="busof"){width=20;height=18;a.shadow=getImagesPath()+"busofs.png";a.iconSize=new GSize(width,height);a.iconAnchor=new GPoint(width/2,height);a.shadowSize=new GSize(29,18);a.infoWindowAnchor=getInfoAnchor(height)}else{if(b.substring(0,4)=="csbb"){width=11;height=11;a.iconSize=new GSize(width,height);a.iconAnchor=new GPoint(width/2,height);a.infoWindowAnchor=getInfoAnchor(height)}else{if(b.substring(0,7)=="cno-bus"||b.substring(0,7)=="cng-bus"){width=24;height=24;a.iconSize=new GSize(width,height);a.iconAnchor=new GPoint(width/2,height);a.infoWindowAnchor=getInfoAnchor(height)}else{alert("Imagem n&atilde; encontrada: "+a.image)}}}}}}return a}function getImagesPath(){return getContextURL()+"images/maps/"}function getContextURL(){var a=null;try{a=document.getElementsByTagName("base")[0].href}catch(b){alert("Por favor, defina a tag <base href> na sua pagina")}return a}function getInfoAnchor(b){var a=b/3;a=Math.floor(a);return new GPoint(a,5)};
