﻿var gmaps=undefined;if(typeof(google)!="undefined"&&typeof(google.maps)!="undefined"&&typeof(google.maps.Map)!="undefined"){gmaps=google.maps}function RichMarker(b){var a=b||{};this.ready_=false;this.dragging_=false;if(b.visible==undefined){b.visible=true}if(b.shadow==undefined){b.shadow="7px -3px 5px rgba(88,88,88,0.7)"}if(b.anchor==undefined){b.anchor=RichMarkerPosition.BOTTOM}this.setValues(a)}if(gmaps){RichMarker.prototype=new gmaps.OverlayView()}window.RichMarker=RichMarker;RichMarker.prototype.getVisible=function(){return(this.get("visible"))};RichMarker.prototype.getVisible=RichMarker.prototype.getVisible;RichMarker.prototype.setVisible=function(a){this.set("visible",a)};RichMarker.prototype.setVisible=RichMarker.prototype.setVisible;RichMarker.prototype.visible_changed=function(){if(this.ready_){this.markerWrapper_.style.display=this.getVisible()?"":"none";this.draw()}};RichMarker.prototype.visible_changed=RichMarker.prototype.visible_changed;RichMarker.prototype.setFlat=function(a){this.set("flat",!!a)};RichMarker.prototype.setFlat=RichMarker.prototype.setFlat;RichMarker.prototype.getFlat=function(){return(this.get("flat"))};RichMarker.prototype.getFlat=RichMarker.prototype.getFlat;RichMarker.prototype.getWidth=function(){return(this.get("width"))};RichMarker.prototype.getWidth=RichMarker.prototype.getWidth;RichMarker.prototype.getHeight=function(){return(this.get("height"))};RichMarker.prototype.getHeight=RichMarker.prototype.getHeight;RichMarker.prototype.setShadow=function(a){this.set("shadow",a);this.flat_changed()};RichMarker.prototype.setShadow=RichMarker.prototype.setShadow;RichMarker.prototype.getShadow=function(){return(this.get("shadow"))};RichMarker.prototype.getShadow=RichMarker.prototype.getShadow;RichMarker.prototype.flat_changed=function(){if(!this.ready_){return}this.markerWrapper_.style.boxShadow=this.markerWrapper_.style.webkitBoxShadow=this.markerWrapper_.style.MozBoxShadow=this.getFlat()?"":this.getShadow()};RichMarker.prototype.flat_changed=RichMarker.prototype.flat_changed;RichMarker.prototype.setZIndex=function(a){this.set("zIndex",a)};RichMarker.prototype.setZIndex=RichMarker.prototype.setZIndex;RichMarker.prototype.getZIndex=function(){return(this.get("zIndex"))};RichMarker.prototype.getZIndex=RichMarker.prototype.getZIndex;RichMarker.prototype.zIndex_changed=function(){if(this.getZIndex()&&this.ready_){this.markerWrapper_.style.zIndex=this.getZIndex()}};RichMarker.prototype.zIndex_changed=RichMarker.prototype.zIndex_changed;RichMarker.prototype.getDraggable=function(){return(this.get("draggable"))};RichMarker.prototype.getDraggable=RichMarker.prototype.getDraggable;RichMarker.prototype.setDraggable=function(a){this.set("draggable",!!a)};RichMarker.prototype.setDraggable=RichMarker.prototype.setDraggable;RichMarker.prototype.draggable_changed=function(){if(this.ready_){if(this.getDraggable()){this.addDragging_(this.markerWrapper_)}else{this.removeDragListeners_()}}};RichMarker.prototype.draggable_changed=RichMarker.prototype.draggable_changed;RichMarker.prototype.getPosition=function(){return(this.get("position"))};RichMarker.prototype.getPosition=RichMarker.prototype.getPosition;RichMarker.prototype.setPosition=function(a){this.set("position",a)};RichMarker.prototype.setPosition=RichMarker.prototype.setPosition;RichMarker.prototype.position_changed=function(){this.draw()};RichMarker.prototype.position_changed=RichMarker.prototype.position_changed;RichMarker.prototype.getAnchor=function(){return(this.get("anchor"))};RichMarker.prototype.getAnchor=RichMarker.prototype.getAnchor;RichMarker.prototype.setAnchor=function(a){this.set("anchor",a)};RichMarker.prototype.setAnchor=RichMarker.prototype.setAnchor;RichMarker.prototype.anchor_changed=function(){this.draw()};RichMarker.prototype.anchor_changed=RichMarker.prototype.anchor_changed;RichMarker.prototype.htmlToDocumentFragment_=function(c){var b=document.createElement("DIV");b.innerHTML=c;if(b.childNodes.length==1){return(b.removeChild(b.firstChild))}else{var a=document.createDocumentFragment();while(b.firstChild){a.appendChild(b.firstChild)}return a}};RichMarker.prototype.removeChildren_=function(a){if(!a){return}var b;while(b=a.firstChild){a.removeChild(b)}};RichMarker.prototype.setContent=function(a){this.set("content",a)};RichMarker.prototype.setContent=RichMarker.prototype.setContent;RichMarker.prototype.getContent=function(){return(this.get("content"))};RichMarker.prototype.getContent=RichMarker.prototype.getContent;RichMarker.prototype.content_changed=function(){if(!this.markerContent_){return}this.removeChildren_(this.markerContent_);var d=this.getContent();if(d){if(typeof d=="string"){d=d.replace(/^\s*([\S\s]*)\b\s*$/,"$1");d=this.htmlToDocumentFragment_(d)}this.markerContent_.appendChild(d);var c=this;var a=this.markerContent_.getElementsByTagName("IMG");for(var b=0,e;e=a[b];b++){gmaps.event.addDomListener(e,"mousedown",function(f){if(c.getDraggable()){if(f.preventDefault){f.preventDefault()}f.returnValue=false}});gmaps.event.addDomListener(e,"load",function(){c.draw()})}gmaps.event.trigger(this,"domready")}if(this.ready_){this.draw()}};RichMarker.prototype.content_changed=RichMarker.prototype.content_changed;RichMarker.prototype.setCursor_=function(a){if(!this.ready_){return}var b="";if(navigator.userAgent.indexOf("Gecko/")!==-1){if(a=="dragging"){b="-moz-grabbing"}if(a=="dragready"){b="-moz-grab"}if(a=="draggable"){b="pointer"}}else{if(a=="dragging"||a=="dragready"){b="move"}if(a=="draggable"){b="pointer"}}if(this.markerWrapper_.style.cursor!=b){this.markerWrapper_.style.cursor=b}};RichMarker.prototype.startDrag=function(b){if(!this.getDraggable()){return}if(!this.dragging_){this.dragging_=true;var a=this.getMap();this.mapDraggable_=a.get("draggable");a.set("draggable",false);this.mouseX_=b.clientX;this.mouseY_=b.clientY;this.setCursor_("dragready");this.markerWrapper_.style.MozUserSelect="none";this.markerWrapper_.style.KhtmlUserSelect="none";this.markerWrapper_.style.WebkitUserSelect="none";this.markerWrapper_.unselectable="on";this.markerWrapper_.onselectstart=function(){return false};this.addDraggingListeners_();gmaps.event.trigger(this,"dragstart")}};RichMarker.prototype.stopDrag=function(){if(!this.getDraggable()){return}if(this.dragging_){this.dragging_=false;this.getMap().set("draggable",this.mapDraggable_);this.mouseX_=this.mouseY_=this.mapDraggable_=null;this.markerWrapper_.style.MozUserSelect="";this.markerWrapper_.style.KhtmlUserSelect="";this.markerWrapper_.style.WebkitUserSelect="";this.markerWrapper_.unselectable="off";this.markerWrapper_.onselectstart=function(){};this.removeDraggingListeners_();this.setCursor_("draggable");gmaps.event.trigger(this,"dragend");this.draw()}};RichMarker.prototype.drag=function(h){if(!this.getDraggable()||!this.dragging_){this.stopDrag();return}var d=this.mouseX_-h.clientX;var c=this.mouseY_-h.clientY;this.mouseX_=h.clientX;this.mouseY_=h.clientY;var g=parseInt(this.markerWrapper_.style.left,10)-d;var f=parseInt(this.markerWrapper_.style.top,10)-c;this.markerWrapper_.style.left=g+"px";this.markerWrapper_.style.top=f+"px";var i=this.getOffset_();var b=new gmaps.Point(g-i.width,f-i.height);var a=this.getProjection();this.setPosition(a.fromDivPixelToLatLng(b));this.setCursor_("dragging");gmaps.event.trigger(this,"drag")};RichMarker.prototype.removeDragListeners_=function(){if(this.draggableListener_){gmaps.event.removeListener(this.draggableListener_);delete this.draggableListener_}this.setCursor_("")};RichMarker.prototype.addDragging_=function(b){if(!b){return}var a=this;this.draggableListener_=gmaps.event.addDomListener(b,"mousedown",function(c){a.startDrag(c)});this.setCursor_("draggable")};RichMarker.prototype.addDraggingListeners_=function(){var a=this;if(this.markerWrapper_.setCapture){this.markerWrapper_.setCapture(true);this.draggingListeners_=[gmaps.event.addDomListener(this.markerWrapper_,"mousemove",function(b){a.drag(b)},true),gmaps.event.addDomListener(this.markerWrapper_,"mouseup",function(){a.stopDrag();a.markerWrapper_.releaseCapture()},true)]}else{this.draggingListeners_=[gmaps.event.addDomListener(window,"mousemove",function(b){a.drag(b)},true),gmaps.event.addDomListener(window,"mouseup",function(){a.stopDrag()},true)]}};RichMarker.prototype.removeDraggingListeners_=function(){if(this.draggingListeners_){for(var a=0,b;b=this.draggingListeners_[a];a++){gmaps.event.removeListener(b)}this.draggingListeners_.length=0}};RichMarker.prototype.getOffset_=function(){var b=this.getAnchor();if(typeof b=="object"){return(b)}var d=new gmaps.Size(0,0);if(!this.markerContent_){return d}var c=this.markerContent_.offsetWidth;var a=this.markerContent_.offsetHeight;switch(b){case RichMarkerPosition.TOP_LEFT:break;case RichMarkerPosition.TOP:d.width=-c/2;break;case RichMarkerPosition.TOP_RIGHT:d.width=-c;break;case RichMarkerPosition.LEFT:d.height=-a/2;break;case RichMarkerPosition.MIDDLE:d.width=-c/2;d.height=-a/2;break;case RichMarkerPosition.RIGHT:d.width=-c;d.height=-a/2;break;case RichMarkerPosition.BOTTOM_LEFT:d.height=-a;break;case RichMarkerPosition.BOTTOM:d.width=-c/2;d.height=-a;break;case RichMarkerPosition.BOTTOM_RIGHT:d.width=-c;d.height=-a;break}return d};RichMarker.prototype.onAdd=function(){if(!this.markerWrapper_){this.markerWrapper_=document.createElement("DIV");this.markerWrapper_.style.position="absolute"}if(this.getZIndex()){this.markerWrapper_.style.zIndex=this.getZIndex()}this.markerWrapper_.style.display=this.getVisible()?"":"none";if(!this.markerContent_){this.markerContent_=document.createElement("DIV");this.markerWrapper_.appendChild(this.markerContent_);var b=this;gmaps.event.addDomListener(this.markerContent_,"click",function(c){gmaps.event.trigger(b,"click",c)});gmaps.event.addDomListener(this.markerContent_,"dblclick",function(c){gmaps.event.trigger(b,"dblclick",c)});gmaps.event.addDomListener(this.markerContent_,"mousedown",function(c){gmaps.event.trigger(b,"mousedown",c)});gmaps.event.addDomListener(this.markerContent_,"mouseout",function(c){if(!b.dragging_){b.setCursor_("")}gmaps.event.trigger(b,"mouseout",c)});gmaps.event.addDomListener(this.markerContent_,"mouseover",function(c){if(!b.dragging_){b.setCursor_("draggable")}gmaps.event.trigger(b,"mouseover",c)});gmaps.event.addDomListener(this.markerContent_,"mouseup",function(c){gmaps.event.trigger(b,"mouseup",c)})}this.ready_=true;this.content_changed();this.flat_changed();this.draggable_changed();var a=this.getPanes();if(a){a.overlayImage.appendChild(this.markerWrapper_)}gmaps.event.trigger(this,"ready")};RichMarker.prototype.onAdd=RichMarker.prototype.onAdd;RichMarker.prototype.draw=function(){if(!this.ready_||this.dragging_){return}var b=this.getProjection();if(!b){return}var d=(this.get("position"));var f=b.fromLatLngToDivPixel(d);var e=this.getOffset_();this.markerWrapper_.style.top=(f.y+e.height)+"px";this.markerWrapper_.style.left=(f.x+e.width)+"px";var a=this.markerContent_.offsetHeight;var c=this.markerContent_.offsetWidth;if(c!=this.get("width")){this.set("width",c)}if(a!=this.get("height")){this.set("height",a)}};RichMarker.prototype.draw=RichMarker.prototype.draw;RichMarker.prototype.onRemove=function(){if(this.markerWrapper_&&this.markerWrapper_.parentNode){this.markerWrapper_.parentNode.removeChild(this.markerWrapper_)}this.removeDragListeners_()};RichMarker.prototype.onRemove=RichMarker.prototype.onRemove;var RichMarkerPosition={TOP_LEFT:1,TOP:2,TOP_RIGHT:3,LEFT:4,MIDDLE:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM:8,BOTTOM_RIGHT:9};window.RichMarkerPosition=RichMarkerPosition;
