
function WfMarker(source_url,direction_url){if(source_url==null)
source_url='json/weatherstation.php';if(direction_url==null)
direction_url='images/windIcons/';this.source_url=source_url;this.img_src=direction_url;this.autoreload_timeout=60000;this.default_timeout=150;this.max_marker_count=300;this.marker_width=40;this.marker_height=40;}
WfMarker.prototype=new GOverlay();WfMarker.prototype.SetPos=function(marker){if(marker.weatherstation){var div_pos=this.map.fromLatLngToDivPixel(marker.latlng);marker.div.style.left=12+div_pos.x-this.marker_width/2+"px";marker.div.style.top=div_pos.y-this.marker_height/2+"px";}}
WfMarker.prototype.ClearMarkers=function(){for(i=0;i<this.max_marker_count;i++){var x=this.markers[i];if(x.weatherstation){x.weatherstation=null;x.div.parentNode.removeChild(x.div);}}}
WfMarker.prototype.RemoveMarkers=function(){for(i=0;i<this.max_marker_count;i++){var x=this.markers[i];x.img.parentNode.removeChild(x.img);x.spd.parentNode.removeChild(x.spd);if(x.div.parentNode){x.div.parentNode.removeChild(x.div);}
x.weatherstation=null;x.img.onclick=null;}
this.markers.length=0;this.markers=null;}
WfMarker.prototype.MarkerClicked=function(marker){GEvent.trigger(this,'click',marker);}
WfMarker.prototype.MarkerHover=function(marker){GEvent.trigger(this,'mouseover',marker);}
WfMarker.prototype.MarkerHoverOut=function(marker){GEvent.trigger(this,'mouseout',marker);}
WfMarker.prototype.CallInProgress=function(request){switch(request.transport.readyState){case 1:case 2:case 3:return true;break;default:return false;break;}}
WfMarker.prototype.OnLoadMarkers=function(request,json){if(this.loadingControl){this.map.removeControl(this.loadingControl);}
GEvent.trigger(this,"before_marker_load",eval("("+request.responseText+")"));this.LoadMarkers(request,json);GEvent.trigger(this,"after_marker_load",eval("("+request.responseText+")"));}
WfMarker.prototype.LoadMarkers=function(request,json){}
WfMarker.prototype.SetImageSrc=function(img,src){if(document.all&&/\.png$/.test(src.toLowerCase())){img.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, src='"+src+"')";img.src='http://mapper.weatherflow.com/images/windIcons/blank.gif';}else{img.src=src;}}
WfMarker.prototype.Autoreload=function(){if(this.map){this.RequestMarkers();setTimeout(this.AutoreloadHandler,this.autoreload_timeout);}}
WfMarker.prototype.MapMoveEnd=function(){this.StartRequestTimeout();}
WfMarker.prototype.StartRequestTimeout=function(){if(this.reloadTimerID){clearTimeout(this.reloadTimerID);this.reloadTimerID=0;}
this.reloadTimerID=setTimeout(this.RequestMarkersHandler,this.default_timeout);}
WfMarker.prototype.RequestMarkers=function(){if(this.loadingControl){this.map.addControl(this.loadingControl);}
if(this.markerRequest&&this.CallInProgress(this.markerRequest)){this.markerRequest.transport.abort();this.markerRequest=null;}
this.reloadTimerID=0;var bounds=this.map.getBounds();var northEast=bounds.getNorthEast();var southWest=bounds.getSouthWest();center=this.map.getCenter();var url=this.source_url;var pars='minLat='+southWest.lat();pars+='&minLon='+southWest.lng();pars+='&maxLat='+northEast.lat();pars+='&maxLon='+northEast.lng();pars+='&zoomLevel='+this.map.getZoom();this.markerRequest=new Ajax.Request(url,{method:'get',parameters:pars,onComplete:this.LoadMarkersHandler});}
WfMarker.prototype.initialize=function(map){this.map=map;this.map_pane=map.getPane(G_MAP_MARKER_MOUSE_TARGET_PANE);this.RequestMarkersHandler=GEvent.callback(this,this.RequestMarkers);this.LoadMarkersHandler=GEvent.callback(this,this.OnLoadMarkers);this.AutoreloadHandler=GEvent.callback(this,this.Autoreload);this.loadingControl=null;try{this.loadingControl=new Loading();}catch(err){}
this.markers=new Array();for(var i=0;i<this.max_marker_count;i++){var m={div:document.createElement("div"),img:document.createElement("img"),spd:document.createElement("div")}
m.div.style.position="absolute";m.div.style.width=this.marker_width+"px";m.div.style.height=this.marker_height+"px";m.div.style.visibility="visible";if(document.all){m.div.onselectstart=function(){return false;}
m.div.ondragstart=function(){return false;}}else{m.div.style.MozUserSelect='none';}
m.img.style.position="absolute";m.img.style.top="0px";m.img.style.left="0px";m.img.onclick=GEvent.callbackArgs(this,this.MarkerHover,m);m.img.onmouseover=null;m.img.onmouseout=GEvent.callbackArgs(m.img,this.MarkerHoverOut,m);if(document.all){m.img.style.cursor="hand";m.img.onselectstart=function(){return false;}
m.img.ondragstart=function(){return false;}}else{m.img.style.cursor="pointer";m.img.style.MozUserSelect='none';}
m.spd.style.position="relative";m.spd.style.top="30%";m.spd.style.left="0px";m.spd.style.width=this.marker_width+"px";m.spd.style.height=this.marker_height+"px";m.spd.style.textAlign="center";m.spd.style.visibility="visible";m.spd.onclick=GEvent.callbackArgs(this,this.MarkerHover,m);m.spd.onmouseover=null;m.spd.onmouseout=GEvent.callbackArgs(this,this.MarkerHoverOut,m);if(document.all){m.spd.style.cursor="hand";m.spd.onselectstart=function(){return false;}
m.spd.ondragstart=function(){return false;}}else{m.spd.style.cursor="pointer";m.spd.style.MozUserSelect='none';}
m.div.appendChild(m.img);m.div.appendChild(m.spd);m.div.onclick=GEvent.callbackArgs(this,this.MarkerHover,m);m.div.onmouseover=null;m.div.onmouseout=GEvent.callbackArgs(m.img,this.MarkerHoverOut,m);this.markers.push(m);}
this.moveendBind=GEvent.bind(this.map,"moveend",this,this.MapMoveEnd);this.Autoreload();}
WfMarker.prototype.remove=function(){this.RemoveMarkers();this.map=null;GEvent.removeListener(this.moveendBind);}
WfMarker.prototype.copy=function(){return new WfMarker(this.source_url);}
WfMarker.prototype.redraw=function(force){if(!force)return;for(var i=0;i<this.markers.length;i++){if(this.markers[i].weatherstation)
this.SetPos(this.markers[i]);}}
