db=function(eb){var fb="";for(var i in eb)fb+="'"+i+"' : "+eb[i]+" ";return fb;}
MLMakeRelativeUrl=function(cg,dg){var xc=cg.lastIndexOf("\x2F");var eg="";if(xc>=0)eg+=cg.substring(0,xc+1);eg+=dg;return eg;}
;MLTileDataMapType.prototype.cache=null;MLTileDataMapType.prototype.opacity=1.0;MLTileDataMapType.prototype.bounds=null;MLTileDataMapType.prototype.getTileUrl=null;MLTileDataMapType.prototype.baseUrl="";MLTileDataMapType.prototype.name="MLTileData";MLTileDataMapType.prototype.alt="MLTileData Tiles";MLTileDataMapType.prototype.tileSize=new google.maps.Size(256,256);MLTileDataMapType.prototype.minZoom=0;MLTileDataMapType.prototype.maxZoom=-1;MLTileDataMapType.prototype.tileMaxZoom=-1;function MLTileDataMapType(){this.cache=Array();this.opacity=1.0;}
MLTileDataMapType.prototype.getTile=function(fg,zoom,gg){var hg=false;var f="";if((!MLList.zoomPastLimit)&&(this.tileMaxZoom>=0)&&(zoom>this.tileMaxZoom)){hg=true;}
else{var c=Math.pow(2,zoom);var ig=fg.x,jg=fg.y;if(ig<0)ig=c+ig%c;if(ig>=c)ig=ig%c;if(jg<0)hg=true;if(jg>=c)hg=true;if((zoom>0)&&(this.bounds!=null)){var x=360/c*ig-180;var y=180-360/c*jg;var kg=x+360/c;var lg=y-360/c;var qd=x;var pd=(2.0*Math.atan(Math.exp(y/180*Math.PI))-Math.PI/2.0)*180/Math.PI;var mg=kg;var ng=(2.0*Math.atan(Math.exp(lg/180*Math.PI))-Math.PI/2.0)*180/Math.PI;var og=new google.maps.LatLngBounds(new google.maps.LatLng(ng,qd),new google.maps.LatLng(pd,mg));if(!og.intersects(this.bounds)){hg=true;}
;}
if(!hg){var d=ig;var e=jg;f="t";for(var g=0;g<zoom;g++){c/=2;if(e<c){if(d<c){f+="q"}
else{f+="r";d-=c}
}
else{if(d<c){f+="t";e-=c}
else{f+="s";d-=c;e-=c}
}
}
}
else{f="blank-tile";}
}
var rb=gg.createElement('IMG');rb.id="t_"+f;rb.style.width=this.tileSize.width+'px';rb.style.height=this.tileSize.height+'px';if((!hg)&&(this.tileMaxZoom>=0)&&(zoom>this.tileMaxZoom)){rb.src=MLList.zoomPastWebService+"?z="+this.tileMaxZoom+"&t="+f+"&u="+this.baseUrl;}
else{rb.src=this.getTileUrl(f);}
rb.style.opacity=this.opacity;rb.style.filter="alpha(opacity="+this.opacity*100+")";this.cache.push(rb);return rb;}
MLTileDataMapType.prototype.realeaseTile=function(pg){var tb=this.cache.indexOf(pg);if(tb!=-1)this.cache.splice(tb,1);pg=null;}
MLTileDataMapType.prototype.setOpacity=function(qg){this.opacity=qg;for(var i=0;i<this.cache.length;i++){this.cache[i].style.opacity=qg;this.cache[i].style.filter="alpha(opacity="+qg*100+")";}
}
MLTileDataMapType.prototype.getOpacity=function(){return this.opacity;}
function MLData(){this.mapTitle="TITLE";this.userData=null;this.isLoaded=false;this.isEnabled=false;this.isFeatureClickable=false;}
MLData.prototype.getBounds=function(){return null;}
MLTileData.prototype=new MLData();MLTileData.prototype.constructor=MLTileData;function MLTileData(){MLData.call(this);this.tileUrl="";this.mapTitle="TITLE";this.overlay=null;}
function MLTileData(cg,rg,sg,tg,dg,ug,vg,wg,xg){MLData.call(this);this.mapTitle=rg;this.mapBounds=sg;if(this.mapBounds){var yg=this.mapBounds.getSouthWest().lng();var zg=this.mapBounds.getNorthEast().lng();if(yg>=zg){var $g=this.mapBounds.getSouthWest().lat();var _g=this.mapBounds.getNorthEast().lat();if(yg>=180)yg=179.9999;if(zg<=-180)zg=-179.9999;this.mapBounds=new google.maps.LatLngBounds(new google.maps.LatLng($g,zg),new google.maps.LatLng(_g,yg));}
}
this.maxZoomLevel=tg;this.tileUrl=dg;this.colours=ug;this.descriptions=vg;this.isFeatureClickable=wg;this.userData=xg;this.isLoaded=true;this.isEnabled=true;}
MLTileData.prototype.getBounds=function(){return this.mapBounds;}
MLTileData.prototype.getOverlay=function(){if(this.overlay!=null){return this.overlay;}
else{this.overlay=new MLTileDataMapType();this.overlay.bounds=this.mapBounds;this.overlay.maxZoom=22;this.overlay.tileMaxZoom=this.maxZoomLevel;this.overlay.baseUrl=this.tileUrl;this.overlay.getTileUrl=function(f){return this.baseUrl+"/"+f+".png";}
return this.overlay;}
}
MLTileData.prototype.getColourScaleHTML=function(){var ah=this.mapTitle;var bh="";var ch="000000";if((this.colours!=null)&&(this.descriptions!=null)){for(var i=0;i<this.colours.length;i++){var dh=this.colours[i]&0xffffff;var eh=dh.toString(16);eh=ch.substring(0,6-eh.length)+eh;bh+="<tr><td bgcolor=\"#"+eh+"\" class=\"scale_colour\">&nbsp;</td>";bh+="<td>"+this.descriptions[i]+"</td></tr>";}
}
else if(this.xmlUrl.length>0){var xf=GXmlHttp.create();xf.open("GET",this.xmlUrl,false);xf.send(null);var fh=GXml.parse(xf.responseText);ah=GXml.value(fh.documentElement.getElementsByTagName("maptitle")[0]);var gh=fh.documentElement.getElementsByTagName("colourThreshold");for(var i=0;i<gh.length;i++){var dh=GXml.value(gh[i].getElementsByTagName("colour")[0]);var hh=GXml.value(gh[i].getElementsByTagName("description")[0]);bh+="<tr><td bgcolor=\"#"+dh.substr(2)+"\" class=\"scale_colour\">&nbsp;</td>";bh+="<td>"+hh+"</td></tr>";}
}
return"<p>"+ah+"</p><table>"+bh+"</table>";}
MLKMLData.prototype=new MLData();MLKMLData.prototype.constructor=MLKMLData;function MLKMLData(ih,jh,kh){MLData.call(this);this.overlay=new google.maps.KmlLayer(jh);this.KMLUrl=jh;this.mapTitle=ih;this.userData=kh;this.isLoaded=true;this.isEnabled=true;}
MLKMLData.prototype.getBounds=function(){return this.overlay.getDefaultViewport();}
MLKMLData.prototype.getOverlay=function(){return this.overlay;}
MLKMLData.prototype.getColourScaleHTML=function(){return"";}
MLMapDescriptorData.prototype=new MLTileData();MLMapDescriptorData.prototype.constructor=MLMapDescriptorData;function MLMapDescriptorData(rg,sg,lh,mh,nh,ug,vg,wg,xg){MLTileData.call(this);this.mapTitle=rg;this.mapBounds=sg;this.renderServerPattern=lh;this.mapDataDescriptorUrl=mh;this.timeTag=nh;this.colours=ug;this.descriptions=vg;this.isFeatureClickable=wg;this.userData=xg;this.isLoaded=true;this.isEnabled=true;}
MLMapDescriptorData.prototype.getOverlay=function(){if(this.overlay!=null){return this.overlay;}
else{this.overlay=new MLTileDataMapType();this.overlay.bounds=null;this.overlay.maxZoom=22;this.overlay.tileMaxZoom=-1;this.overlay.baseUrl=this.renderServerPattern.replace("\x7B0\x7D",this.mapDataDescriptorUrl);if(this.overlay.baseUrl.indexOf("s=\x7B1\x7D")>=0){this.overlay.baseUrl=this.overlay.baseUrl.replace("\x7B1\x7D",this.timeTag);this.overlay.getTileUrl=function(f){return this.baseUrl.replace("\x7B2\x7D",f);}
}
else{this.overlay.getTileUrl=function(f){return this.baseUrl.replace("\x7B1\x7D",f);}
}
return this.overlay;}
}
function MLList(map){this.gmap=map;this.isFeatureClickEnabled=false;this.featureDragTime=new Date();this.featureEventHandle=null;this.onfeaturechange=null;this.featureInfoWindow=null;this.xlayers=new Array();}
;MLList.zoomPastLimit=true;MLList.zoomPastWebService="ZoomInHandler.ashx";MLList.prototype.isTileLayer=function(oh){if((oh<0)||(oh>=this.xlayers.length))return false;return this.xlayers[oh]instanceof MLTileData;}
;MLList.prototype.isKMLLayer=function(oh){if((oh<0)||(oh>=this.xlayers.length))return false;return this.xlayers[oh]instanceof MLKMLData;}
;MLList.prototype.getNumLayers=function(){return this.xlayers.length;}
;MLList.prototype.getIsLoaded=function(oh){if((oh<0)||(oh>=this.xlayers.length))return false;return this.xlayers[oh].isLoaded;}
;MLList.prototype.getIsEnabled=function(oh){if((oh<0)||(oh>=this.xlayers.length))return false;return this.xlayers[oh].isEnabled;}
;MLList.prototype.getOpacity=function(oh){if((oh<0)||(oh>=this.xlayers.length))return-1;if(this.xlayers[oh]instanceof MLKMLData)return 1.0;return this.xlayers[oh].getOverlay().getOpacity();}
;MLList.prototype.getMapTitle=function(oh){if((oh<0)||(oh>=this.xlayers.length))return"Index "+oh+" is out of bounds";return this.xlayers[oh].mapTitle;}
;MLList.prototype.getMapBounds=function(oh){if((oh<0)||(oh>=this.xlayers.length))return null;return this.xlayers[oh].getBounds();}
;MLList.prototype.getMaxZoomLevel=function(oh){if((oh<0)||(oh>=this.xlayers.length))return null;return this.xlayers[oh].maxZoomLevel;}
;MLList.prototype.getAllMaxZoomLevel=function(){if(this.zoomPastLimit)return this.gmap.getCurrentMapType().getMaximumResolution();var ph=0;for(var i=0;i<this.xlayers.length;i++)if(this.xlayers[i].maxZoomLevel>ph)ph=this.xlayers[i].maxZoomLevel;return ph;}
;MLList.prototype.getColourScaleColours=function(oh){if((oh<0)||(oh>=this.xlayers.length))return null;return this.xlayers[oh].colours;}
;MLList.prototype.getColourScaleDescriptions=function(oh){if((oh<0)||(oh>=this.xlayers.length))return null;return this.xlayers[oh].descriptions;}
;MLList.prototype.getIsClickable=function(oh){if((oh<0)||(oh>=this.xlayers.length))return null;return this.xlayers[oh].isFeatureClickable;}
;MLList.prototype.getUserData=function(oh){if((oh<0)||(oh>=this.xlayers.length))return null;return this.xlayers[oh].userData;}
;MLList.prototype.setMapTitle=function(oh,ah){if((oh<0)||(oh>=this.xlayers.length))return;this.xlayers[oh].mapTitle=ah;}
;MLList.prototype.setIsEnabled=function(oh,yc){if((oh<0)||(oh>=this.xlayers.length))return;if(this.xlayers[oh].isEnabled==yc)return;this.xlayers[oh].isEnabled=yc;this.rebuildGMap();}
;MLList.prototype.refreshOpacity=function(){for(var i=0;i<this.xlayers.length;i++)this.setOpacity(i,this.xlayers[i].opacity);}
;MLList.prototype.setOpacity=function(oh,qg){if((oh<0)||(oh>=this.xlayers.length))return;if(!this.xlayers[oh]instanceof MLTileData)return;this.xlayers[oh].getOverlay().setOpacity(qg);return;}
;MLList.prototype.setUserData=function(oh,nb){if((oh<0)||(oh>=this.xlayers.length))return;this.xlayers.userData=nb;}
MLList.prototype.getTileCoords=function(e){var x=0,y=0;if(e.offsetX){x=e.offsetX;y=e.offsetY;}
else{x=e.clientX;y=e.clientY;var eb=e.target;while(eb){x-=eb.offsetLeft;y-=eb.offsetTop;eb=eb.offsetParent;}
}
var kf=this.gmap.getContainer();var latlng=this.gmap.fromContainerPixelToLatLng(new GPoint(e.clientX-kf.offsetLeft,e.clientY-kf.offsetTop));var name=e.srcElement?e.srcElement.src:e.target.src;if(!name)return;var xc=name.lastIndexOf("\x2F");var qh=name.lastIndexOf("t=");if(qh>xc)xc=qh+1;if(xc>=0)name=name.substring(xc+1);xc=name.lastIndexOf(".");if(xc>=0)name=name.substring(0,xc);return{'tileX':x,'tileY':y,'tileName':name,'latLng':latlng}
;}
MLList.prototype.getTileName=function(rh,zoom){var sh=this.gmap.getProjection().fromLatLngToPoint(rh);var c=256;var d=sh.x;var e=sh.y;var f="t";for(var g=0;g<zoom;g++){c/=2;if(e<c){if(d<c){f+="q"}
else{f+="r";d-=c}
}
else{if(d<c){f+="t";e-=c}
else{f+="s";d-=c;e-=c}
}
}
return{'tileName':f,'x':Math.floor(e/c*256),'y':Math.floor(d/c*256)}
;}
MLList.prototype.setFeatureClickEnabled=function(th){if(th){if(this.featureEventHandle)return;this.featureEventHandle=google.maps.event.addListener(this.gmap,'click',MapTube.bindAsEventListener(function(uh){var vh=this.getTileName(uh.latLng,this.gmap.getZoom());this.tileX=vh.x;this.tileY=vh.y;this.tileName=vh.tileName;this.latLng=uh.latLng;var nb={'tileX':this.tileY,'tileY':this.tileX,'tileName':this.tileName,'latLng':uh.latLng
}
;nb.layers=new Array();for(var i=0;i<this.xlayers.length;i++)nb.layers.push(this.xlayers[i].userData);if(this.onfeaturechange)this.onfeaturechange(nb);}
,this
));}
else{if(this.featureEventHandle==null)return;google.maps.event.removeListener(this.featureEventHandle);this.featureEventHandle=null;}
}
MLList.prototype.getAllLayersBounds=function(){var wh;for(var i=0;i<this.xlayers.length;i++){var xh=this.xlayers[i].getBounds();if(xh==null)continue;if(wh==null){wh=new google.maps.LatLngBounds(xh.getSouthWest(),xh.getNorthEast());}
else{wh.extend(xh.getSouthWest());wh.extend(xh.getNorthEast());}
}
return wh;}
;MLList.prototype.getAllLayersCentre=function(){var wh=this.getAllLayersBounds();if(wh!=null)return wh.getCenter();return new google.maps.LatLng(51.52650545529106,-0.13102327732138574);}
;MLList.prototype.getInitialZoom=function(){var wh=this.getAllLayersBounds();var z=6;if(wh!=null){var yh=Math.abs(wh.getNorthEast().lat()-wh.getSouthWest().lat());var zh=Math.abs(wh.getNorthEast().lng()-wh.getSouthWest().lng());var length=Math.sqrt(yh*zh);z=(Math.log(360)-Math.log(length))/Math.log(2);}
return Math.floor(z);}
;MLList.prototype.getNumClickableLayers=function(){var $h=0;for(var i=0;i<this.xlayers.length;i++){if(this.xlayers[i].isFeatureClickable)++$h;}
return $h;}
MLList.prototype.add=function(cg){this.xlayers.push(new MLData(cg));}
;MLList.prototype.addWithData=function(cg,rg,sg,tg,dg,ug,vg,wg,xg){var nb=new MLTileData(cg,rg,sg,tg,dg,ug,vg,wg,xg);this.xlayers.push(nb);}
;MLList.prototype.addKML=function(rg,jh,xg){var nb=new MLKMLData(rg,jh,xg);this.xlayers.push(nb);}
MLList.prototype.addMapDescriptor=function(rg,sg,_h,mh,nh,ug,vg,wg,xg){var nb=new MLMapDescriptorData(rg,sg,_h,mh,nh,ug,vg,wg,xg);this.xlayers.push(nb);}
MLList.prototype.remove=function(oh){}
MLList.prototype.rebuildGMap=function(){this.gmap.overlayMapTypes.clear();for(var i=this.xlayers.length-1;i>=0;i--){if(this.xlayers[i]instanceof MLKMLData)continue;if((this.xlayers[i].isEnabled)&&(this.xlayers[i].isLoaded)){this.gmap.overlayMapTypes.push(this.xlayers[i].getOverlay());}
}
for(var i=this.xlayers.length-1;i>=0;i--){if(this.xlayers[i]instanceof MLKMLData){this.xlayers[i].overlay.setMap(this.gmap);}
}
}
;MLList.prototype.moveUp=function(ai){if(ai==0){alert("You can't move the top layer up any more.");return;}
if((ai<0)||(ai>=this.xlayers.length))return;var bi=this.xlayers[ai-1];this.xlayers[ai-1]=this.xlayers[ai];this.xlayers[ai]=bi;this.rebuildGMap();}
;MLList.prototype.moveDown=function(ci){if(ci==this.xlayers.length-1){alert("You can't move the bottom layer down any more.");return;}
if((ci<0)||(ci>=this.xlayers.length))return;var di=this.xlayers[ci+1];this.xlayers[ci+1]=this.xlayers[ci];this.xlayers[ci]=di;this.rebuildGMap();}
;MLList.prototype.moveLayer=function(ei,fi){if((ei<0)||(ei>this.xlayers.length))return;if((fi<0)||(fi>this.xlayers.length))return;if(ei==fi)return;var gi=this.xlayers.splice(ei,1);this.xlayers.splice(fi,0,gi[0]);this.rebuildGMap();}
;MLList.prototype.getColourScaleHTML=function(oh){if((oh>=0)&&(oh<this.xlayers.length))return this.xlayers[oh].getColourScaleHTML();return"";}
;MLList.prototype.containsKMLLayer=function(){for(var i=0;i<this.xlayers.length;i++)if(this.xlayers[i]instanceof MLKMLData)return true;return false;}
MLList.prototype.scheduleMapDefaultView=function(){for(var i=0;i<this.xlayers.length;i++){if(this.xlayers[i]instanceof MLKMLData){var hi=this.xlayers[i].overlay;var ii=this;google.maps.event.addListener(hi,"load",function(){var xh=ii.getAllLayersBounds();if(xh!=null){var z=ii.gmap.getBoundsZoomLevel(xh);ii.gmap.setOptions({center:xh.getCenter(),zoom:z}
);}
}
);}
}
}
;
