
function AjaxRequest(){if(window.XMLHttpRequest)
this._request=new XMLHttpRequest();else if(window.ActiveXObject)
this._request=new ActiveXObject("Microsoft.XMLHTTP");else
return null;}
AjaxRequest.prototype.abort=function(){this._reponse=null;this._onDataRetrieved=null;this._request.abort();}
AjaxRequest.prototype.asyncRequest=function(method,url,params,onData){this.url=url;if(arguments.length==3){if(typeof arguments[2]=='function'){onData=arguments[2];params=false;}}
if(onData)this.onData=onData;method?method=method.toUpperCase():method="GET";var fullURL=url;if(method=="GET"){if(params)fullURL+="?"+params;this._request.open(method,fullURL,true);var _this=this;this._request.onreadystatechange=function(){if(_this._onDataRetrieved)_this._onDataRetrieved()};this._request.send(null);}else if(method=="POST"){this._request.open(method,fullURL,true);var _this=this;if(params){this._request.setRequestHeader('Content-type','application/x-www-form-urlencoded');this._request.setRequestHeader('Content-length',params.length);this._request.setRequestHeader('Connection','close');this._request.onreadystatechange=function(){if(_this._onDataRetrieved)_this._onDataRetrieved()};this._request.send(params);}else{this._request.send(null);}}}
AjaxRequest.prototype.syncRequest=function(method,url,params){method?method=method.toUpperCase():method="GET";var fullURL=url;if(method=="GET"){if(params)fullURL+="?"+params;this._request.open(method,fullURL,false);this._request.send(null);}else if(method=="POST"){this._request.open(method,fullURL,false);if(params){this._request.setRequestHeader("Cache-Control","no-store");this._request.setRequestHeader('Content-type','application/x-www-form-urlencoded');this._request.setRequestHeader('Connection','close');this._request.setRequestHeader('Content-length',params.length);this._request.send(params);}else{this._request.send(null);}}
if(this._onDataRetrieved)this._onDataRetrieved();}
AjaxRequest.prototype._onDataRetrieved=function(){if(this._request.readyState==4){if(this._request.status==200){this._response=this._request.responseText;if(this.onData){this.onData(this);this.onData=null;}}else{this._response="An error occurred retrieving data: "+this._request.status;}}}
AjaxRequest.prototype.getResponseText=function(){return this._response;}
AjaxRequest.prototype.getResponseXML=function(){var theDocument=false;if(window.ActiveXObject){try{theDocument=new ActiveXObject("Microsoft.XMLDOM");theDocument.async=false;theDocument.loadXML(this._response);}catch(e){alert("Error parsing XML.");return false;}}else if(window.XMLHttpRequest){try{var parser=new DOMParser();theDocument=parser.parseFromString(this._response,"text/xml");}catch(e){alert("Error parsing XML.");return false;}}
return theDocument;}
function ImageCache(map){this.map=map;this.cache=new Object();this.temp_cache=new Object();}
ImageCache.prototype.addImage=function addImage(src,imageElement){if(imageElement.loading){this.map.imagesToLoad--;if(this.map.imagesToLoad<=0){this.map.imagesDoneLoading();}}
if(this.map.imagesToLoad<0)this.map.imagesToLoad=0;var image=document.createElement('img');var _this=this;imageElement.loading=true;image.imageElement=imageElement;image.onload=function(event){_this.onload(event,this);}
image.onerror=function(event){_this.onerror(event,this);}
image.onabort=function(event){_this.onabort(event,this);}
image.src=src;this.temp_cache[src]=image;this.map.imagesToLoad++;if(this.map.imagesToLoad>0)
this.map.imagesLoading();return this.temp_cache[src];}
ImageCache.prototype.getImage=function getImage(src){if(this.cache[src]){this.map.imagesToLoad--;if(this.map.imagesToLoad<=0)
this.map.imagesDoneLoading();return this.cache[src];}else{return false;}}
ImageCache.prototype.onerror=function(event,image){this.map.imagesToLoad--;image.imageElement.loading=null;if(this.map.imagesToLoad<=0){this.map.imagesDoneLoading();}}
ImageCache.prototype.onabort=function(event,image){this.map.imagesToLoad--;image.imageElement.loading=null;if(this.map.imagesToLoad<=0)
this.map.imagesDoneLoading();}
ImageCache.prototype.cancelLoad=function(imageElement){if(this.cache){if(this.cache[imageElement.src]){this.cache[imageElement.src].onload=null;this.cache[imageElement.src].imageElement=null;this.cache[imageElement.src]=null;}}}
ImageCache.prototype.cancelAllLoads=function(){for(var i in this.cache){if(this.cache[i]&&this.cache[i].onload!=null){this.cache[i].onload=null;this.cache[i].imageElement=null;this.cache[i]=null;}}}
ImageCache.prototype.reload=function(_this,src,imageElement){_this.cancelLoad(imageElement);_this.addImage(src,imageElement);}
ImageCache.prototype.onload=function(event,image){this.cache[image.src]=this.temp_cache[image.src];image.imageElement.src=image.src;image.onload=null;image.imageElement.loading=null;this.map.imagesToLoad--;if(this.map.imagesToLoad<=0){this.map.imagesDoneLoading();}
this.temp_cache[image.src]=null;}
ImageCache.prototype.kill=function(){for(var i in this.cache){if(this.cache[i]){this.cache[i].imageElement=null;this.cache[i].onload=null;this.cache[i].onerror=null;this.cache[i].onabort=null;this.cache[i]=null;}}
this.map=null;this.cache=null}
function ImageLoader(map){this.image=document.createElement('img');this.map=map;}
ImageLoader.prototype.loadImage=function(src,imageElement){var _this=this;this.image.imageElement=imageElement;if(imageElement.loading){this.map.imagesToLoad--;if(this.map.imagesToLoad<=0){this.map.imagesDoneLoading();}}
if(this.map.imagesToLoad<0)this.map.imagesToLoad=0;imageElement.loading=true;this.image.onload=function(event){_this.onload(event,this);}
this.image.onerror=function(event){_this.onerror(event,this);}
this.image.onabort=function(event){_this.onabort(event,this);}
this.image.src=src;this.map.imagesToLoad++;if(this.map.imagesToLoad>0)
this.map.imagesLoading();return this.image;}
ImageLoader.prototype.onload=function(event,image){image.imageElement.src=image.src;image.imageElement.loading=null;image.onload=null;this.map.imagesToLoad--;if(this.map.imagesToLoad<=0){this.map.imagesDoneLoading();}}
ImageLoader.prototype.onerror=function(event,image){this.map.imagesToLoad--;image.imageElement.loading=null;if(this.map.imagesToLoad<=0){this.map.imagesDoneLoading();}}
ImageLoader.prototype.onabort=function(event,image){this.map.imagesToLoad--;image.imageElement.loading=null;if(this.map.imagesToLoad<=0){this.map.imagesDoneLoading();}}
ImageLoader.prototype.kill=function(){this.image=null;}
var prop_enum=[];document.write(' <!--[if IE]> '+'<xml:namespace ns="urn:schemas-microsoft-com:vml" prefix="v"/>'+'<style type="text/css">'+'v\\:* { behavior: url(#default#VML);}'+'</style>     '+'<![endif]-->  ');function JSDraw(canvas_width,canvas_height,container_element){this.width=canvas_width;this.height=canvas_height;this.x=0;this.y=0;this.container_element=container_element;this.isIE=(navigator.appName=='Microsoft Internet Explorer');if(this.isIE){prop_enum['fill']='fillcolor';prop_enum['stroke']='strokecolor';prop_enum['stroke-width']='strokeweight';prop_enum['stroke-opacity']='opacity';prop_enum['fill-opacity']='opacity';prop_enum['stroke-linecap']='endcap';prop_enum['stroke-linejoin']='joinstyle';prop_enum['stroke-miterlimit']='miterlimit';prop_enum['stroke-dasharray']='dashstyle';prop_enum['font-size']='fontSize';prop_enum['font-family']='fontFamily';this.board=document.createElement('div');this.board.style.width=this.width+'px';this.board.style.height=this.height+'px';this.board.style.overflow='hidden';this.board.style.className='map-pane';this.board.style.backgroundImage="url('scrollable_map/images/blank.gif')";this.board.position='relative';this.canvas=document.createElement('v:group');this.canvas.style.width=this.width+'px';this.canvas.style.height=this.height+'px';this.canvas.style.top='0px';this.canvas.style.left='0px';this.canvas.style.position='absolute';this.canvas.setAttribute('coordsize',this.width+' '+this.height);this.canvas.setAttribute('coordorigin','0, 0');this.canvas.style.visibility='visible';this.board.appendChild(this.canvas);if(this.container_element){this.container_element.appendChild(this.board);}else{document.body.appendChild(this.board);}}else{prop_enum['fill']='fill';prop_enum['stroke']='stroke';prop_enum['stroke-width']='stroke-width';prop_enum['stroke-opacity']='stroke-opacity';prop_enum['fill-opacity']='fill-opacity';prop_enum['stroke-linecap']='stroke-linecap';prop_enum['stroke-linejoin']='stroke-linejoin';prop_enum['stroke-miterlimit']='stroke-miterlimit';prop_enum['stroke-dasharray']='stroke-dasharray';this.canvas=document.createElementNS('http://www.w3.org/2000/svg','svg');this.canvas.setAttribute('width',(this.width+1));this.canvas.setAttribute('height',(this.height+1));this.canvas.setAttribute('viewBox','-0.5 -0.5 '+(this.width+1)+' '+(this.height+1));this.canvas.setAttribute('preserveAspectRatio',"xMidYMid slice");if(this.container_element){this.container_element.appendChild(this.canvas);}else{document.body.appendChild(this.canvas);}
this.board=this.canvas;}
this.shapes=[];}
JSDraw.prototype.moveBy=function(dx,dy){var left=parseInt(this.board.style.left.split('px')[0],10);var top=parseInt(this.board.style.top.split('px')[0],10);this.board.style.left=(left+dx)+'px';this.board.style.top=(top+dy)+'px';}
JSDraw.prototype.setViewBox=function(x,y,w,h){this.width=w;this.height=h;this.x=x;this.y=y;if(this.isIE){this.canvas.setAttribute('coordsize',w+' '+h);this.canvas.setAttribute('coordorigin',x+', '+y);}else{this.canvas.setAttribute('viewBox',(x-0.5)+' '+(y-0.5)+' '+(w+1)+' '+(h+1));}}
JSDraw.prototype.resize=function(w,h){this.width=w;this.height=h;if(this.isIE){this.canvas.style.width=this.width+'px';this.canvas.style.height=this.height+'px';}else{this.canvas.setAttribute('width',(this.width+1));this.canvas.setAttribute('height',(this.height+1));}}
JSDraw.prototype.moveViewBox=function(dx,dy){this.x-=dx;this.y-=dy;if(this.isIE){this.canvas.setAttribute('coordsize',this.width+' '+this.height);this.canvas.setAttribute('coordorigin',this.x+', '+this.y);}else{this.canvas.setAttribute('viewBox',(this.x-0.5)+' '+(this.y-0.5)+' '+(this.width+1)+' '+(this.height+1));}}
JSDraw.prototype.hide=function(){this.canvas.style.visibility='hidden';for(var i=0;i<this.shapes.length;i++){this.shapes[i].shape.style.visibility='hidden';}}
JSDraw.prototype.show=function(){this.canvas.style.visibility='visible';for(var i=0;i<this.shapes.length;i++){this.shapes[i].shape.style.visibility='visible';}}
JSDraw.prototype.circle=function(cx,cy,rad,properties,events){var o=new Ellipse(this,cx,cy,rad,rad,properties,events);this.shapes.push(o);return o;}
JSDraw.prototype.ellipse=function(cx,cy,rx,ry,properties,events){var o=new Ellipse(this,cx,cy,rx,ry,properties,events);this.shapes.push(o);return o;}
JSDraw.prototype.line=function(s_x,s_y,e_x,e_y,properties,events){var o=new PolyLine(this,[s_x,s_y,e_x,e_y],properties,events);this.shapes.push(o);return o;}
JSDraw.prototype.polyline=function(points,properties,events){var o=new PolyLine(this,points,properties,events);this.shapes.push(o);return o;}
JSDraw.prototype.rectangle=function(x,y,w,h,properties,events){var o=new PolyLine(this,[x,y,(x+w)-1,y,(x+w)-1,(y+h)-1,x,(y+h)-1],properties,events)
this.shapes.push(o);return o;}
JSDraw.prototype.roundedRectangle=function(x,y,w,h,rx,ry,properties,events){var o=new RoundedRectangle(this,x,y,w,h,rx,ry,properties,events);this.shapes.push(o);return o;}
JSDraw.prototype.polygon=function(points,properties,events){var o=new PolyLine(this,points,properties,events);this.shapes.push(o);return o;}
JSDraw.prototype.text=function(x,y,w,h,text,rot,properties,events){var o=new Text(this,x,y,w,h,text,rot,properties,events);this.shapes.push(o);return o;}
function setEventHandlers(obj){if(obj.events['onclick'])
obj.shape.onclick=function(event,point){obj.events['onclick'](event,obj);};if(obj.events['onmouseover'])
obj.shape.onmouseover=function(event,point){obj.events['onmouseover'](event,obj);};if(obj.events['onmouseout'])
obj.shape.onmouseout=function(event,point){obj.events['onmouseout'](event,obj);};if(obj.events['ondblclick'])
obj.shape.ondblclick=function(event,point){obj.events['ondblclick'](event,obj);};if(obj.events['onmousedown'])
obj.shape.onmousedown=function(event,point){obj.events['onmousedown'](event,obj);};if(obj.events['onmouseup'])
obj.shape.onmouseup=function(event,point){obj.events['onmouseup'](event,obj);};if(obj.events['onmousemove'])
obj.shape.onmousemove=function(event,point){obj.events['onmousemove'](event,obj);};}
function Ellipse(canvas,x,y,rx,ry,properties,events){this.canvas=canvas;this.events=events;this.properties=properties;this.x=x;this.y=y;this.rx=rx;this.ry=ry;if(this.canvas.isIE){this.shape=document.createElement('v:oval');this.fill=document.createElement('v:fill');this.fill.setAttribute('opacity',(this.properties['fill-opacity']||1.0));this.stroke=document.createElement('v:stroke');this.stroke.setAttribute('opacity',(this.properties['stroke-opacity']||1.0));this.stroke.setAttribute('dashstyle',(this.properties['stroke-dasharray']||'solid'));if(!this.properties||!this.properties['fill']||this.properties['fill']=='none'){this.fill.setAttribute('on','false');}
this.shape.appendChild(this.fill);this.shape.appendChild(this.stroke);this.shape.style.left=(x-(rx))+'px';this.shape.style.width=(rx*2)+'px';this.shape.style.top=(y-(ry))+'px';this.shape.style.height=(ry*2)+'px';}else{this.shape=document.createElementNS('http://www.w3.org/2000/svg','ellipse');this.shape.setAttribute('cx',x);this.shape.setAttribute('cy',y);this.shape.setAttribute('rx',rx);this.shape.setAttribute('ry',ry);if(!this.properties||!this.properties['fill']){this.shape.setAttribute('fill','none');}}
for(var x in this.properties){this.shape.setAttribute(prop_enum[x],this.properties[x]);}
if(this.events){setEventHandlers(this);}
this.canvas.canvas.appendChild(this.shape);}
Ellipse.prototype.moveTo=function(points){this.x=points[0];this.y=points[1];if(this.canvas.isIE){this.shape.style.left=(this.x-(this.rx))+'px';this.shape.style.top=(this.y-(this.ry))+'px';}else{this.shape.setAttribute('cx',this.x);this.shape.setAttribute('cy',this.y);}}
function PolyLine(canvas,points,properties,events){this.canvas=canvas;this.points=points;this.properties=properties;this.events=events;if(this.canvas.isIE){if(this.properties&&this.properties['stroke-linecap']=='butt')this.properties['stroke-linecap']='flat';this.shape=document.createElement('v:polyline');if(!this.properties||!this.properties['fill']||this.properties['fill']=='none'){this.shape.setAttribute('filled',false);}else{this.fill=document.createElement('v:fill');this.fill.setAttribute('opacity',((this.properties&&this.properties['fill-opacity'])||1.0));this.shape.appendChild(this.fill);}
this.shape.setAttribute('stroked',true);this.stroke=document.createElement('v:stroke');this.stroke.setAttribute('opacity',((this.properties&&this.properties['stroke-opacity'])||1.0));this.stroke.setAttribute('endcap',((this.properties&&this.properties['stroke-linecap'])||'square'));this.shape.appendChild(this.stroke);}else{this.shape=document.createElementNS('http://www.w3.org/2000/svg','polyline');}
this.shape.setAttribute(prop_enum['stroke'],((this.properties&&this.properties['stroke'])||'black'));this.shape.setAttribute(prop_enum['fill'],'none');this.shape.setAttribute('points',this.points.join());for(var x in this.properties){this.shape.setAttribute(prop_enum[x],this.properties[x]);}
if(this.events){setEventHandlers(this);}
this.canvas.canvas.appendChild(this.shape);}
PolyLine.prototype.moveTo=function(points){if(this.canvas.isIE){var pts=this.shape.getAttribute('points');pts.length;this.canvas.canvas.removeChild(this.shape);if(this.properties&&this.properties['stroke-linecap']=='butt')this.properties['stroke-linecap']='flat';this.shape=document.createElement('v:polyline');if(!this.properties||!this.properties['fill']||this.properties['fill']=='none'){this.shape.setAttribute('filled',false);}else{this.fill=document.createElement('v:fill');this.fill.setAttribute('opacity',((this.properties&&this.properties['fill-opacity'])||1.0));this.shape.appendChild(this.fill);}
this.shape.setAttribute('stroked',true);this.stroke=document.createElement('v:stroke');this.stroke.setAttribute('opacity',((this.properties&&this.properties['stroke-opacity'])||1.0));this.stroke.setAttribute('endcap',((this.properties&&this.properties['stroke-linecap'])||'square'));this.shape.appendChild(this.stroke);this.shape.setAttribute('points',points.join());for(var x in this.properties){this.shape.setAttribute(prop_enum[x],this.properties[x]);}
if(this.events){setEventHandlers(this);}
this.canvas.canvas.appendChild(this.shape);}else{this.shape.setAttribute('points',points.join());}}
function RoundedRectangle(canvas,x,y,w,h,rx,ry,properties,events){this.x=x;this.y=y;this.width=w;this.height=h;this.arc_x=rx;this.arc_y=ry;this.canvas=canvas;this.properties=properties;this.events=events;if(this.canvas.isIE){this.shape=document.createElement('v:roundrect');this.fill=document.createElement('v:fill');this.fill.setAttribute('opacity',(this.properties['fill-opacity']||1.0));if(!this.properties||!this.properties['fill']||this.properties['fill']=='none'){this.fill.setAttribute('on','false');}
this.stroke=document.createElement('v:stroke');this.stroke.setAttribute('opacity',(this.properties['stroke-opacity']||1.0));if(!this.properties||!this.properties['fill']||this.properties['fill']=='none'){this.fill.setAttribute('on','false');}
this.shape.appendChild(this.fill);this.shape.appendChild(this.stroke);var half_smaller_dim=(((w<h)?w:h)/2);var arcsize=((ry<rx)?ry:rx)/half_smaller_dim;this.shape.setAttribute('arcsize',arcsize);this.shape.style.top=y+'px';this.shape.style.left=x+'px';this.shape.style.height=h+'px';this.shape.style.width=w+'px';}else{this.shape=document.createElementNS('http://www.w3.org/2000/svg','rect');this.shape.setAttribute('x',x);this.shape.setAttribute('y',y);this.shape.setAttribute('width',w);this.shape.setAttribute('height',h);this.shape.setAttribute('rx',rx);this.shape.setAttribute('ry',ry);if(!this.properties||!this.properties['fill']){this.shape.setAttribute('fill','none');}}
for(var x in this.properties){this.shape.setAttribute(prop_enum[x],this.properties[x]);}
if(this.events){setEventHandlers(this);}
this.canvas.canvas.appendChild(this.shape);}
RoundedRectangle.prototype.moveBy=function(dx,dy){}
function Text(canvas,x,y,w,h,content,rot,properties,events){this.canvas=canvas;this.properties=properties;this.events=events;this.fontsize=(properties)?properties['font-size']:12;if(this.canvas.isIE){this.shape=document.createElement('v:shape');this.shape.setAttribute('fill','none');this.textbox=document.createElement('v:textbox');this.textbox.setAttribute('fill','none');this.text=document.createElement('div');this.text.style.backgroundColor='transparent';this.text.style.valign='bottom';this.text.innerHTML=content;this.textbox.appendChild(this.text);this.shape.style.top=(y-(this.fontsize/2))+'px';this.shape.style.left=(x-7)+'px';this.shape.style.height=h+'px';this.shape.style.width=w+'px';if(rot>0){this.text.style.writingMode="tb-rl";this.shape.style.top=(y)+'px';this.shape.style.left=(x-w+20)+'px';}
for(var x in this.properties){this.text.style.setAttribute((prop_enum[x]||x),this.properties[x]);}
this.shape.appendChild(this.textbox);}else{this.shape=document.createElementNS('http://www.w3.org/2000/svg','g');this.shape.setAttribute('transform','translate('+x+' '+(y+20)+')');this.text=document.createElementNS('http://www.w3.org/2000/svg','text');this.text.setAttribute('x',0);this.text.setAttribute('y',0);for(var x in this.properties){this.text.setAttribute((prop_enum[x]||x),this.properties[x]);}
this.text.setAttribute('transform','rotate('+rot+')');this.shape.appendChild(this.text);var d=document.createTextNode(content);this.text.appendChild(d);}
if(this.events){setEventHandlers(this);}
this.canvas.canvas.appendChild(this.shape);}
Text.prototype.moveTo=function(points){if(this.canvas.isIE){this.shape.style.top=(points[1]-(this.fontsize/2))+'px';this.shape.style.left=(points[0]-7)+'px';}else{this.shape.setAttribute('transform','translate('+points[0]+' '+(points[1]+20)+')');}}
function Layer(map,wmsLayer){this.zdepth=wmsLayer.zdepth;this.id=wmsLayer.id;this.wmsLayer=wmsLayer;this.map=map;this.mapTiles=new Array()
this.htmlIndex;if(this.map.layerCaches){this.imageCache=new ImageCache(map);if(!this.map.layerCaches[wmsLayer.id]){this.map.layerCacheIds.push(wmsLayer.id);this.map.layerCaches[wmsLayer.id]=this.imageCache;}else{this.imageCache=this.map.layerCaches[wmsLayer.id]}}
this._createLayerHTML();}
Layer.prototype._createLayerHTML=function(){this.mapLayer=document.createElement('div');this.mapLayer.className='map-layer';this.mapLayer.style.width=this.map.mapLayerContainer.style.width;this.mapLayer.style.height=this.map.mapLayerContainer.style.height;if(this.wmsLayer.opacity>=0&&this.wmsLayer.opacity<100){this.mapLayer.style.opacity=(this.wmsLayer.opacity/100);this.mapLayer.style.filter='alpha(opacity='+this.wmsLayer.opacity+')';}else{this.mapLayer.style.filter='';this.mapLayer.style.opacity='';}
var inserted=false;for(var i=0;i<this.map.layers.length;i++){if(this.zdepth<=this.map.layers[i].zdepth&&this.id!=this.map.layers[i].id){this.map.mapLayerContainer.insertBefore(this.mapLayer,this.map.layers[i].mapLayer);inserted=true;this.htmlIndex=i;break;}}
if(!inserted){this.htmlIndex=this.map.layers.length;this.map.mapLayerContainer.appendChild(this.mapLayer);}
for(var i=0;i<this.map.xdim;i++){for(var j=0;j<this.map.ydim;j++){this.mapTiles.push(new MapTile(this,i,j));}}}
Layer.prototype.mapTileCycle=function(dx,dy){if(this.wmsLayer.opacity>=0&&this.wmsLayer.opacity<=100){this.mapLayer.style.filter='';}
for(var i=0;i<this.mapTiles.length;i++){this.mapTiles[i].moveBy(dx,dy);}
if(this.wmsLayer.opacity>=0&&this.wmsLayer.opacity<100){this.mapLayer.style.filter='alpha(opacity='+this.wmsLayer.opacity+')';}}
Layer.prototype.zoomIn=function(){for(var i=0;i<this.mapTiles.length;i++){this.mapTiles[i].zoomIn();}}
Layer.prototype.zoomOut=function(){for(var i=0;i<this.mapTiles.length;i++){this.mapTiles[i].zoomOut();}}
Layer.prototype.draw=function(){for(var i=0;i<this.mapTiles.length;i++){this.mapTiles[i].draw()}}
Layer.prototype.clear=function(){for(var i=0;i<this.mapTiles.length;i++){this.mapTiles[i].clear()}}
Layer.prototype.setOpacity=function(opacity){this.wmsLayer.opacity=opacity;if(this.wmsLayer.opacity>=0&&this.wmsLayer.opacity<100){this.mapLayer.style.opacity=(this.wmsLayer.opacity/100);this.mapLayer.style.filter='alpha(opacity='+this.wmsLayer.opacity+')';}else{this.mapLayer.style.filter='';this.mapLayer.style.opacity='';}}
Layer.prototype.kill=function(){this.map.mapLayerContainer.removeChild(this.mapLayer);for(var i=0;i<this.mapTiles.length;i++){this.mapTiles[i].kill();}
this.mapTiles=null;this.id=null;this.wmsLayer=null;this.mapLayer=null;this.map=null;}
function LayerInterface(map,consolidateLayers){this.map=map;this.closed=true;this.consolidateLayers=consolidateLayers;this.sliders=[];this.createLayerInterfaceHTML();}
LayerInterface.prototype.createLayerInterfaceHTML=function(){var _this=this;var liback=document.createElement('div');liback.className='liback';liback.style.position='absolute';liback.style.cursor='default';liback.style.backgroundImage="url('scrollable_map/images/blank.gif')";liback.style.width=this.map.mapViewport.style.width;liback.style.height=this.map.mapViewport.style.height;liback.style.zIndex=999;liback.style.display='none';liback.style.color="white";this.liback=liback;var li=document.createElement('div');li.className='layer-panel';var w=this.map.mapViewport.style.width.split("px")[0]-80;var h=this.map.mapViewport.style.height.split("px")[0]-180;li.style.top='40px';li.style.left='40px';li.style.width=w+'px';li.style.height=h+'px';li.style.fontWeight='bold';this.li=li;var lititle=document.createElement('div');lititle.innerHTML='Available Layers For This View:';lititle.style.backgroundColor='black';lititle.style.color='white';lititle.style.height='1em';lititle.style.padding='3px';this.lititle=lititle;var licontents=document.createElement('div');licontents.style.height=(h-24)+'px';licontents.style.overflow='auto';licontents.style.borderTop='solid black 1px';this.licontents=licontents;var cancel=document.createElement('img');cancel.src='scrollable_map/images/cancel.png';cancel.alt='X';cancel.className='popup-cancel';cancel.onclick=function(){_this.closeLayers();};this.cancel=cancel;this.map.mapViewport.appendChild(this.liback);this.liback.appendChild(li);this.li.appendChild(lititle);this.li.appendChild(licontents);this.li.appendChild(cancel);}
LayerInterface.prototype.resize=function(){this.liback.style.width=this.map.mapViewport.style.width;this.liback.style.height=this.map.mapViewport.style.height;this.li.style.width=parseInt(this.map.mapViewport.style.width.split("px")[0],10)-80+'px';this.li.style.height=parseInt(this.map.mapViewport.style.height.split("px")[0],10)-Math.floor(parseInt(this.map.mapViewport.style.height.split("px")[0],10)/2.5)+'px';this.licontents.style.height=(parseInt(this.map.mapViewport.style.height.split("px")[0],10)-Math.floor(parseInt(this.map.mapViewport.style.height.split("px")[0])/2.5))-24+'px';this.liback.style.top='0px';}
LayerInterface.prototype.loadLayers=function(){var _this=this;if(this.map.wmsLayerManager.isLoading){this.map.wmsLayerManager.onloaded=function(){_this.loadLayers()};}else{if(this.closed){for(var i=0;i<this.map.wmsLayers.length;i++){var layer=this.map.wmsLayers[i];var scale=this.map.getScale();if(!layer.isHidden&&this.map.wmsLayerManager.mapLayerOverlap(layer.boundingbox)&&(scale>=layer.scaleMin&&scale<=layer.scaleMax)&&layer.owner){var wms_group=this.licontents;if(!this.consolidateLayers){wms_group=document.getElementById(layer.owner+this.map.parentElementId);if(!wms_group){wms_group=document.createElement('div');wms_group.id=layer.owner+this.map.parentElementId;wms_group.className='wms-group';var p=document.createElement('p');p.innerHTML=layer.owner;this.licontents.appendChild(wms_group);wms_group.appendChild(p);}}
var chk=document.createElement('input');chk.type='checkbox';chk.wmsId=layer.id;chk.legendUrl=layer.legendUrl;chk.onclick=function(event){_this.toggleLayer(event,this);}
if(this.map.containsLayer(layer.id)){chk.checked=true;chk.defaultChecked=true;}
var lbl=document.createElement('label');lbl.innerHTML=layer.title+'&nbsp;';var br=document.createElement('br');wms_group.appendChild(chk);wms_group.appendChild(lbl);wms_group.appendChild(br);}}
this.resize();this.liback.style.display='block';this.closed=false;}}}
LayerInterface.prototype.closeLayers=function(){var elems;for(var i=0;i<this.sliders.length;i++){this.sliders[i].kill();}
this.sliders=[];elems=this.licontents.getElementsByTagName('input');for(var i=0;i<elems.length;i++){elems[i].onclick=null;elems[i].wmsId=null;elems[i].legendUrl=null;elems[i].parentNode.removeChild(elems[i]);i--;}
elems=this.licontents.getElementsByTagName('label');for(var i=0;i<elems.length;i++){elems[i].parentNode.removeChild(elems[i]);i--;}
elems=this.licontents.getElementsByTagName('br');for(var i=0;i<elems.length;i++){elems[i].parentNode.removeChild(elems[i]);i--;}
this.liback.style.display='none';this.closed=true;}
LayerInterface.prototype.toggleLayer=function(event,check){event=event||window.event;if(check.checked){this.map.appendLayer(check.wmsId);}else{this.map.removeLayer(check.wmsId);}
if(this.map.opacityInterface&&!this.map.opacityInterface.closed){this.map.opacityInterface.redraw();}}
LayerInterface.prototype.kill=function(){this.map.mapViewport.removeChild(this.liback);this.liback.removeChild(this.li);this.li.removeChild(this.lititle);this.li.removeChild(this.licontents);this.li.removeChild(this.cancel);this.closeLayers();this.map=null;}
function Map(center_lon,center_lat,zoom,tileWidth,tileHeight,xdim,ydim,map_width,map_height,defaultWmsUrl,tileCaching,parentMap,parentElementId){this.is_moving=false;this.is_zooming=false;this.dont_draw=false;this.identifyPopup=null;this.zoom=0;this.max_zoom=20;this.tileWidth=tileWidth;this.tileHeight=tileHeight;this.x=0;this.x_no_loop=0;this.y=0;this.deg_px_x=360/(tileHeight*4)*2;this.deg_px_y=360/(tileHeight*4)*2;this.xdim=xdim;this.ydim=ydim;this.parentElementId=parentElementId;this.parentMap=parentMap;this.parentElement=document.getElementById(this.parentElementId);this.animator=false;this.pathIndex=0;this.path=[];this.resize_offset_x=0;this.resize_offset_y=0;this.toolAction=null;this.layers=[];this.imagesToLoad=0;this.snapBackTimer=null;this.waitingLayers=[];if(navigator.appName.indexOf("Microsoft Internet Explorer")==-1){if(tileCaching){this.layerCaches=[];this.layerCacheIds=[];}}
this._createMapHTML();this.centerLL=this.getCenterLatLon();this.moveTo(center_lon,center_lat);this.centerLL=this.getCenterLatLon();this.zoomInN(zoom);this.centerLL=this.getCenterLatLon();this.moveTo(center_lon,center_lat);this.centerLL=this.getCenterLatLon();if(map_width&&map_height){this.resize(map_width,map_height);}
this.wmsLayers=[];var args='nocache='+(new Date()).getTime();if(!defaultWmsUrl){defaultWmsUrl='wms/wms_default.xml';}
this.wmsLayerManager=new WmsLayerManager(this,defaultWmsUrl+'?'+args);this.blankImage=document.createElement('img');this.blankImage.src='scrollable_map/images/blank.gif';this.jsDraw=new JSDraw(this.viewport_width*3,this.viewport_height*3,this.pane);this.jsDraw.board.style.position='absolute';this.jsDraw.board.style.top=-this.viewport_height+'px';this.jsDraw.board.style.left=-this.viewport_width+'px';this.jsDraw.setViewBox(-this.viewport_width,-this.viewport_height,3*this.viewport_width,3*this.viewport_height);this.svgShapes=[];}
Map.prototype._createMapHTML=function(){var _this=this;this.mapLayerContainer=document.createElement('div');this.mapLayerContainer.className='map-layer-container';this.mapLayerContainer.style.width=(this.xdim*this.tileWidth)+'px';this.mapLayerContainer.style.height=(this.ydim*this.tileHeight)+'px';this.mapLayerContainer.style.top=-this.tileHeight+'px';this.mapLayerContainer.style.left=-this.tileWidth+'px';this.mapViewport=document.createElement('div');this.mapViewport.className='map-viewport';this.mapViewport.style.width=((this.xdim-1)*this.tileWidth)+'px';this.mapViewport.style.height=((this.ydim-1)*this.tileHeight)+'px';var parEl=document.getElementById(this.parentElementId);parEl.style.width=this.mapViewport.style.width;parEl.style.height=this.mapViewport.style.height;parEl.style.border='solid #bbb 1px';this.parEl=parEl;this.pane=document.createElement('div');this.pane.className='map-pane';this.pane.style.left='0px';this.pane.style.top='0px';this.pane.style.width=((this.xdim)*this.tileWidth)+'px';this.pane.style.height=((this.ydim)*this.tileHeight)+'px';this.pane.style.backgroundImage="url('scrollable_map/images/blank.gif')";this.pane.onmousedown=function(event){return _this._performAction(event);};this.pane.ondblclick=function(event){return _this.animateMove(event,this);};this.pane.oncontextmenu=function(){return false;};document.getElementById(this.parentElementId).appendChild(this.mapViewport);this.mapViewport.appendChild(this.mapLayerContainer);this.viewport_width=parseInt(this.mapViewport.style.width.split('px')[0],10);this.viewport_height=parseInt(this.mapViewport.style.height.split('px')[0],10);this.mapViewport.appendChild(this.pane);if(!this.parentMap){var load_img=document.createElement('img');load_img.src='scrollable_map/images/rotating_arrow.gif';load_img.className='loading-image';this.loadimg=load_img;this.mapViewport.appendChild(this.loadimg);}}
Map.prototype.svgCircle=function(clat,clon,r,prop,events){var ccoords=this.getPixelFromLatLon(clat,clon);var x=ccoords[0]+(this.jsDraw.x+this.viewport_width);var y=ccoords[1]+(this.jsDraw.y+this.viewport_height);var o=this.jsDraw.circle(x,y,r,prop,events);o.map_points=[clat,clon];this.svgShapes.push(o);}
Map.prototype.svgPolyLine=function(points,prop,events){var tpts=[];for(var i=0;i<points.length;i+=2){var lcoords=this.getPixelFromLatLon(points[i],points[i+1]);var x=lcoords[0]+(this.jsDraw.x+this.viewport_width);var y=lcoords[1]+(this.jsDraw.y+this.viewport_height);tpts.push(x);tpts.push(y);}
var o=this.jsDraw.polyline(tpts,prop,events);o.map_points=points;this.svgShapes.push(o);}
Map.prototype.svgPolygon=function(points,prop,events){var tpts=[];for(var i=0;i<points.length;i+=2){var lcoords=this.getPixelFromLatLon(points[i],points[i+1]);var x=lcoords[0]+(this.jsDraw.x+this.viewport_width);var y=lcoords[1]+(this.jsDraw.y+this.viewport_height);tpts.push(x);tpts.push(y);}
var o=this.jsDraw.polygon(tpts,prop,events);o.map_points=points;this.svgShapes.push(o);}
Map.prototype.svgText=function(lat,lon,w,h,content,rot,prop,events){var lcoords=this.getPixelFromLatLon(lat,lon);var x=lcoords[0]+(this.jsDraw.x+this.viewport_width);var y=lcoords[1]+(this.jsDraw.y+this.viewport_height);var o=this.jsDraw.text(x,y,w,h,content,rot,prop,events);o.map_points=[lat,lon];this.svgShapes.push(o);}
Map.prototype.redrawSVG=function(){this.jsDraw.board.style.top=-this.viewport_height+'px';this.jsDraw.board.style.left=-this.viewport_width+'px';this.jsDraw.setViewBox(-this.viewport_width,-this.viewport_height,3*this.viewport_width,3*this.viewport_height);for(var i=0;i<this.svgShapes.length;i++){var tpts=[];for(var j=0;j<this.svgShapes[i].map_points.length;j+=2){var ccoords=this.getPixelFromLatLon(this.svgShapes[i].map_points[j],this.svgShapes[i].map_points[j+1]);var x=ccoords[0]+(this.jsDraw.x+this.viewport_width);var y=ccoords[1]+(this.jsDraw.y+this.viewport_height);tpts.push(x);tpts.push(y);}
this.svgShapes[i].moveTo(tpts);}}
Map.prototype.resize=function(width_px,height_px,no_recenter){var cll=this.getCenterLatLon();this.pane.style.width=width_px+'px';this.pane.style.height=height_px+'px';this.mapViewport.style.width=width_px+'px';this.mapViewport.style.height=height_px+'px';this.parEl.style.width=this.mapViewport.style.width;this.parEl.style.height=this.mapViewport.style.height;this.viewport_width=width_px;this.viewport_height=height_px;this.centerLL=this.getCenterLatLon();if(!no_recenter){this.moveTo(cll[0],cll[1])
this.centerLL=[cll[0],cll[1]];}
this._testSnapBack();if(this.overviewMap){this.overviewMap.map.panner.kill();this.overviewMap.map.addPanner();}
if(this.scaleBar)this.scaleBar.calculateScale();if(this.jsDraw){this.jsDraw.board.style.top=-this.viewport_height+'px';this.jsDraw.board.style.left=-this.viewport_width+'px';this.jsDraw.resize(3*this.viewport_width,3*this.viewport_height);this.jsDraw.setViewBox(-this.viewport_width,-this.viewport_height,3*this.viewport_width,3*this.viewport_height)
this.redrawSVG();}}
Map.prototype.imagesLoading=function(){if(!this.parentMap)
this.loadimg.style.display='block';}
Map.prototype.imagesDoneLoading=function(){if(!this.parentMap)
this.loadimg.style.display='none';}
Map.prototype.addZoomSlider=function(zoom_levels,hide_slider){this.max_zoom=zoom_levels-1;if(this.max_zoom<0)this.max_zoom=15;this.zoomSlider=new ZoomSlider(this,zoom_levels,hide_slider);}
Map.prototype.addPanner=function(){this.panner=new Panner(this);}
Map.prototype.addOverviewMap=function(parentElemendId,wms_config,w,h){this.overviewMap=new OverviewMap(this,parentElemendId,wms_config,w,h);}
Map.prototype.addScaleBar=function(){this.scaleBar=new ScaleBar(this);}
Map.prototype.addLayerInterface=function(consolidate){this.layerInterface=new LayerInterface(this,consolidate);this.opacityInterface=new OpacityInterface(this);}
Map.prototype.setCursor=function(css){if(!css||css=='')css='url(scrollable_map/images/handopen.cur), move';this.pane.style.cursor=css;}
Map.prototype.setToolAction=function(func,cursor){this.toolAction=func;this.setCursor(cursor);}
Map.prototype._performAction=function(event){(!this.toolAction)?this._startDrag(event):this.toolAction(event,this);if(this.onaction)this.onaction(event);return false;}
Map.prototype._startDrag=function(event){this.setCursor('url(scrollable_map/images/handclose.cur), move');event=event||window.event;var _this=this;var coordsPx=[event.clientX,event.clientY];this.startXY=event.clientX+":"+event.clientY;this.lastMouseX=event.clientX;this.lastMouseY=event.clientY;document.onmousemove=function(event){return _this._drag(event);};document.onmouseup=function(event){return _this._endDrag(event);};return false;}
Map.prototype._drag=function(event){if(this.snapBackTimer)clearTimeout(this.snapBackTimer);this.snapBackTimer=null;event=event||window.event;if(navigator.appVersion.indexOf("MSIE")!=-1)unselect();var coordsPx=[event.clientX,event.clientY];var currentMouseX=coordsPx[0];var currentMouseY=coordsPx[1];var bbox=this.getViewportBoundingBox();this.moveBy(currentMouseX-this.lastMouseX,currentMouseY-this.lastMouseY);this.lastMouseX=currentMouseX;this.lastMouseY=currentMouseY;var _this=this;if(!this.animator)
this.snapBackTimer=setTimeout(function(){_this._testSnapBack()},50);return false;}
Map.prototype._endDrag=function(event){event=event||window.event;this.centerLL=this.getCenterLatLon();this.setCursor('');if(this.startXY!=event.clientX+":"+event.clientY)
this.updateComponentsAfterMove();if(this.snapBackTimer){this._testSnapBack();clearTimeout(this.snapBackTimer);}
this.snapBackTimer=false;if(this.ondrop)this.ondrop(event);document.onmousemove=null;document.onmouseup=null;return false;}
Map.prototype.setEvent=function(eventName,func){if(typeof(func)=='function'){switch(eventName.toLowerCase()){case"onzoomin":this.onzoomin=function(params){func(params);};break;case"onzoomout":this.onzoomout=function(params){func(params);};break;case"onaction":this.onaction=function(params){func(params);};break;case"ondrop":this.ondrop=function(params){func(params);};break;case"onlayerappend":this.onlayerappend=function(params){func(params);};break;case"onlayerremove":this.onlayerremove=function(params){func(params);};break;case"onidentify":this.onidentify=function(){func();};break;case"onidentifyclose":this.onidentifyclose=function(){func();};break;case"ondonemoving":this.ondonemoving=function(){func();};break;case"onmove":this.onmove=function(p1,p2){func(p1,p2);};break;default:break;}}}
Map.prototype.getCenterLatLon=function(){var vpbbox=this.getViewportBoundingBox();var xex=(vpbbox.xmin+vpbbox.xmax)/2;if(xex>180)xex-=360;else if(xex<-180)xex+=360;return[xex,(vpbbox.ymin+vpbbox.ymax)/2];}
Map.prototype.getLatLonFromPixel=function(x,y){var center_px_x=this.viewport_width/2;var center_px_y=this.viewport_height/2;var dx=center_px_x-x;var dy=y-center_px_y;var dx_deg=dx*this.deg_px_x;var dy_deg=dy*this.deg_px_y;var centerLL=this.getCenterLatLon();var tx=(centerLL[0]-dx_deg);if(tx<-180)tx+=360;else if(tx>180)tx-=360;return[tx,(centerLL[1]-dy_deg)];}
Map.prototype.getPixelFromLatLon=function(lat,lon){var coords=this.getCenterLatLon();var dx_deg=coords[0]-lon;var dy_deg=coords[1]-lat;var dx=dx_deg/this.deg_px_x;var dy=dy_deg/this.deg_px_y;return[((this.viewport_width/2)-dx),((this.viewport_height/2)+dy)]}
Map.prototype.getTilesPerMapX=function(){return Math.floor((360/this.deg_px_x)/this.tileWidth);}
Map.prototype.getTilesPerMapY=function(){return Math.floor(180/this.deg_px_y)/this.tileHeight;}
Map.prototype.getScale=function(){var bbox=this.getViewportBoundingBox();var xWid=(bbox.xmax-bbox.xmin)/(this.tileWidth*this.deg_px_x);var yHig=(bbox.ymax-bbox.ymin)/(this.tileHeight*this.deg_px_y);var vertScale=(bbox.ymax-bbox.ymin)/(this.tileWidth*yHig);var horzScale=(bbox.xmax-bbox.xmin)/(this.tileHeight*xWid);return((vertScale+horzScale)/2.0);}
Map.prototype.getTileWidthDeg=function(){return this.deg_px_x*this.tileWidth;}
Map.prototype.getTileHeightDeg=function(){return this.deg_px_y*this.tileHeight;}
Map.prototype.getViewportBoundingBox=function(){var mlc_top=parseInt(this.mapLayerContainer.style.top.split('px')[0],10);var mlc_left=parseInt(this.mapLayerContainer.style.left.split('px')[0],10);var xmin=((((this.x+1)*this.tileWidth)-(mlc_left+this.tileWidth))*this.deg_px_x)-180;if(xmin>180)xmin-=360;else if(xmin<-180)xmin+=360;var xmax=xmin+(this.viewport_width*this.deg_px_x);var resize_offset_y=(((this.ydim-1)*this.tileHeight)-this.viewport_height)*this.deg_px_y;var ymin=(((((this.y)*this.tileHeight)+(mlc_top+this.tileHeight))*this.deg_px_y))-90+resize_offset_y;var ymax=ymin+(this.viewport_height*this.deg_px_y);return{xmin:xmin,ymin:ymin,xmax:xmax,ymax:ymax};}
Map.prototype.getViewportBoundingBoxString=function(){var bbox=this.getViewportBoundingBox();return bbox.xmin+','+bbox.ymin+','+bbox.xmax+','+bbox.ymax;}
Map.prototype.getUnclippedBoundingBox=function(){var xmin = (((this.x) * this.tileWidth)*this.deg_px_x)-180;if (xmin > 180) xmin -= 360;else if (xmin < -180) xmin += 360;var xmax = xmin + (this.xdim * this.tileWidth * this.deg_px_x);var ymin = (((this.y) * this.tileHeight) * this.deg_px_y) - 90;var ymax = ymin + (this.ydim * this.tileHeight * this.deg_px_y);return {xmin:xmin, ymin:ymin, xmax:xmax, ymax:ymax};}
Map.prototype.getUnclippedBoundingBoxString = function() {var bbox = this.getUnclippedBoundingBox();return bbox.xmin + "," + bbox.ymin + "," + bbox.xmax + "," + bbox.ymax;}
Map.prototype.zoomInN=function(n){if(this.wmsLayerManager)this.wmsLayerManager.cancelFetchLayers();this.imagesToLoad=0;var center=this.centerLL;this.clear();this.is_zooming=true;for(var j=0;j<n;j++){if(!this.max_zoom||(this.zoom<this.max_zoom)){this.deg_px_x/=2;this.deg_px_y/=2;this.zoom++;this.x=(this.x*2)+Math.floor(this.xdim/2);this.x_no_loop=this.x;this.y=(this.y*2)+Math.floor(this.ydim/2);this.x=this.x%this.getTilesPerMapX();if(this.x<0){this.x=(this.getTilesPerMapX()-1);}
for(var i=0;i<this.layers.length;i++){this.layers[i].zoomIn();}
this.moveTo(center[0],center[1]);}else{break;}}
this.is_zooming=false;if(this.wmsLayerManager)this.wmsLayerManager.updateWmsLayers();this.updateComponentsAfterZoom();this.draw();if(this.onzoomin)this.onzoomin(this.zoom);}
Map.prototype.zoomOutN=function(n){if(this.wmsLayerManager)this.wmsLayerManager.cancelFetchLayers();this.imagesToLoad=0;this.x=Math.floor(this.x);this.y=Math.floor(this.y);var center=this.centerLL;this.clear();this.is_zooming=true;for(var j=0;j<n;j++){if(this.zoom>=1){this.deg_px_x*=2;this.deg_px_y*=2;this.zoom--;this.x=Math.floor((this.x-Math.floor(this.xdim/2))/2);this.x_no_loop=this.x;this.y=Math.floor((this.y-Math.floor(this.ydim/2))/2);this.x=(this.x)%this.getTilesPerMapX();if(this.x<0){this.x=this.getTilesPerMapX()-1;}
for(var i=0;i<this.layers.length;i++){this.layers[i].zoomOut();}
this.moveTo(center[0],center[1]);}else{break;}}
this.is_zooming=false;if(this.wmsLayerManager)this.wmsLayerManager.updateWmsLayers();this.updateComponentsAfterZoom();this.draw();if(this.onzoomout)this.onzoomout(this.zoom);}
Map.prototype.jumpTo=function(lon,lat,zoom){this.is_jumping=true;this.is_moving=true;var to_zoom=zoom||this.zoom;var tzoom=this.zoom;this.zoomOutN(this.zoom);this.moveTo(lon,lat);this.centerLL=[lon,lat];this.zoomInN(to_zoom);this.is_moving=false;this.is_jumping=false;this.draw();this.updateComponentsAfterMove();}
Map.prototype.moveTo=function(lon,lat){this.is_moving=true
lon=lon%360;if(lon>180)lon-=360;else if(lon<-180)lon+=360;var coords=this.getCenterLatLon();var centerLat=coords[1];var centerLon=coords[0];var dlat=lat-centerLat;var dlon=lon-centerLon;var dy=Math.floor(dlat/this.deg_px_y);var dx=-1*Math.floor(dlon/this.deg_px_x);this.moveBy(dx,dy);if(this.parentMap)this.is_moving=false;this._testSnapBack();this.is_moving=false;this.draw();}
Map.prototype.moveBy=function(dx,dy){var tolerance=((this.getTilesPerMapY()/2)+2.5)*this.tileHeight*this.deg_px_y;var mlc_top=parseInt(this.mapLayerContainer.style.top.split('px')[0],10);var mlc_left=parseInt(this.mapLayerContainer.style.left.split('px')[0],10);var bbox=this.getViewportBoundingBox();var ymax=bbox.ymax+(dy*this.deg_px_y)
if(ymax>tolerance){var diff_dy=Math.floor((ymax-tolerance)/this.deg_px_y);dy-=diff_dy;}
var ymin=bbox.ymin+(dy*this.deg_px_y)
if(ymin<-tolerance){var diff_dy=Math.floor((ymin+tolerance)/this.deg_px_y);dy-=diff_dy;}
this.mapLayerContainer.style.left=(mlc_left+dx)+'px';this.mapLayerContainer.style.top=(mlc_top+dy)+'px';if(this.identifyPopup)this.identifyPopup.moveBy(dx,dy);if(this.parentMap)this._testSnapBack();if(this.jsDraw)this.jsDraw.moveBy(dx,dy);if(this.onmove)this.onmove(dx,dy);}
Map.prototype.fitToBBox=function(xmin,ymin,xmax,ymax){var map_x_extent=this.viewport_width*this.deg_px_x;var bbox_x_extent=xmax-xmin;var x_zoom=this.zoom;if(map_x_extent<bbox_x_extent){while((map_x_extent)<bbox_x_extent){if(x_zoom==0)break;x_zoom-=1;map_x_extent*=2;}}else if(map_x_extent>bbox_x_extent){while((map_x_extent)>=bbox_x_extent){if(x_zoom==this.max_zoom+1)break;x_zoom+=1;map_x_extent/=2;}
x_zoom-=1;}
var map_y_extent=this.viewport_height*this.deg_px_y;var bbox_y_extent=ymax-ymin;var y_zoom=this.zoom;if(map_y_extent<bbox_y_extent){while((map_y_extent)<bbox_y_extent){if(y_zoom==0)break;y_zoom-=1;map_y_extent*=2;}}else if(map_y_extent>bbox_y_extent){while((map_y_extent)>=bbox_y_extent){y_zoom+=1;map_y_extent/=2;if(y_zoom==this.max_zoom+1)break;}
y_zoom-=1;}
var lowest_zoom=x_zoom;if(y_zoom<x_zoom)lowest_zoom=y_zoom;this.jumpTo(((xmax+xmin)/2),((ymax+ymin)/2),lowest_zoom);}
Map.prototype.fitToBBoxLowerLeft=function(xmin,ymin,xmax,ymax){var map_x_extent=(this.viewport_width*this.deg_px_x)/2;var bbox_x_extent=xmax-xmin;var x_zoom=this.zoom;if(map_x_extent<bbox_x_extent){while((map_x_extent)<bbox_x_extent){if(x_zoom==0)break;x_zoom-=1;map_x_extent*=2;}}else if(map_x_extent>bbox_x_extent){while((map_x_extent)>bbox_x_extent){if(x_zoom==16)break;x_zoom+=1;map_x_extent/=2;}
x_zoom-=1;}
var map_y_extent=this.viewport_height*this.deg_px_y;var bbox_y_extent=ymax-ymin;var y_zoom=this.zoom;if(map_y_extent<bbox_y_extent){while((map_y_extent)<bbox_y_extent){if(y_zoom==0)break;y_zoom-=1;map_y_extent*=2;}}else if(map_y_extent>bbox_y_extent){while((map_y_extent)>bbox_y_extent){if(y_zoom==16)break;y_zoom+=1;map_y_extent/=2;}
y_zoom-=1;}
var lowest_zoom=x_zoom;if(y_zoom<x_zoom){lowest_zoom=y_zoom;}
this.dont_draw=true;this.clear();this.jumpTo(((xmax+xmin)/2),((ymax+ymin)/2),lowest_zoom);this.moveBy(-this.tileWidth*0.75,0);this.centerLL=this.getCenterLatLon();this.updateComponentsAfterMove();this.dont_draw=false;this._testSnapBack();this.draw();}
Map.prototype.animateMove=function(event){event=event||window.event;var coords=getRelativeCoords(event,this.pane);this.animateMoveToPx(coords[0],coords[1]);}
Map.prototype.animateMoveByPx=function(dx,dy){var startX=this.viewport_width/2;var startY=this.viewport_height/2;this.animateMoveToPx(startX+dx,startY+dy);}
Map.prototype.animateMoveToLatLon=function(lat,lon){var ll=this.getPixelFromLatLon(lat,lon);this.animateMoveToPx(ll[0],ll[1]);}
Map.prototype.animateMoveToPx=function(endX,endY){this.path=[];this.pathIndex=0;clearInterval(this.animator);var startX=this.viewport_width/2;var startY=this.viewport_height/2;var dx=(startX-endX);var dy=(startY-endY);var dirVect=[];if(dx!=0||dy!=0){if(Math.abs(dx)>=Math.abs(dy)){dirVect.push(dx/Math.abs(dx));dirVect.push(dy/Math.abs(dx));while(Math.abs(dx)>5){dx/=2;dx=Math.floor(dx);dy=Math.floor(Math.abs(dx)*(dirVect[1]));this.path.push([dx,dy]);}
var ubound=Math.abs(dx);for(var i=0;i<ubound;i++){dx-=(dx/Math.abs(dx));dy=Math.floor(Math.abs(dx)*(dirVect[1]));this.path.push([dx,dy]);}}else if(Math.abs(dx)<Math.abs(dy)){dirVect.push(dx/Math.abs(dy));dirVect.push(dy/Math.abs(dy));while(Math.abs(dy)>5){dy/=2;dy=Math.floor(dy);dx=Math.floor(Math.abs(dy)*(dirVect[0]));this.path.push([dx,dy]);}
var ubound=Math.abs(dx);for(var i=0;i<ubound;i++){dy-=(dy/Math.abs(dy));dx=Math.floor(Math.abs(dy)*(dirVect[0]));this.path.push([dx,dy]);}}
var _this=this;this.pathIndex=0;this.animator=setInterval(function(){_this.animateMapStep();},20);}}
Map.prototype.animateMapStep=function(){var vector=this.path[this.pathIndex];if(vector){this.moveBy(vector[0],vector[1]);this.pathIndex++;if(this.pathIndex==this.path.length){clearInterval(this.animator);this.animator=false;this.centerLL=this.getCenterLatLon();if(this.parentMap){this.parentMap.clear();this.parentMap.dont_draw=true;}
this._testSnapBack();if(this.parentMap){this.parentMap.dont_draw=false;this.parentMap.draw();}
this.path=null;this.updateComponentsAfterMove();if(this.ondonemoving)this.ondonemoving();return true;}else{return false;}}}
Map.prototype._testSnapBack=function(){clearTimeout(this.snapBackTimer);this.snapBackTimer=null;var curMapX=parseInt(this.mapLayerContainer.style.left.split('px')[0],10);var curMapY=parseInt(this.mapLayerContainer.style.top.split('px')[0],10);var resize_offset_x=(((this.xdim-1)*this.tileWidth)-this.viewport_width)/2
var resize_offset_y=(((this.ydim-1)*this.tileHeight)-this.viewport_height)/2
if(curMapX>(0.0*this.tileWidth)-resize_offset_x){var numCycles=Math.floor((curMapX+resize_offset_x)/this.tileWidth)+1;curMapX-=(numCycles*this.tileWidth);this.mapLayerContainer.style.left=curMapX+'px';for(var i=0;i<Math.abs(numCycles);i++){this.mapTileCycle(1,0);}}else if(curMapX<(-1.0*this.tileWidth)-resize_offset_x){var numCycles=Math.ceil(curMapX/this.tileWidth);curMapX-=(numCycles*this.tileWidth);this.mapLayerContainer.style.left=curMapX+'px';for(var i=0;i<Math.abs(numCycles);i++){this.mapTileCycle(-1,0);}}
if(curMapY>(-0.0*this.tileHeight)-resize_offset_y){var numCycles=Math.floor((curMapY+resize_offset_y)/this.tileHeight)+1;curMapY-=(numCycles*this.tileHeight);this.mapLayerContainer.style.top=curMapY+'px';for(var i=0;i<Math.abs(numCycles);i++){this.mapTileCycle(0,1);}}else if(curMapY<(-1.0*this.tileHeight)-resize_offset_y){var numCycles=Math.ceil(curMapY/this.tileHeight);curMapY-=(numCycles*this.tileHeight);this.mapLayerContainer.style.top=curMapY+'px';for(var i=0;i<Math.abs(numCycles);i++){this.mapTileCycle(0,-1);}}}
Map.prototype.mapTileCycle=function(dx,dy){for(var i=0;i<this.layers.length;i++){this.layers[i].mapTileCycle(dx,dy);}
this.x_no_loop-=dx;this.x=(this.x-dx)%this.getTilesPerMapX();if(this.x<0){this.x=this.getTilesPerMapX()-dx;}
this.y-=(-1*dy);}
function sorter(t1,t2){if(t1.zdepth<t2.zdepth)return-1;if(t1.zdepth>t2.zdepth)return 1;return 0;}
Map.prototype.appendLayer=function(layerId,noqueue){var wmsLayer=null;if(!this.containsLayer(layerId)){for(var i=0;i<this.wmsLayers.length;i++){if(layerId==this.wmsLayers[i].id){wmsLayer=this.wmsLayers[i];break;}}}
if(wmsLayer){var l=new Layer(this,wmsLayer);this.layers.splice(l.htmlIndex,0,l);if(this.onlayerappend)this.onlayerappend(layerId)}else{if(!noqueue)this.waitingLayers.push(layerId);}
if(this.opacityInterface&&!this.opacityInterface.closed){this.opacityInterface.redraw();}}
Map.prototype.appendWaitingLayers=function(){for(var i=0;i<this.waitingLayers.length;i++){this.appendLayer(this.waitingLayers,true);}
this.waitingLayers=[];}
Map.prototype.removeLayer=function(layerId){for(var i=0;i<this.layers.length;i++){if(this.layers[i].id==layerId){if(this.onlayerremove)this.onlayerremove(layerId);this.layers[i].kill();this.layers[i]=null;this.layers.splice(parseInt(i,10),1);break;}}
if(this.Interface&&!this.opacityInterface.closed){this.opacityInterface.redraw();}}
Map.prototype.removeAllLayers=function(){for(var i=0;i<this.layers.length;i++){if(this.onlayerremove)this.onlayerremove(this.layers[i].id);this.layers[i].kill();this.layers[i]=null;this.layers.splice(parseInt(i,10),1);i--;}}
Map.prototype.containsLayer=function(layerId){for(var i=0;i<this.layers.length;i++){if(this.layers[i].id==layerId){return true;}}
return false;}
Map.prototype.getLayer=function(layerId){for(var i=0;i<this.layers.length;i++){if(this.layers[i].id==layerId){return this.layers[i];}}
return null;}
Map.prototype.getWmsLayer=function(layerId){var wmsLayer=null;for(var i=0;i<this.wmsLayers.length;i++){if(layerId==this.wmsLayers[i].id){wmsLayer=this.wmsLayers[i];break;}}
return wmsLayer;}
Map.prototype.loadWmsLayerFile=function(url,name,isDefault,isHidden){if(this.wmsLayerManager){this.wmsLayerManager.loadWmsLayers(url,name,isDefault,isHidden);}}
Map.prototype.cancelWmsLayerFileLoad=function(){if(this.wmsLayerManager){this.wmsLayerManager.cancelFetchLayers();}}
Map.prototype.draw=function(){for(var i=0;i<this.layers.length;i++){this.layers[i].draw();}}
Map.prototype.clear=function(){for(var i=0;i<this.layers.length;i++){this.layers[i].clear();}}
Map.prototype.updateComponentsAfterZoom=function(){if(this.identifyPopup){this.identifyPopup.reposition();}
if(this.scaleBar){this.scaleBar.calculateScale();}
if(this.zoomSlider){this.zoomSlider.moveToZoomLevel(this.zoom);}
if(this.opacityInterface&&!this.opacityInterface.closed){this.opacityInterface.redraw();}
if(this.overviewMap){var z=this.zoom;var oz=this.overviewMap.map.zoom;var num_zooms=(z-oz)-2;if(num_zooms>0){this.overviewMap.zoomInN(num_zooms);}if(num_zooms<0){this.overviewMap.zoomOutN(-num_zooms);}
this.overviewMap.map.panner.kill();this.overviewMap.map.panner.createPannerHTML();}
if(this.jsDraw){this.redrawSVG();}}
Map.prototype.updateComponentsAfterMove=function(){if(this.scaleBar){this.scaleBar.calculateScale();}
if(this.overviewMap){var ll=this.getCenterLatLon();this.overviewMap.moveTo(ll[0],ll[1]);}
if(this.parentMap){var ll=this.getCenterLatLon();this.parentMap.moveTo(ll[0],ll[1]);this.parentMap.centerLL=this.parentMap.getCenterLatLon();if(this.parentMap.scaleBar){this.parentMap.scaleBar.calculateScale();}}
if(this.jsDraw){this.jsDraw.hide();var tdx=parseInt(this.jsDraw.board.style.left.split('px')[0],10)+this.viewport_width;var tdy=parseInt(this.jsDraw.board.style.top.split('px')[0],10)+this.viewport_height;this.jsDraw.moveViewBox(tdx,tdy);this.jsDraw.board.style.left=-this.viewport_width+'px';this.jsDraw.board.style.top=-this.viewport_height+'px';this.jsDraw.show();}}
Map.prototype.kill=function(){if(this.parentElementId){if(document.getElementById(this.parentElementId)){document.getElementById(this.parentElementId).removeChild(this.mapViewport);}}
this.mapViewport.removeChild(this.pane);this.mapViewport.removeChild(this.mapLayerContainer);if(this.layerInterface)this.layerInterface.kill();if(this.layerCaches){for(var i=0;i<this.layerCacheIds.length;i++){this.layerCaches[this.layerCacheIds[i]].kill();}
this.layerCaches=null;for(var i=0;i<this.layerCacheIds.length;i++)
this.layerCacheIds[i]=null;this.layerCacheIds=null;}
for(var i=0;i<this.layers.length;i++){this.layers[i].kill();}
this.layers=null;if(this.popupIdentify)this.popupIdentify.kill();if(this.zoomSlider)this.zoomSlider.kill();if(this.panner)this.panner.kill();if(this.overviewMap)this.overviewMap.kill();if(this.scaleBar)this.scaleBar.kill();this.is_zooming=null;this.zoom=null;this.tileWidth=null;this.tileHeight=null;this.x=null;this.y=null;this.deg_px_x=null;this.deg_px_y=null;this.xdim=null;this.ydim=null;this.animator=null;this.pathIndex=null;this.path=null;this.wmsLayerManager.kill();this.pane.oncontextmenu=null;this.pane.onmousedown=null;this.pane.ondblclick=null;document.onmousemove=null;document.onmouseup=null;this.mapLayerContainer=null;this.pane=null;this.mapViewport=null;this.parentElementId=null;}
function MapTile(layer,initX,initY){if(!layer.imageCache)
this.jsImageLoader=new ImageLoader(layer.map);else
this.jsImageLoader=null;this.layer=layer;this.initX=initX;this.initY=initY;this.x=(initX+this.layer.map.x)%this.layer.map.getTilesPerMapX();this.y=initY+this.layer.map.y;if(this.layer.wmsLayer.overlap){this.overlapX=Math.floor(this.layer.map.tileWidth/36);this.overlapY=Math.floor(this.layer.map.tileHeight/36);}else{this.overlapX=0;this.overlapY=0;}
this.height=this.layer.map.tileHeight-(this.overlapY*-2);this.width=this.layer.map.tileWidth-(this.overlapX*-2);this._createMapTileHTML();}
MapTile.prototype._createMapTileHTML=function(){this.mapTile=document.createElement('img');this.mapTile.src=this.layer.map.blankImage.src;this.mapTile.className='map-tile';this.mapTile.style.width=this.width+'px';this.mapTile.style.height=this.height+'px';this.mapTile.style.left=(this.layer.map.tileWidth*this.initX)-this.overlapX+'px';this.mapTile.style.top=(this.layer.map.tileHeight*(this.layer.map.ydim-1-this.initY))-this.overlapY+'px';this.layer.mapLayer.appendChild(this.mapTile);this.draw();}
MapTile.prototype.moveBy=function(dx,dy){var curTileX=parseInt(this.mapTile.style.left.split("px")[0],10)+this.overlapX;var curTileY=parseInt(this.mapTile.style.top.split("px")[0],10)+this.overlapY;var newTileX=(curTileX+(dx*this.layer.map.tileWidth));var newTileY=(curTileY+(dy*this.layer.map.tileHeight));if(newTileX>=(this.layer.map.tileWidth*this.layer.map.xdim)){newTileX=0;var tx=(this.layer.map.x-dx)%this.layer.map.getTilesPerMapX();if(tx<0){tx=this.layer.map.getTilesPerMapX()-dx;}
this.x-=(this.layer.map.xdim);if(this.x<0){this.x=tx;}
this.draw();}else if(newTileX<=-(this.layer.map.tileWidth)){newTileX=this.layer.map.tileWidth*(this.layer.map.xdim-1);this.x+=+(this.layer.map.xdim);if(this.x>=this.layer.map.getTilesPerMapX()){this.x=((this.layer.map.x-(this.layer.map.getTilesPerMapX()))+(this.layer.map.xdim));}
this.draw();}else if(newTileY>=(this.layer.map.tileHeight*this.layer.map.ydim)){newTileY=0;this.y+=+this.layer.map.ydim;this.draw();}else if(newTileY<=-(this.layer.map.tileHeight)){newTileY=this.layer.map.tileHeight*(this.layer.map.ydim-1);this.y-=+this.layer.map.ydim;this.draw();}
this.mapTile.style.left=newTileX-this.overlapX+"px";this.mapTile.style.top=newTileY-this.overlapY+"px";}
MapTile.prototype.zoomIn=function(){this.mapTile.style.left=parseInt((this.layer.map.tileWidth*this.initX)-this.overlapX,10)+'px';this.mapTile.style.top=parseInt((this.layer.map.tileHeight*(this.layer.map.ydim-1-this.initY))-this.overlapY,10)+'px';this.x=this.initX+this.layer.map.x;this.y=this.initY+this.layer.map.y;if(this.x>=this.layer.map.getTilesPerMapX()){this.x-=this.layer.map.getTilesPerMapX();}}
MapTile.prototype.zoomOut=function(){this.mapTile.style.left=(this.layer.map.tileWidth*this.initX)-this.overlapX+'px';this.mapTile.style.top=(this.layer.map.tileHeight*(this.layer.map.ydim-1-this.initY))-this.overlapY+'px';this.x=Math.floor(this.initX+this.layer.map.x);this.y=Math.ceil(this.initY+this.layer.map.y);if(this.x>=this.layer.map.getTilesPerMapX()){this.x-=this.layer.map.getTilesPerMapX();}}
MapTile.prototype.clear=function(){this.mapTile.src=this.layer.map.blankImage.src;}
MapTile.prototype.draw=function(){if(!(this.layer.map.is_zooming||this.layer.map.is_moving||this.layer.map.is_jumping||this.layer.map.dont_draw)){this.clear();var xmin=((this.x*this.layer.map.getTileWidthDeg())%360)-180;if(180-xmin<0.0000001)xmin=-180;var xmax=xmin+this.layer.map.getTileWidthDeg();var ymin=((this.y*this.layer.map.getTileHeightDeg()))-90;var ymax=ymin+this.layer.map.getTileHeightDeg();if((xmin>=-180&&xmax<=180)&&(ymin>=-90&&!(ymin>=90))){var src=this.layer.wmsLayer.baseUrl;if(src.indexOf('?')==-1){src+='?';}else if(src.indexOf('?')!=src.length-1){src+='&';}
var w=this.layer.wmsLayer;if(w.serviceType=='mapcache'){src+=this.getSourceMVMapCache(w);}else if(w.serviceType=='wms'){src+=this.getSourceWMS(w);}else if(w.serviceType=='mvwms'){src+=this.getSourceMVWMS(w);}else if(w.serviceType=='basemap'){src+=this.getSourceMVBaseMap(w);}else if(w.serviceType=='arctms'){src=src.substr(0,src.length-1);src+=this.getSourceArcTMS(w);}else if(w.serviceType=='tms'){src=src.substr(0,src.length-1);src+=this.getSourceTMS(w);}else{src+=this.getSourceWMS(w);}
if(this.layer.imageCache){if(this.cachedImage){this.cachedImage.onload=null;}
var img=this.layer.imageCache.getImage(src);if(!img){this.cachedImage=this.layer.imageCache.addImage(src,this.mapTile);}else{this.mapTile.src=img.src;}}else if(this.jsImageLoader){this.cachedImage=this.jsImageLoader.loadImage(src,this.mapTile);}else{this.mapTile.src=src;}}else{if(this.cachedImage){this.layer.map.imagesToLoad--;this.cachedImage.onload=null;}
this.mapTile.src=this.layer.map.blankImage.src;}}}
MapTile.prototype.getSourceWMS=function(w){var xmin=((this.x*this.layer.map.getTileWidthDeg())%360)-180;if(180-xmin<0.0000001)xmin=-180;var xmax=xmin+this.layer.map.getTileWidthDeg();var ymin=((this.y*this.layer.map.getTileHeightDeg()))-90;var ymax=ymin+this.layer.map.getTileHeightDeg();xmin-=(this.overlapX*this.layer.map.deg_px_x)
xmax+=(this.overlapX*this.layer.map.deg_px_x)
ymin-=(this.overlapY*this.layer.map.deg_px_y)
ymax+=(this.overlapY*this.layer.map.deg_px_y)
var src='request=GetMap';src+='&srs=EPSG:'+w.srs;src+='&version='+w.version;src+='&layers='+w.layers;src+="&BBOX="+xmin+","+ymin+","+xmax+","+ymax;src+="&width="+this.width;src+="&height="+this.height;src+='&transparent=true';src+='&format='+w.format;if(w.sld)src+='&sld='+w.sld;return src;}
MapTile.prototype.getSourceMVWMS=function(w){var xmin=((this.x*this.layer.map.getTileWidthDeg())%360)-180;if(180-xmin<0.0000001)xmin=-180;var xmax=xmin+this.layer.map.getTileWidthDeg();var ymin=((this.y*this.layer.map.getTileHeightDeg()))-90;var ymax=ymin+this.layer.map.getTileHeightDeg();xmin-=(this.overlapX*this.layer.map.deg_px_x)
xmax+=(this.overlapX*this.layer.map.deg_px_x)
ymin-=(this.overlapY*this.layer.map.deg_px_y)
ymax+=(this.overlapY*this.layer.map.deg_px_y)
var src='request=GetMap';src+='&datasource='+w.datasource;src+='&srs=EPSG:'+w.srs;src+='&version='+w.version;src+='&layers='+w.layers;src+="&BBOX="+xmin+","+ymin+","+xmax+","+ymax;src+="&width="+this.width;src+="&height="+this.height;src+='&transparent=true';src+='&format='+w.format;return src;}
MapTile.prototype.getSourceMVMapCache=function(w){var src='request='+w.request;src+='&zoomlevel='+this.layer.map.zoom;src+='&mx='+(this.x%this.layer.map.getTilesPerMapX());src+='&my='+this.y;src+='&mapcache='+w.datasource+"."+w.name;src+='&format='+w.format;return src;}
MapTile.prototype.getSourceMVBaseMap=function(w){var xmin=((this.x*this.layer.map.getTileWidthDeg())%360)-180;if(180-xmin<0.0000001)xmin=-180;var xmax=xmin+this.layer.map.getTileWidthDeg();var ymin=((this.y*this.layer.map.getTileHeightDeg()))-90;var ymax=ymin+this.layer.map.getTileHeightDeg();xmin-=(this.overlapX*this.layer.map.deg_px_x)
xmax+=(this.overlapX*this.layer.map.deg_px_x)
ymin-=(this.overlapY*this.layer.map.deg_px_y)
ymax+=(this.overlapY*this.layer.map.deg_px_y)
var src='request=GetMap';src+='&srs=EPSG:'+w.srs;src+='&version='+w.version;src+='&layers=';src+='&datasource='+w.datasource;src+='&basemap='+w.name;src+="&BBOX="+xmin+","+ymin+","+xmax+","+ymax;src+="&width="+this.width;src+="&height="+this.height;src+='&transparent=true';src+='&format='+w.format;return src;}
MapTile.prototype.getSourceTMS=function(w){var tpmx=this.layer.map.getTilesPerMapX()
var src=this.layer.map.zoom+'/'+(this.x%tpmx)+'/'+this.y;src+='.'+w.format;return src;}
MapTile.prototype.getSourceArcTMS = function(w) {
	var tpmx = this.layer.map.getTilesPerMapX();
	var tpmy = this.layer.map.getTilesPerMapY();
	return this.layer.map.zoom  + '/' + (tpmy - this.y - 1) +  '/' + (this.x % tpmx);
}
MapTile.prototype.kill=function(){this.layer.mapLayer.removeChild(this.mapTile);this.mapTile=null;this.layer=null;this.initX=null;this.initY=null;this.x=null;this.y=null;this.cachedImage=null;if(this.jsImageLoader){this.jsImageLoader.kill();this.jsImageLoader=null;}}
function OpacityInterface(map){this.map=map;this.closed=true;this.sliders=[];this.createOpacityInterfaceHTML();}
OpacityInterface.prototype.createOpacityInterfaceHTML=function(){var _this=this;var li=document.createElement('div');li.className='layer-panel';var w=this.map.mapViewport.style.width.split("px")[0];var h=Math.floor(this.map.mapViewport.style.height.split("px")[0]/4);li.style.bottom='0px';li.style.left='0px';li.style.width=w+'px';li.style.height=h+'px';li.style.fontWeight='bold';li.style.display='none';li.style.zIndex=999;this.li=li;var lititle=document.createElement('div');lititle.innerHTML='Toggle Opacity For Map Layers:';lititle.style.backgroundColor='black';lititle.style.color='white';lititle.style.height='1em';lititle.style.padding='3px';this.lititle=lititle;var licontents=document.createElement('div');licontents.style.height=(h-21)+'px';licontents.style.overflow='auto';licontents.style.borderTop='solid black 1px';licontents.style.color='white';licontents.style.position='relative';this.licontents=licontents;var cancel=document.createElement('img');cancel.src='scrollable_map/images/cancel.png';cancel.style.color='white';cancel.alt='X';cancel.className='popup-cancel';cancel.onclick=function(){_this.close();};this.cancel=cancel;this.map.mapViewport.appendChild(li);this.li.appendChild(lititle);this.li.appendChild(licontents);this.li.appendChild(cancel);}
OpacityInterface.prototype.resize=function(){}
OpacityInterface.prototype.open=function(){if(this.closed){this.draw();}}
OpacityInterface.prototype.draw=function(){var _this=this;for(var i=0;i<this.map.wmsLayers.length;i++){var layer=this.map.wmsLayers[i];var scale=this.map.getScale();if((scale>=layer.scaleMin&&scale<=layer.scaleMax)&&this.map.containsLayer(layer.id)){var lbl=document.createElement('span');lbl.innerHTML=layer.title;lbl.style.whiteSpace='nowrap';var sbc=document.createElement('div');sbc.layerid=layer.id;if(layer.opacity>=0&&layer.opacity<=100){var lid=layer.id;var f=function(value,sb){var lay=_this.map.getLayer(sb.parentElement.layerid);if(lay){lay.setOpacity(value);}}
var sb=new SliderBar(100,0,100,layer.opacity,sbc,f);this.sliders.push(sb);var div=document.createElement('div');div.className='opacity-layer';this.licontents.appendChild(div);div.appendChild(lbl);div.appendChild(sbc);}}}
this.li.style.display='block';this.closed=false;}
OpacityInterface.prototype.resize=function(){this.li.style.width=parseInt(this.map.mapViewport.style.width.split("px")[0],10)+'px';this.li.style.height=Math.floor((this.map.mapViewport.style.height.split("px")[0])/4)+'px';this.licontents.style.height=(Math.floor(this.map.mapViewport.style.height.split("px")[0],10)/4)-21+'px';}
OpacityInterface.prototype.redraw=function(){this.clear();this.draw();}
OpacityInterface.prototype.close=function(){this.clear();this.li.style.display='none';this.closed=true;}
OpacityInterface.prototype.clear=function(){var elems=this.licontents.childNodes;for(var i=0;i<elems.length;i++){this.licontents.removeChild(elems[i]);i--;}
this.sliders=[];}
function OverviewMap(map,parentElementId,wms_config,w,h){this.width=w||150;this.height=h||150;this.wms_config=wms_config;this.parentMap=map;this.parentElementId=parentElementId;this.createOverviewMapHTML();}
OverviewMap.prototype.createOverviewMapHTML=function(){var oc;var _this=this;if(this.parentElementId){oc=document.getElementById(this.parentElementId);}else{var oe=document.createElement('div');oe.className='map-overview-envelope';oe.style.width=(this.width+6)+'px';oe.style.height=(this.height+6)+'px';oc=document.createElement('div');oc.className='map-overview';var numOverviews=getElementsByClassName(document,'map-overview').length;oc.id='map-overview_'+numOverviews;var tov=document.createElement('div');tov.className='toggle-overview-button';tov.open=true;tov.overview=oe;tov.onclick=function(){if(this.open){this.style.backgroundImage="url('scrollable_map/images/overviewMax.PNG')";this.overview.style.height='0px'
this.overview.style.width='0px';this.open=false;}else{this.style.backgroundImage="url('scrollable_map/images/overviewMin.PNG')";this.overview.style.height=(_this.width+6)+'px';this.overview.style.width=(_this.height+6)+'px';this.open=true;}}
oe.appendChild(oc);this.parentMap.mapViewport.appendChild(oe);this.parentMap.mapViewport.appendChild(tov);}
var parentMapLL=this.parentMap.getCenterLatLon();this.map=new Map(parentMapLL[0],parentMapLL[1],0,128,128,3,3,this.width,this.height,this.wms_config,true,this.parentMap,oc.id);this.map.zoomInN(this.parentMap.zoom-2);this.map.addPanner();if(!this.parentElementId){oc.style.borderBottomWidth='0px';oc.style.borderRightWidth='0px';}}
OverviewMap.prototype.moveTo=function(lon,lat){this.map.moveTo(lon,lat);this.map.centerLL=this.map.getCenterLatLon();}
OverviewMap.prototype.zoomInN=function(n){this.map.zoomInN(n);}
OverviewMap.prototype.zoomOutN=function(n){this.map.zoomOutN(n);}
OverviewMap.prototype.jumpTo=function(lon,lat,zoom){this.map.jumpTo(lon,lat,zoom);this.map.centerLL=this.overviewMap.getCenterLatLon();}
OverviewMap.prototype.hidePanner=function(){this.map.panner.hide();}
OverviewMap.prototype.showPanner=function(){this.map.panner.show();}
OverviewMap.prototype.kill=function(){this.map.kill();}
function Panner(map){this.map=map;this.createPannerHTML();}
Panner.prototype.createPannerHTML=function(){var _this=this;var bbox=this.map.parentMap.getViewportBoundingBox();var tl_coords=this.map.getPixelFromLatLon(bbox.ymax,bbox.xmin);var br_coords=this.map.getPixelFromLatLon(bbox.ymin,bbox.xmax);this.width=br_coords[0]-tl_coords[0];this.height=br_coords[1]-tl_coords[1];var p=document.createElement('div');p.className='panner';p.onmousedown=function(event){_this.startPannerDrag(event);return false;};p.style.width=this.width+'px';p.style.height=this.height+'px';var pi=document.createElement('div');pi.className='panner-inner';pi.style.width=this.width+'px';pi.style.height=this.height+'px';this.p=p;this._centerPanner();this.p.appendChild(pi);this.map.mapViewport.appendChild(this.p);if(((this.width>(this.map.viewport_width/2))||(this.height>(this.map.viewport_height/2)))&&this.map.zoom>0){this.show();this.map.zoomOutN(1);this.kill();this.createPannerHTML();}else if(((this.width>(this.map.viewport_width))||(this.height>this.map.viewport_height))&&this.map.zoom==0){this._centerPanner();this.hide();}else if(((this.width<(this.map.viewport_width/4))&&(this.height<this.width))&&this.map.zoom<this.map.max_zoom){this.show();this.map.zoomInN(1);this.kill();this.createPannerHTML();}else if(((this.width<(this.map.viewport_width/4))&&(this.height<this.width))&&this.map.zoom==this.map.max_zoom){this._centerPanner();this.hide();}else if(((this.height<(this.map.viewport_height/4))&&(this.width<this.height))&&this.map.zoom<this.map.max_zoom){this.show();this.map.zoomInN(1);this.kill();this.createPannerHTML();}else if(((this.height<(this.map.viewport_height/4))&&(this.width<this.height))&&this.map.zoom==this.map.max_zoom){this._centerPanner();this.hide();}}
Panner.prototype._centerPanner=function(){var bbox=this.map.parentMap.getViewportBoundingBox();var coords=this.map.getPixelFromLatLon(bbox.ymax,bbox.xmin);this.left=coords[0];this.top=coords[1];if(this.left>this.map.viewport_width)this.left=this.left%this.map.tileWidth;var cx=this.left+(this.width/2)
var cy=this.top+(this.height/2)
var ll=this.map.getLatLonFromPixel(cx,cy);this.map.moveTo(ll[0],ll[1]);bbox=this.map.parentMap.getViewportBoundingBox();coords=this.map.getPixelFromLatLon(bbox.ymax,bbox.xmin);if(this.left>this.map.viewport_width)this.left=this.left%this.map.tileWidth;this.left=coords[0];this.top=coords[1];if(this.left>this.map.viewport_width)this.left=this.left%this.map.tileWidth;this.p.style.left=this.left+'px';this.p.style.top=this.top+'px';}
Panner.prototype.startPannerDrag=function(event){var _this=this;event=event||window.event;this.lastX=event.clientX;this.lastY=event.clientY;document.onmousemove=function(event){_this.pannerDrag(event);};document.onmouseup=function(event){_this.endPannerDrag(event);};this.testMapMoveIntv=setInterval(function(){_this.testMapMove();},1);}
Panner.prototype.pannerDrag=function(event){event=event||window.event;if(navigator.appVersion.indexOf("MSIE")!=-1)unselect(event);var curX=event.clientX;var curY=event.clientY;var dx=curX-this.lastX;var dy=curY-this.lastY;this.left+=dx;this.top+=dy;this.p.style.left=this.left+'px';this.p.style.top=this.top+'px';this.lastX=curX;this.lastY=curY;}
Panner.prototype.endPannerDrag=function(event){clearInterval(this.testMapMoveIntv);var cx=this.left+Math.floor(this.width/2);var cy=this.top+Math.floor(this.height/2);var ll=this.map.getLatLonFromPixel(cx,cy);this.map.moveTo(ll[0],ll[1]);this.map.centerLL=this.map.getCenterLatLon();this.map.updateComponentsAfterMove();this._centerPanner();document.onmousemove=null;document.onmouseup=null;}
Panner.prototype.testMapMove=function(){var speed=2;var x=0;var y=0
if(this.left<0){x=-this.left;if(x>speed)x=speed;}else if((this.left+this.width)>(this.map.viewport_width)){x=-1*((this.left+this.width)-(this.map.viewport_width));if(x<-speed)x=-speed;}
if(this.top<0){y=-this.top;if(y>speed)y=speed;}else if((this.top+this.height)>(this.map.viewport_height)){y=-1*((this.top+this.height)-(this.map.viewport_height));if(y<-speed)y=-speed;}
this.map.moveBy(x,y);}
Panner.prototype.show=function(){this.p.style.display='block';}
Panner.prototype.hide=function(){this.p.style.display='none';}
Panner.prototype.kill=function(){this.p.onmousedown=null;this.map.mapViewport.removeChild(this.p);}
function ScaleBar(map){this.map=map;this.createScaleBarHTML();this.calculateScale();}
ScaleBar.prototype.createScaleBarHTML=function(){var sb=document.createElement("div");sb.className='scale-bars';this.scaleBar=sb;var sbm=document.createElement('div');sbm.className='scale-bar-mi'
sb.appendChild(sbm);this.scaleBarMI=sbm;var sbk=document.createElement('div');sbk.className='scale-bar-km';sb.appendChild(sbk);this.scaleBarKM=sbk;this.map.mapViewport.appendChild(this.scaleBar);}
ScaleBar.prototype.calculateScale=function(){this.scale('mi');this.scale('km');}
ScaleBar.prototype.scale=function(units){var vpbbox=this.map.getViewportBoundingBox();var baseScaleLat=vpbbox.ymin;var degPerPxLon=this.map.deg_px_y;var unitFactor=3963.0;var distanceUnit=" mi.";if(units=='km'){unitFactor=6377.0;distanceUnit=" km.";}
var rad=180/Math.PI;var barInDeg=60*degPerPxLon;var scale=unitFactor*Math.acos(Math.sin(baseScaleLat/rad)*Math.sin(baseScaleLat/rad)+
Math.cos(baseScaleLat/rad)*Math.cos(baseScaleLat/rad)*Math.cos((barInDeg/rad)-(0/rad)));var barScale=500;if(scale>=2500){barScale=5000;}else if(scale>=1000){barScale=2500;}else if(scale>=500){barScale=1000;}else if(scale>=250){barScale=500;}else if(scale>=100){barScale=250;}else if(scale>=50){barScale=100;}else if(scale>=25){barScale=50;}else if(scale>=10){barScale=25;}else if(scale>=5){barScale=10;}else if(scale>=2){barScale=5;}else if(scale>=1){barScale=2;}else if(scale>=0.5){barScale=1;}else{if(units=='mi'){distanceUnit=" ft.";}else{distanceUnit=" m.";}
if(scale>=0.2){barScale=0.5;}else if(scale>=0.1){barScale=0.25;}else if(scale>=0.05){barScale=0.1;}else if(scale>=0.025){barScale=0.05;}else if(scale>=0.01){barScale=0.025;}else if(scale>=0.005){barScale=0.01;}else if(scale>=0.0025){barScale=0.005;}else{barScale=0.005;}}
var barLength=rad*(Math.acos((Math.cos(barScale/unitFactor)-(Math.sin(baseScaleLat/rad)*Math.sin(baseScaleLat/rad)))/(Math.cos(baseScaleLat/rad)*Math.cos(baseScaleLat/rad))))/degPerPxLon;if(distanceUnit==" ft."){barScale*=5280;}
if(distanceUnit==" m."){barScale*=1000;}
if(units=='mi'){this.scaleBarMI.innerHTML=parseInt(barScale,10)+""+distanceUnit;this.scaleBarMI.style.width=barLength+'px';}else{this.scaleBarKM.innerHTML=parseInt(barScale,10)+""+distanceUnit;this.scaleBarKM.style.width=barLength+'px';}
return false;}
ScaleBar.prototype.kill=function(){}
function SliderBar(size,min,max,start_value,parentElement,onChangeCB){this.size=size;this.min=min;this.max=max;this.start_value=start_value;this.parentElement=parentElement;this.onChangeCB=onChangeCB;this.createSliderBarHTML();}
SliderBar.prototype.createSliderBarHTML=function(){var _this=this;this.container=document.createElement('div');this.container.className='sliderbar_container';this.container.style.width=(this.size+12)+'px';this.container.onclick=function(event){_this.jumpTo(event);};this.parentElement.appendChild(this.container);this.rail_main=document.createElement('div');this.rail_main.className='sliderbar-rail-main';this.rail_main.style.width=(this.size+8)+'px';this.container.appendChild(this.rail_main);this.rail_cap=document.createElement('div');this.rail_cap.className='sliderbar-rail-cap';this.rail_cap.style.left=(this.size+8)+'px';this.container.appendChild(this.rail_cap);this.knob=document.createElement('div');this.knob.className='sliderbar-knob';this.knob.style.left=Math.floor((this.size)*(this.start_value/100))+'px';this.knob.onmousedown=function(event){_this.startDrag(event);};this.container.appendChild(this.knob);}
SliderBar.prototype.startDrag=function(event){event=event||window.event;var _this=this;document.onmousemove=function(event){_this.drag(event);};document.onmouseup=function(event){_this.endDrag(event);};var mouse_pos=getRelativeCoords(event,this.container)[0];var knob_pos=parseInt((this.knob.style.left.split('px')[0]),10);this.last_pos=mouse_pos;this.grab_offset=(mouse_pos-knob_pos)-8;}
SliderBar.prototype.drag=function(event){event=event||window.event;var mouse_pos=getRelativeCoords(event,this.container)[0];var newpos=(mouse_pos-8)-this.grab_offset;if(newpos<0){newpos=0;}else if(newpos>this.size){newpos=this.size;}
this.knob.style.left=newpos+'px';if(navigator.appVersion.indexOf("MSIE")!=-1)unselect();this.getValue();}
SliderBar.prototype.endDrag=function(event){event=event||window.event;document.onmousemove=null;document.onmouseup=null;if(navigator.appVersion.indexOf("MSIE")!=-1)unselect();this.getValue();}
SliderBar.prototype.jumpTo=function(event){event=event||window.event;var mouse_pos=getRelativeCoords(event,this.container)[0];var newpos=mouse_pos-6;if(newpos<0)newpos=0;else if(newpos>this.size)newpos=this.size;this.knob.style.left=newpos+'px';if(navigator.appVersion.indexOf("MSIE")!=-1)unselect();this.getValue();}
SliderBar.prototype.getValue=function(){var knob_pos=parseInt((this.knob.style.left.split('px')[0]),10);var value=((this.max-this.min)/this.size)*knob_pos;if(this.onChangeCB)this.onChangeCB(value,this);}
SliderBar.prototype.kill=function(){this.knob.onmousedown=null;this.container.removeChild(this.knob);this.container.removeChild(this.rail_main);this.container.removeChild(this.rail_cap);this.parentElement.removeChild(this.container);this.parentElement.parentNode.removeChild(this.parentElement);}
var dragBBox=false;var dragBBoxMap=false;var initX=0;var initY=0;var px_off=0;var bbox_dragging=false;function zoomInToPoint(event,map){if(!bbox_dragging){event=event||window.event;var coordsPx=getRelativeCoords(event,map.pane);initX=coordsPx[0];initY=coordsPx[1];dragBBoxMap=map;dragBBox=document.createElement('div');dragBBox.className='drag-bbox';dragBBox.style.left=coordsPx[0]-px_off+'px';dragBBox.style.top=coordsPx[1]-px_off+'px';dragBBox.style.height='1px';map.pane.appendChild(dragBBox);document.onmousemove=dragZoomBBox;document.onmouseup=endZoomBBox;bbox_dragging=true;}else{killZoomBBox();}}
function dragZoomBBox(event){event=event||window.event;unselect();var mapCoords=getRelativeCoords(event,dragBBoxMap.pane)
var dx=mapCoords[0]-initX;if(dx<0){dx=-dx;dragBBox.style.left=mapCoords[0]-px_off+'px';}else{dragBBox.style.left=initX-px_off+'px';}
dragBBox.style.width=dx+'px';var dy=mapCoords[1]-initY;if(dy<0){dy=-dy;dragBBox.style.top=mapCoords[1]-px_off+'px';}else{dragBBox.style.top=initY-px_off+'px';}
dragBBox.style.height=dy+'px';}
function endZoomBBox(event){killZoomBBox();event=event||window.event;var mapCoords=getRelativeCoords(event,dragBBoxMap.pane)
var ll_init=dragBBoxMap.getLatLonFromPixel(initX-px_off,initY-px_off);var ll_end=dragBBoxMap.getLatLonFromPixel(mapCoords[0]-px_off,mapCoords[1]-px_off);var x1=ll_init[0];var y1=ll_init[1];var x2=ll_end[0];var y2=ll_end[1];var xmin=x1;var xmax=x2;if(x1>x2){xmin=x2;xmax=x1;}
var ymin=y1;var ymax=y2;if(y1>y2){ymin=y2;ymax=y1;}
if(Math.abs(initX-mapCoords[0])<10&&Math.abs(initY-mapCoords[1])<10){dragBBoxMap.moveTo(ll_end[0],ll_end[1]);dragBBoxMap.centerLL=dragBBoxMap.getCenterLatLon();dragBBoxMap.zoomInN(1);dragBBoxMap.centerLL=dragBBoxMap.getCenterLatLon();dragBBoxMap.updateComponentsAfterMove();}else{dragBBoxMap.fitToBBox(xmin,ymin,xmax,ymax);dragBBoxMap.centerLL=dragBBoxMap.getCenterLatLon();}
dragBBoxMap=null;}
function killZoomBBox(){dragBBox.style.display='none';dragBBox.parentNode.removeChild(dragBBox);dragBBox=null;document.onmousemove=null;document.onmouseup=null;bbox_dragging=false;}
function zoomOutToPoint(event,map){event=event||window.event;var coordsPx=getRelativeCoords(event,map.pane);var ll=map.getLatLonFromPixel(coordsPx[0],coordsPx[1]);map.zoomOutN(1);map.moveTo(ll[0],ll[1]);map.centerLL=map.getCenterLatLon();}
function sorter(t1,t2){if(t1.zdepth<t2.zdepth)return-1;if(t1.zdepth>t2.zdepth)return 1;return 0;}
function callLater(func){return(function(){});}
function unselect(){if(document.selection)
document.selection.empty();if(window.getSelection)
window.getSelection().removeAllRanges();}
function getPositionedEventCoords(evt){evt=(evt)?evt:window.event;var elem=(evt.target)?evt.target:evt.srcElement;var coords={left:0,top:0};if(evt.layerX){var borders={left:parseInt(getElementStyle(elem,"borderLeftWidth","border-left-width"),10),top:parseInt(getElementStyle(elem,"borderTopWidth","border-top-width"),10)};coords.left=evt.layerX-borders.left;coords.top=evt.layerY-borders.top;}else if(evt.offsetX){coords.left=evt.offsetX;coords.top=evt.offsetY;}
return coords;}
function getRelativeEventCoords(evt,listenerElement){var elem=(evt.target)?evt.target:evt.srcElement;if(elem==listenerElement||listenerElement==null)return getPositionedEventCoords(evt);var elmRelCoords=getRelativePosition(elem,listenerElement);var evtCoords=getPositionedEventCoords(evt);evtCoords.left+=elmRelCoords.left;evtCoords.top+=elmRelCoords.top;return evtCoords;}
function getElementStyle(elem,IEStyleAttr,CSSStyleAttr){if(window.getComputedStyle){var compStyle=window.getComputedStyle(elem,"");return compStyle.getPropertyValue(CSSStyleAttr);}else if(document.defaultView&&document.defaultView.getComputedStyle(elem,"")!=null){var compStyle=document.defaultView.getComputedStyle(elem,"");return compStyle.getPropertyValue(CSSStyleAttr);}else if(elem.currentStyle){return elem.currentStyle[IEStyleAttr];}
return"";}
function getElementPosition(elemID){var offsetTrail=document.getElementById(elemID);var offsetLeft=0;var offsetTop=0;while(offsetTrail){offsetLeft+=offsetTrail.offsetLeft;offsetTop+=offsetTrail.offsetTop;offsetTrail=offsetTrail.offsetParent;}
if(navigator.userAgent.indexOf("Mac")!=-1&&typeof document.body.leftMargin!="undefined"){offsetLeft+=document.body.leftMargin;offsetTop+=document.body.topMargin;}
return{left:offsetLeft,top:offsetTop};}
function getRelativePosition(child,parent){var offsetTrail=child;var offsetLeft=0;var offsetTop=0;var found=false;while(offsetTrail){offsetLeft+=offsetTrail.offsetLeft;offsetTop+=offsetTrail.offsetTop;offsetTrail=offsetTrail.offsetParent;if(offsetTrail==parent){found=true;break;}}
if(found){return{left:offsetLeft,top:offsetTop};}else{return{left:0,top:0};}}
function getElementsByClassName(node,classname){var a=[];var re=new RegExp('\\b'+classname+'\\b');var els=node.getElementsByTagName("*");for(var i=0,j=els.length;i<j;i++)
if(re.test(els[i].className))a.push(els[i]);return a;}
function getRelativeCoords(evt,elem){var coords=[];var sx,sy;if(self.pageYOffset){sx=self.pageXOffset;sy=self.pageYOffset;}else if(document.documentElement&&document.documentElement.scrollTop){sx=document.documentElement.scrollLeft;sy=document.documentElement.scrollTop;}else if(document.body){sx=document.body.scrollLeft;sy=document.body.scrollTop;}
var x=evt.clientX-findPosX(elem)+sx;var y=evt.clientY-findPosY(elem)+sy;coords.push(x);coords.push(y);return coords;}
function findPosX(obj)
{var curleft=0;if(obj.offsetParent)
{while(obj.offsetParent)
{curleft+=obj.offsetLeft
obj=obj.offsetParent;}}
else if(obj.x)
curleft+=obj.x;return curleft;}
function findPosY(obj)
{var curtop=0;if(obj.offsetParent)
{while(obj.offsetParent)
{curtop+=obj.offsetTop
obj=obj.offsetParent;}}
else if(obj.y)
curtop+=obj.y;return curtop;}
function getWindowDimensions(){var width=0;var height=0;if(window.innerWidth){width=window.innerWidth;}else{width=document.documentElement.clientWidth;}
if(window.innerHeight){height=window.innerHeight;}else{height=document.documentElement.clientHeight;}
return{width:width,height:height};}
function getNodeValue(node,tagname,default_val){var elems=node.getElementsByTagName(tagname);if(elems&&elems[0]&&elems[0].firstChild&&elems[0].firstChild.nodeValue){return elems[0].firstChild.nodeValue;}
return default_val;}
function createElement(type,name){var element=null;try{element=document.createElement('<'+type+' name="'+name+'">');}catch(e){}
if(!element){element=document.createElement(type);element.name=name;}
return element;}
function WmsLayer(name,title,id,baseUrl,zdepth,classTheme,className,scaleMin,scaleMax,boundingbox,legendUrl,metaUrl,url_layers,description,sld,srs,version,request,serviceType,format,opacity,overlap,datasource,isHidden,owner){this.id=id;this.title=title;this.name=name;this.baseUrl=baseUrl;this.zdepth=zdepth;this.scaleMin=scaleMin;this.scaleMax=scaleMax;this.boundingbox=boundingbox;this.classTheme=classTheme;this.className=className;this.legendUrl=legendUrl;this.metaUrl=metaUrl;this.layers=url_layers;this.description=description;this.sld=sld;this.srs=srs;this.version=version;this.opacity=opacity;this.request=request;this.serviceType=serviceType;this.format=format;this.overlap=overlap;this.datasource=datasource;this.isHidden=isHidden;this.owner=owner;}
WmsLayer.prototype.kill=function(){this.id=null;this.title=null;this.name=null;this.baseUrl=null;this.zdepth=null;this.scaleMin=null;this.scaleMax=null;this.legendUrl=null;this.metaUrl=null;this.layers=null;this.srs=null;this.version=null;this.request=null;this.serviceType=null;this.format=null;this.overlap=null;this.datasource=null;this.isHidden=null;this.owner=null;}
function WmsLayerManager(map,url){this.map=map;this.url=url;this.urls=[];this.urls.push(url);this.loading=0;this.defaultLoad=[];this.defaultLoad.push(url);this.hiddenLoad=[];this.layerNames=[];this.layerNames[0]='Default Layer Set';this.defaultLayers=[];this.selectedUnavailable=[];this.numFilesLoading=0;this.fetchWmsLayers();}
WmsLayerManager.prototype.loadWmsLayers=function(url,name,isDefault,isHidden){this.isLoading=true;this.loading++;this.numFilesLoading++;this.layerNames[this.layerNames.length]=name;if(isHidden)this.hiddenLoad.push(this.numFilesLoading);url+="?nocache="+(new Date).getTime();if(isDefault)this.defaultLoad.push(url);this.urls.push(url)
var loaded=this.fetchWmsLayers();if(!loaded)this.loading--;}
WmsLayerManager.prototype.fetchWmsLayers=function(){var _this=this;if(!this.ar){this.ar=new AjaxRequest();var args='1=1&scale='+this.map.getScale()+'&bbox='+this.map.getViewportBoundingBoxString();this.ar.asyncRequest('GET',this.urls[this.loading],args,function(){_this.fillWmsLayersArray();});return true;}else{return false;}}
WmsLayerManager.prototype.fillWmsLayersArray=function(){if(this.ar){var isHidden=false;for(var i=0;i<this.hiddenLoad.length;i++){if(this.hiddenLoad[i]==this.loading){isHidden=true;break;}}
var layersXML=this.ar.getResponseXML();if(layersXML){var services=layersXML.getElementsByTagName('Service');for(var i=0;i<services.length;i++){var version=getNodeValue(services[i],'Version');var baseUrl=getNodeValue(services[i],'GetMapURL');var serviceType=getNodeValue(services[i],'serviceType','wms');var formatType=getNodeValue(services[i],'format','image/png');var request=getNodeValue(services[i],'request','GetMap');var layers=services[i].getElementsByTagName('Layer');for(var j=0;j<layers.length;j++){var datasource=getNodeValue(layers[j],'datasource');var overlapTiles=getNodeValue(layers[j],'overlapTiles');var name=getNodeValue(layers[j],'Name');var title=getNodeValue(layers[j],'Title');var id=layers[j].getAttribute('id');var zdepth=layers[j].getElementsByTagName('Classification')[0].getAttribute('zdepth');var classTheme=getNodeValue(layers[j].getElementsByTagName('Classification')[0],'Theme');var className=getNodeValue(layers[j].getElementsByTagName('Classification')[0],'Name');var srs=getNodeValue(layers[j],'SRS');var scaleMin=getNodeValue(layers[j],'MinScale',0);var scaleMax=getNodeValue(layers[j],'MaxScale',10);var layer_name=getNodeValue(layers[j],'Name');var re=RegExp("\\s","g");var url_layers=layer_name.replace(re,'+');var legendUrl=getNodeValue(layers[j],'LegendURL');var metaUrl=getNodeValue(layers[j],'MetadataURL');var opacity=getNodeValue(layers[j],'opacity',100);var boundingbox=getNodeValue(layers[j],'LatLon','-180,-90,180,90');var description=getNodeValue(layers[j],'Description','No description');var sld=getNodeValue(layers[j],'SLDURL');var layer_exists=false
for(var k=0;k<this.map.wmsLayers.length;k++){if(this.map.wmsLayers[k].id==id){layer_exists=true;break;}}
if(!layer_exists){this.appendDefaultLayer(new WmsLayer(name,title,id,baseUrl,-1*zdepth,classTheme,className,scaleMin,scaleMax,boundingbox,legendUrl,metaUrl,url_layers,description,sld,srs,version,request,serviceType,formatType,opacity,overlapTiles,datasource,isHidden,this.layerNames[this.loading]));}}}}}
layersXML=null;this.ar.abort();this.ar=false;if(this.loading<(this.urls.length-1)){this.loading++;this.fetchWmsLayers();}else{this.isLoading=false;if(this.onloaded){this.onloaded();this.onloaded=null;}}}
WmsLayerManager.prototype.cancelFetchLayers=function(){if(this.ar)this.ar.abort();this.ar=null;}
WmsLayerManager.prototype.updateWmsLayers=function(){this.isLoading=true;this.loading=0;if(this.ar)this.ar.abort();this.ar=null;this.fetchWmsLayers();var scale=this.map.getScale();var wms=this.map.wmsLayers
for(var i=0;i<this.selectedUnavailable.length;i++){if(this.mapLayerOverlap(this.selectedUnavailable[i].boundingbox)&&(scale>=this.selectedUnavailable[i].scaleMin&&scale<=this.selectedUnavailable[i].scaleMax)){if(!this.map.containsLayer(this.selectedUnavailable[i].id)){this.map.appendLayer(this.selectedUnavailable[i].id);this.selectedUnavailable.splice(i,1);i--;}}}
for(var i=0;i<wms.length;i++){if(!(this.mapLayerOverlap(wms[i].boundingbox)&&(scale>=wms[i].scaleMin&&scale<=wms[i].scaleMax))){if(this.map.containsLayer(wms[i].id)){this.map.removeLayer(wms[i].id);this.selectedUnavailable.push(wms[i]);}}}}
WmsLayerManager.prototype.appendDefaultLayer=function(layer){var scale=this.map.getScale();if(this.mapLayerOverlap(layer.boundingbox)&&(scale>=layer.scaleMin&&scale<=layer.scaleMax)){this.map.wmsLayers.push(layer);for(var i=0;i<this.defaultLoad.length;i++){if(this.urls[this.loading]==this.defaultLoad[i]){this.map.appendLayer(layer.id);this.defaultLayers.push(layer);break;}}}}
WmsLayerManager.prototype.getAvailableDefaultLayers=function(){var availLayers=[];var scale=this.map.getScale();for(var i=0;i<this.defaultLayers.length;i++){var layer=this.defaultLayers[i];if(this.mapLayerOverlap(this.defaultLayers[i].boundingbox)&&(scale>=this.defaultLayers[i].scaleMin&&scale<=this.defaultLayers[i].scaleMax)){availLayers.push(layer);}}
return availLayers;}
WmsLayerManager.prototype.getAllAvailableLayers=function(){var available=[];var scale=this.map.getScale();var bbox=this.map.getViewportBoundingBox();for(var i=0;i<this.map.wmsLayers.length;i++){if(this.mapLayerOverlap(this.map.wmsLayers[i].boundingbox)&&(scale>=this.map.wmsLayers[i].scaleMin&&scale<=this.map.wmsLayers[i].scaleMax)){available.push(this.map.wmsLayers[i]);}}
return available;}
WmsLayerManager.prototype.mapLayerOverlap=function(tbb){tbb=tbb||'-180,-90,180,90';var mapbbox=this.map.getViewportBoundingBox();var tbb=tbb.split(',');var bbox={xmin:tbb[0],ymin:tbb[1],xmax:tbb[2],ymax:tbb[3]};if((mapbbox.xmin<bbox.xmin&&bbox.xmin<mapbbox.xmax)&&(mapbbox.ymin<bbox.ymin&&bbox.ymin<mapbbox.ymax)){return true;}else if((mapbbox.xmin<bbox.xmax&&bbox.xmax<mapbbox.xmax)&&(mapbbox.ymin<bbox.ymin&&bbox.ymin<mapbbox.ymax)){return true;}else if((mapbbox.xmin<bbox.xmin&&bbox.xmin<mapbbox.xmax)&&(mapbbox.ymin<bbox.ymax&&bbox.ymax<mapbbox.ymax)){return true;}else if((mapbbox.xmin<bbox.xmax&&bbox.xmax<mapbbox.xmax)&&(mapbbox.ymin<bbox.ymax&&bbox.ymax<mapbbox.ymax)){return true;}else if((bbox.xmin<mapbbox.xmin&&mapbbox.xmin<bbox.xmax)&&(bbox.ymin<mapbbox.ymin&&mapbbox.ymin<bbox.ymax)){return true}else if((bbox.xmin<mapbbox.xmax&&mapbbox.xmax<bbox.xmax)&&(bbox.ymin<mapbbox.ymin&&mapbbox.ymin<bbox.ymax)){return true;}else if((bbox.xmin<mapbbox.xmin&&mapbbox.xmin<bbox.xmax)&&(bbox.ymin<mapbbox.ymax&&mapbbox.ymax<bbox.ymax)){return true;}else if((bbox.xmin<mapbbox.xmax&&mapbbox.xmax<bbox.xmax)&&(bbox.ymin<mapbbox.ymax&&mapbbox.ymax<bbox.ymax)){return true;}else if((mapbbox.xmin>bbox.xmin&&bbox.xmax>mapbbox.xmax)&&(mapbbox.ymin<bbox.ymin&&bbox.ymax<mapbbox.ymax)){return true;}else if((mapbbox.xmin<bbox.xmin&&bbox.xmax<mapbbox.xmax)&&(mapbbox.ymin>bbox.ymin&&bbox.ymax>mapbbox.ymax)){return true;}else{return false;}}
WmsLayerManager.prototype.kill=function(){this.map=null;this.url=null;for(var i=0;i<this.defaultLayers.length;i++){this.defaultLayers[i].kill();this.defaultLayers[i]=null;}
this.defaultLayers=null;for(var i=0;i<this.selectedUnavailable.length;i++){this.selectedUnavailable[i].kill();this.selectedUnavailable[i]=null;}
this.selectedUnavailable=null;}
function ZoomSlider(map,zoom_levels,hide_slider){this.map=map;this.hide_slider=hide_slider;if(zoom_levels>18&&(zoom_levels>0&&zoom_levels<3)){zoom_levels=10;}
this.level=this.map.zoom;this.y=((zoom_levels-this.map.zoom)-1)*10;this.ypos=this.y;this.zoom_levels=zoom_levels;this.createZoomSliderHTML();}
ZoomSlider.prototype.createZoomSliderHTML=function(){var _this=this;var zoom_in=document.createElement('div');zoom_in.className='zoom-in-button clearfix';zoom_in.onclick=function(){_this.map.zoomInN(1);};this.zoom_in=zoom_in;var zoom_out=document.createElement('div');zoom_out.className='zoom-out-button';zoom_out.onclick=function(){_this.map.zoomOutN(1);};if(this.hide_slider){zoom_out.style.top='25px'}else{zoom_out.style.top=(this.zoom_levels*10)+30+'px'}
this.zoom_out=zoom_out;var rail=document.createElement('div');rail.className='slider-rail';if(this.hide_slider)rail.style.display='none';this.rail=rail;var rail_top=document.createElement('div');rail_top.className='rail-top';var rail_mid=document.createElement('div');rail_mid.className='rail-mid';rail_mid.style.height=(this.zoom_levels*10)+'px';rail_mid.onmousedown=function(event){_this.zoomSliderJumpTo(event);};this.rail_mid=rail_mid;var rail_bottom=document.createElement('div');rail_bottom.className='rail-bottom';var slider_handle=document.createElement('div');slider_handle.className='slider-handle';slider_handle.style.top=(((this.zoom_levels-this.map.zoom)-1)*10)+2+'px';slider_handle.onmousedown=function(event){_this.startDrag(event);};this.slider_handle=slider_handle;rail.appendChild(rail_top)
rail.appendChild(rail_mid)
rail.appendChild(rail_bottom)
rail.appendChild(slider_handle);var parEl=document.getElementById(this.map.parentElementId);this.map.mapViewport.appendChild(this.zoom_in);if(this.zoom_levels)this.map.mapViewport.appendChild(this.rail);this.map.mapViewport.appendChild(this.zoom_out);}
ZoomSlider.prototype.startDrag=function(evt){this.slider_handle.style.cursor='url(scrollable_map/images/handclose.cur), pointer';this.rail_mid.style.cursor='url(scrollable_map/images/handclose.cur), pointer';var _this=this;evt=(evt)?evt:window.event;this.lastMouseY=evt.clientY;this.curMouseY=this.lastMouseY;document.onmousemove=function(event){_this.zoomSliderDrag(event);};document.onmouseup=function(){_this.zoomSliderEndDrag();};return false;}
ZoomSlider.prototype.zoomSliderDrag=function(evt){evt=(evt)?evt:window.event;this.curMouseY=evt.clientY;var dy=this.curMouseY-this.lastMouseY;this.moveBy(dy);this.lastMouseY=this.curMouseY;unselect(evt);return false;}
ZoomSlider.prototype.zoomSliderJumpTo=function(evt){evt=(evt)?evt:window.event;var coords=getRelativeEventCoords(evt,this.rail_mid)
this.moveTo(coords.top-5);return false;}
ZoomSlider.prototype.zoomSliderEndDrag=function(){this.slider_handle.style.cursor='';this.rail_mid.style.cursor='pointer';var _this=this;var oldLevel=this.level;this.y=this.ypos;var ypos=this.ypos;var newLevel=Math.floor((((this.zoom_levels-1)*10)-ypos)/10);if(oldLevel!=newLevel){var n=newLevel-oldLevel;this.level=newLevel;if(n>0){this.map.zoomInN(n);}else if(n<0){this.map.zoomOutN(-n);}}
document.onmousemove=null;document.onmouseup=null;return false;}
ZoomSlider.prototype.moveBy=function(dy){this.y+=dy;if(this.y>=0&&this.y<=((this.zoom_levels-1)*10)){this.ypos=Math.floor((this.y+3)/10)*10;if(this.ypos<0)this.ypos=0;if(this.ypos>((this.zoom_levels-1)*10))this.ypos=((this.zoom_levels-1)*10);this.slider_handle.style.top=(this.ypos+2)+"px";}else{if(this.y<0){this.slider_handle.style.top='2px';}else{this.slider_handle.style.top=((this.zoom_levels-1)*10)+2+'px';}}}
ZoomSlider.prototype.moveTo=function(y){this.y=y;this.ypos=Math.floor((this.y+3)/10)*10;this.slider_handle.style.top=(this.ypos+2)+"px";this.zoomSliderEndDrag();}
ZoomSlider.prototype.moveToZoomLevel=function(zoom){this.level=zoom;this.y=(((this.zoom_levels-1)-zoom)*10);this.ypos=Math.floor((this.y+3)/10)*10;this.slider_handle.style.top=(this.ypos+2)+"px";}
ZoomSlider.prototype.kill=function(){this.level=null;this.y=null;this.ypos=null;this.rail_mid.onmousedown=null;this.rail_mid=null;this.slider_handle.onmousedown=null;this.slider_handle=null;this.map=null;}