/*
   openlayers-tools.js -- MetaCarta JavaScript OpenLayers Tools Package

  Copyright (C) MetaCarta, Incorporated. An unpublished work created
  2007 - 2008.  All rights reserved.  This software contains the confidential
  and proprietary information of MetaCarta, Incorporated
  ("MetaCarta").  Copying, distribution or reverse engineering without
  MetaCarta's express written permission is prohibited.

  IF YOU ARE READING THIS, YOU ARE VIOLATING YOUR LICENSE AGREEMENT.
*/

/* $Id: openlayers-tools.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: openlayers-tools.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: openlayers-tools.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: openlayers-tools.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: openlayers-tools.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: openlayers-tools.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: openlayers-tools.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
if(typeof MetaCarta.OLTools=="undefined"){MetaCarta.OLTools={};}
if(MetaCarta.OLTools&&typeof MetaCarta.OLTools.DensityLayer=="undefined"){MetaCarta.OLTools.DensityLayer=OpenLayers.Class(OpenLayers.Layer.WMS,{DEFAULT_PARAMS:{version:"2.0.0"},singleTile:true,ratio:1,isBaseLayer:false,queryObject:null,urlBase:null,reference:null,onlyRedrawOnQueryObjectResponse:false,initialize:function(name,url,params,options){this.urlBase=url;this.queryObject=options.queryObject;if(!this.queryObject){this.queryObject=new MetaCarta.Query.Search(options);this.queryObject.owner=this;}
this.queryObject.registerListener("queryResponse",this.onQuerySuccess,this);this.queryObject.registerListener("queryError",this.onQueryError,this);OpenLayers.Layer.WMS.prototype.initialize.apply(this,arguments);},destroy:function(){if(this.queryObject.owner==this){this.queryObject.destroy();}
this.queryObject=null;this.urlBase=null;this.reference=null;this.onlyRedrawOnQueryObjectResponse=null;OpenLayers.Layer.WMS.prototype.destroy.apply(this,arguments);},clone:function(obj){if(obj==null){obj=new MetaCarta.OLTools.DensityLayer(this.name,this.options);}
obj=OpenLayers.Layer.WMS.prototype.clone.apply(this,[obj]);return obj;},onQueryError:function(evt){this.setVisibility(false);},onQuerySuccess:function(evt){this.reference=null;if(evt.response&&evt.response.density&&evt.response.density.Reference){this.reference=evt.response.density.Reference;this.url=this.urlBase+'/'+this.reference;this.redraw();}
if(this.onlyRedrawOnQueryObjectResponse){this.reference=null;}},moveTo:function(bounds,zoomChanged,dragging){if(!this.reference){this.display(false);}else{OpenLayers.Layer.WMS.prototype.moveTo.apply(this,arguments);}},CLASS_NAME:"MetaCarta.OLTools.DensityLayer"});}
if(typeof MetaCarta.OLTools=="undefined"){MetaCarta.OLTools={};}
if(MetaCarta.OLTools&&typeof MetaCarta.OLTools.SearchPopup=="undefined"){MetaCarta.OLTools.SearchPopup=OpenLayers.Class(OpenLayers.Popup.AnchoredBubble,{feature:null,servers:null,allServersEmpty:false,loadedRefs:null,refsBuffer:null,refIndex:null,initialize:function(id,lonlat,size,contentHTML,anchor,closeBox){OpenLayers.Popup.AnchoredBubble.prototype.initialize.apply(this,arguments);this.div.style.fontFamily="Verdana";this.loadedRefs=new Array();this.refsBuffer=new Array();},destroy:function(){this.servers=null;this.loadedRefs=null;this.refsBuffer=null;OpenLayers.Popup.AnchoredBubble.prototype.destroy.apply(this,arguments);},draw:function(px){OpenLayers.Popup.AnchoredBubble.prototype.draw.apply(this,arguments);this.loadContents();this.configureServersArray();var overrideCSS=this.feature.layer.overrideCSS;var color=(overrideCSS&&overrideCSS['popupBackground'])?overrideCSS['popupBackground']:"FFFBDF";this.setBackgroundColor(color);this.setOpacity(0.9);this.setIndex(0);return this.div;},setIndex:function(index){if(index!=null){this.refIndex=(index<0)?0:index;}
var totalDocs=this.getTotalDocs();var loadedDocs=this.loadedRefs.length;if((totalDocs>0)&&(totalDocs<1000)&&(totalDocs==loadedDocs)){this.allServersEmpty=true;}
var beyondLoadedRefs=(this.refIndex>(loadedDocs-1));if(beyondLoadedRefs&&this.allServersEmpty){this.refIndex=this.loadedRefs.length-1;this.navText.innerHTML="Displaying Last of "+
(this.refIndex+1);var ref=this.loadedRefs[this.refIndex];this.resultDiv.innerHTML=this.getRefSummaryHTML(ref);}else{var roundDocs=MetaCarta.Number.format(totalDocs);if(beyondLoadedRefs){var navHTML="Loading #"+(this.refIndex+1);if(totalDocs>0){navHTML+=" of "+roundDocs;}
this.navText.innerHTML=navHTML;this.resultDiv.innerHTML="Please wait... loading more data.";this.queryServers();}else{this.navText.innerHTML="Displaying #"+
(this.refIndex+1)+" of "+roundDocs;var ref=this.loadedRefs[this.refIndex];this.resultDiv.innerHTML=this.getRefSummaryHTML(ref);}}},queryServers:function(){var mostRelevant=0;for(var i=0;i<this.servers.length;i++){var server=this.servers[i];if((!server.empty)&&(server.lastRelevance>mostRelevant)){mostRelevant=server.lastRelevance;}}
for(var i=0;i<this.servers.length;i++){var server=this.servers[i];if((server.lastRelevance==mostRelevant)||(server.lastRelevance==null)){server.loaded=false;var options={'newParams':server.params,'requestData':{'server':server}};server.queryObject.query=this.feature.layer.queryObject.query;server.queryObject.run(options);server.params.startRef+=MetaCarta.OLTools.SearchPopup.MAX_FEATURES;}}},onLoadSuccess:function(evt){var server=evt.requestData.server;var response=evt.response;server.loaded=true;if((response==null)||(response.refs==null)||(response.refs.length==0)){server.empty=true;this.allServersEmpty=true;for(var i=0;i<this.servers.length;i++){if(!this.servers[i].empty){this.allServersEmpty=false;break;}}}else{server.totalDocCount=response.approxNumRefsQuery;for(var i=0;i<response.refs.length;i++){var ref=response.refs[i];this.addRef(ref);server.lastRelevance=ref.relevance;}}
var allServersLoaded=true;for(var i=0;i<this.servers.length;i++){if(this.servers[i].loaded==false){allServersLoaded=false;break;}}
if(allServersLoaded){this.transferRefsFromBuffer();}},addRef:function(ref){for(var i=0;i<this.refsBuffer.length;i++){if(ref.relevance>this.refsBuffer[i].relevance){this.refsBuffer.splice(i,0,ref);break;}}
if(i==this.refsBuffer.length){this.refsBuffer.push(ref);}},transferRefsFromBuffer:function(){var count=Math.min(this.refsBuffer.length,MetaCarta.OLTools.SearchPopup.MAX_FEATURES);for(var i=0;i<count;i++){var ref=this.refsBuffer.shift();this.loadedRefs.push(ref);}
this.setIndex();},configureServersArray:function(){this.servers=new Array();var lonlat=this.feature.lonlat;var degrees=this.feature.layer.map.getResolution()*1;var bounds=new OpenLayers.Bounds(lonlat.lon-degrees,lonlat.lat-degrees,lonlat.lon+degrees,lonlat.lat+degrees);var server={'id':OpenLayers.Util.createUniqueID("Server_"),'params':{'BBOX':bounds.toArray(),'startRef':0,'maxRefs':MetaCarta.OLTools.SearchPopup.MAX_FEATURES,'grid':null},'empty':false,'totalDocCount':0,'lastRelevance':null,'loaded':false};server.queryObject=this.feature.layer.queryObject.clone();server.queryObject.registerListener("queryResponse",this.onLoadSuccess,this);this.servers.push(server);},getServer:function(id){var server=null;for(var i=0;i<this.servers.length;i++){if(this.servers[i].id==id){server=this.servers[i];break;}}
return server;},getTotalDocs:function(){var totalDocs=0;for(var i=0;i<this.servers.length;i++){totalDocs+=this.servers[i].totalDocCount;}
return totalDocs;},loadContents:function(){this.navDiv=OpenLayers.Util.createDiv(this.id+"_navDiv",null,new OpenLayers.Size(250,20),null,"relative");this.navText=OpenLayers.Util.createDiv(this.id+"_navText",null,new OpenLayers.Size(200,20),null,"absolute");var overrideCSS=this.feature.layer.overrideCSS;var color=(overrideCSS&&overrideCSS['navTextColor'])?overrideCSS['navTextColor']:"#666";this.navText.style.color=color;this.navText.style.fontSize=".8em";this.navText.style.fontFamily="Verdana";this.navText.style.left="20px";var navIconSize=new OpenLayers.Size(16,17);var id=this.id+"_backward";var img=MetaCarta.OLTools.SearchLayer._getImagesLocation()
+"arrow-l.png";this.backwardImg=OpenLayers.Util.createAlphaImageDiv(id,null,navIconSize,img);var id=this.id+"_forward";var img=MetaCarta.OLTools.SearchLayer._getImagesLocation()
+"arrow-r.png";this.forwardImg=OpenLayers.Util.createAlphaImageDiv(id,null,navIconSize,img);this.forwardImg.style.right="35px";this.forwardImg.style.top="0px";var img=MetaCarta.OLTools.SearchLayer._getImagesLocation()
+"close.gif";this.closeImg=OpenLayers.Util.createAlphaImageDiv(this.id+"_close",null,navIconSize,img);this.closeImg.style.right="10px";this.closeImg.style.top="0px";this.navEventsBackward=new MetaCarta.Events(this,this.backwardImg);this.navEventsBackward.register("mousedown",this.navBackward,this);var navBackMouseOver=function(evt){var img=MetaCarta.OLTools.SearchLayer._getImagesLocation()
+"arrow-l-over.gif";OpenLayers.Util.modifyAlphaImageDiv(this,null,null,null,img);};this.navEventsBackward.register("mouseover",navBackMouseOver,this.backwardImg);var navBackMouseOut=function(evt){var img=MetaCarta.OLTools.SearchLayer._getImagesLocation()+"arrow-l.gif";OpenLayers.Util.modifyAlphaImageDiv(this,null,null,null,img);};this.navEventsBackward.register("mouseout",navBackMouseOut,this.backwardImg);this.navEventsBackward.register("dblclick",OpenLayers.Event.stop);this.navEventsForward=new MetaCarta.Events(this,this.forwardImg);this.navEventsForward.register("mousedown",this.navForward,this);var navForwardMouseOver=function(evt){var img=MetaCarta.OLTools.SearchLayer._getImagesLocation()+"arrow-r-over.gif";OpenLayers.Util.modifyAlphaImageDiv(this,null,null,null,img);};this.navEventsForward.register("mouseover",navForwardMouseOver,this.forwardImg);var navForwardMouseOut=function(evt){var img=MetaCarta.OLTools.SearchLayer._getImagesLocation()+"arrow-r.gif";OpenLayers.Util.modifyAlphaImageDiv(this,null,null,null,img);};this.navEventsForward.register("mouseout",navForwardMouseOut,this.forwardImg);this.navEventsForward.register("dblclick",OpenLayers.Event.stop);this.navEventsClose=new MetaCarta.Events(this,this.closeImg);this.navEventsClose.register("mousedown",this.hide,this);this.navEventsClose.register("dblclick",OpenLayers.Event.stop);this.navDiv.appendChild(this.backwardImg);this.navDiv.appendChild(this.navText);this.navDiv.appendChild(this.forwardImg);this.navDiv.appendChild(this.closeImg);this.contentDiv.appendChild(this.navDiv);this.resultDiv=document.createElement("div");this.resultDiv.id=this.id+"_resultDiv";this.contentDiv.appendChild(this.resultDiv);},setContentHTML:function(contentHTML){},navBackward:function(evt){this.setIndex(this.refIndex-1);OpenLayers.Event.stop(evt);},navForward:function(evt){this.setIndex(this.refIndex+1);OpenLayers.Event.stop(evt);},getRefSummaryHTML:function(ref){var dStyle="font-size: 1em;";var aStyle="font-weight: bold; font-size: 1em;";var contentHTML="";contentHTML+="<div style='margin: 0.25em' class='mcPopup'>";contentHTML+="<div style='height: 1.3em; overflow: hidden'>"
contentHTML+="<span style='font-weight: bold'>"
contentHTML+="<a href='"+ref.doc.URL+"' target='_blank' "+"style='"+aStyle+"'>";contentHTML+=ref.doc.title;contentHTML+="</a>"
contentHTML+="</span>"
contentHTML+="</div>"
contentHTML+="<span class='mcPopupLocation'>"
contentHTML+="<b>Location:</b>";contentHTML+=ref.geoRef;contentHTML+="</span>"
contentHTML+="<br />";contentHTML+="<span style='align:center' class='mcPopupContent'>"
contentHTML+="<b>Extract:</b>";contentHTML+="</span>"
contentHTML+="<br>";contentHTML+="<span class='mcPopupContent' style='align:center'>"
contentHTML+=ref.extract;contentHTML+="</span>"
contentHTML+="</div>"
return contentHTML;},CLASS_NAME:"MetaCarta.OLTools.SearchPopup"});MetaCarta.OLTools.SearchPopup.MAX_FEATURES=20;}
if(typeof MetaCarta.OLTools=="undefined"){MetaCarta.OLTools={};}
if(MetaCarta.OLTools&&typeof MetaCarta.OLTools.LocationFinderFeature=="undefined"){MetaCarta.OLTools.LocationFinderFeature=OpenLayers.Class(OpenLayers.Feature,{loc:null,highlightRatio:0.7,popupClass:null,popupCloseBox:false,initialize:function(layer,loc){this.loc=loc;var lonlat=new OpenLayers.LonLat(loc.centroid.Longitude,loc.centroid.Latitude);var data={};var newArguments=new Array(layer,lonlat,data);OpenLayers.Feature.prototype.initialize.apply(this,newArguments);data.icon=this.createMarkerIcon(loc);data.popupSize=new OpenLayers.Size(250,200);this.createMarker();this.layer.addMarker(this.marker);},destroy:function(){this.popupClass=null;if((this.marker!=null)&&(this.layer.markers)){this.layer.removeMarker(this.marker);}
OpenLayers.Feature.prototype.destroy.apply(this,arguments);},createMarkerIcon:function(loc){var icon=null;if(this.layer.markerIcon!=null){icon=this.layer.markerIcon.clone();}else{if(loc.style){var defaultSymbol=loc.responseObject.styles[loc.style];var iconSize=new OpenLayers.Size(defaultSymbol.width*this.highlightRatio,defaultSymbol.height*this.highlightRatio);var offsetFunc=function(size){return new OpenLayers.Pixel(-size.w,-size.h);};icon=new OpenLayers.Icon(defaultSymbol.URL,iconSize,null,offsetFunc);}else{icon=MetaCarta.OLTools.LocationFinderFeature.defaultIcon();}}
return icon;},setHighlight:function(highlit){var ratio=highlit?(1/this.highlightRatio):this.highlightRatio;var w=parseInt((this.marker.icon.size.w*ratio)+0.5);var h=parseInt((this.marker.icon.size.h*ratio)+0.5);this.marker.icon.setSize(new OpenLayers.Size(w,h));},createMarker:function(){OpenLayers.Feature.prototype.createMarker.apply(this,arguments);this.marker.events.register("mousedown",this,this.onMarkerMouseDown);this.marker.events.register("mouseover",this,this.onMarkerMouseOver);this.marker.events.register("mouseout",this,this.onMarkerMouseOut);},onMarkerMouseOver:function(evt){},onMarkerMouseOut:function(evt){},onMarkerMouseDown:function(evt){if(this.popupClass){if(this.popup==null){this.layer.map.addPopup(this.createPopup(this.popupCloseBox),true);}else{var mapPopup=this.layer.map.popups[0];if(this.popup==mapPopup){this.popup.toggle();}else{this.layer.map.addPopup(this.popup,true);this.popup.show();}}
OpenLayers.Event.stop(evt);}},CLASS_NAME:"MetaCarta.OLTools.LocationFinderFeature"});MetaCarta.OLTools.LocationFinderFeature.defaultIcon=function(){var url=MetaCarta.OLTools.LocationFinderLayer._getImagesLocation()
+"icon.png";var size=new OpenLayers.Size(25,25);var calculateOffset=function(size){return new OpenLayers.Pixel(-(size.w/2),-size.h);};return new OpenLayers.Icon(url,size,null,calculateOffset);};}
if(typeof MetaCarta.OLTools=="undefined"){MetaCarta.OLTools={};}
if(MetaCarta.OLTools&&typeof MetaCarta.OLTools.SearchFeature=="undefined"){MetaCarta.OLTools.SearchFeature=OpenLayers.Class(OpenLayers.Feature,{loc:null,popupClass:null,popupCloseBox:false,defaultStyle:null,highlightRatio:0.7,initialize:function(layer,loc){this.loc=loc;var lon=(loc.centroid.X!=null)?loc.centroid.X:loc.centroid.Longitude;var lat=(loc.centroid.Y!=null)?loc.centroid.Y:loc.centroid.Latitude;var lonlat=new OpenLayers.LonLat(lon,lat);var data={};var newArguments=new Array(layer,lonlat,data);OpenLayers.Feature.prototype.initialize.apply(this,newArguments);data.icon=this.createMarkerIcon(loc);data.popupSize=new OpenLayers.Size(250,200);this.createMarker();this.layer.addMarker(this.marker);},destroy:function(){this.popupClass=null;if((this.marker!=null)&&(this.layer.markers)){this.layer.removeMarker(this.marker);}
OpenLayers.Feature.prototype.destroy.apply(this,arguments);},createMarkerIcon:function(loc){var icon=null;if(this.layer.markerIcon!=null){icon=this.layer.markerIcon.clone();}else{if(loc.style){if(this.defaultStyle){var defaultSymbol=loc.responseObject.symbols[this.defaultStyle];}else{var defaultSymbol=loc.responseObject.symbols[loc.style];}
var iconSize=new OpenLayers.Size(defaultSymbol.width*this.highlightRatio,defaultSymbol.height*this.highlightRatio);var offsetFunc=function(size){return new OpenLayers.Pixel(-size.w/2,-size.h/2);};icon=new OpenLayers.Icon(defaultSymbol.URL,iconSize,null,offsetFunc);}else{icon=MetaCarta.OLTools.SearchFeature.defaultIcon();}}
return icon;},setHighlight:function(highlit){var ratio=highlit?(1/this.highlightRatio):this.highlightRatio;var w=parseInt((this.marker.icon.size.w*ratio)+0.5);var h=parseInt((this.marker.icon.size.h*ratio)+0.5);this.marker.icon.setSize(new OpenLayers.Size(w,h));},createMarker:function(){OpenLayers.Feature.prototype.createMarker.apply(this,arguments);this.marker.events.register("mousedown",this,this.onMarkerMouseDown);this.marker.events.register("mouseover",this,this.onMarkerMouseOver);this.marker.events.register("mouseout",this,this.onMarkerMouseOut);},onMarkerMouseOver:function(evt){},onMarkerMouseOut:function(evt){},onMarkerMouseDown:function(evt){if(this.popupClass){if(this.popup==null){this.layer.map.addPopup(this.createPopup(this.popupCloseBox),true);}else{var mapPopup=this.layer.map.popups[0];if(this.popup==mapPopup){this.popup.toggle();}else{this.layer.map.addPopup(this.popup,true);this.popup.show();}}
OpenLayers.Event.stop(evt);}},CLASS_NAME:"MetaCarta.OLTools.SearchFeature"});MetaCarta.OLTools.SearchFeature.defaultIcon=function(){var url=MetaCarta.OLTools.SearchLayer._getImagesLocation()
+"icon.png";var size=new OpenLayers.Size(25,25);var calculateOffset=function(size){return new OpenLayers.Pixel(-(size.w/2),-size.h);};return new OpenLayers.Icon(url,size,null,calculateOffset);};}
if(typeof MetaCarta.OLTools=="undefined"){MetaCarta.OLTools={};}
if(MetaCarta.OLTools&&typeof MetaCarta.OLTools.SearchTile=="undefined"){MetaCarta.OLTools.SearchTile=OpenLayers.Class(OpenLayers.Tile,{features:null,initialize:function(layer,position,bounds,url,size){OpenLayers.Tile.prototype.initialize.apply(this,arguments);this.features=new Array();this.layer.queryObject.registerListener("queryResponse",this.processResults,this);this.layer.queryObject.registerListener("queryError",this.handleError,this);},destroy:function(){OpenLayers.Tile.prototype.destroy.apply(this,arguments);this.destroyAllFeatures();this.features=null;},draw:function(){if(OpenLayers.Tile.prototype.draw.apply(this,arguments)){if(this.isLoading){this.events.triggerEvent("reload");}else{this.isLoading=true;this.events.triggerEvent("loadstart");}
this.layer.queryObject.BBOX=this.bounds.toArray();this.layer.queryObject.run();}},handleError:function(evt){if(this.features&&this.features.length){this.destroyAllFeatures();}
this.isLoading=false;this.events.triggerEvent("loadend");},processResults:function(evt){var response=evt.response;if(this.features&&this.features.length){this.destroyAllFeatures();}
for(var i=0;i<response.locs.length;i++){var loc=response.locs[i];if(typeof loc!="function"){var feature=new this.layer.featureClass(this.layer,loc);this.features.push(feature);}}
this.isLoading=false;this.events.triggerEvent("loadend");},destroyAllFeatures:function(){while(this.features.length>0){var feature=this.features.shift();feature.destroy();}},CLASS_NAME:"MetaCarta.OLTools.SearchTile"});}
if(typeof MetaCarta.OLTools=="undefined"){MetaCarta.OLTools={};}
if(MetaCarta.OLTools&&typeof MetaCarta.OLTools.LocationFinderLayer=="undefined"){MetaCarta.OLTools.LocationFinderLayer=OpenLayers.Class(OpenLayers.Layer.Markers,{queryObject:null,features:null,featureClass:MetaCarta.OLTools.LocationFinderFeature,initialize:function(name,options){this.setConfigOptions(options);OpenLayers.Layer.Markers.prototype.initialize.apply(this,arguments);this.features=new Array();this.queryObject=options.queryObject;if(!this.queryObject){this.queryObject=new MetaCarta.Query.LocationFinder(options);this.queryObject.owner=this;}
this.queryObject.registerListener("queryError",this.onQueryError,this);this.queryObject.registerListener("queryResponse",this.onQueryResponse,this);this.queryObject.registerListener("queryRun",this.onQueryRun,this);},destroy:function(){OpenLayers.Layer.Markers.prototype.destroy.apply(this,arguments);if(this.queryObject.owner==this){this.queryObject.destroy();}
this.destroyAllFeatures();this.features=null;},clone:function(obj){if(obj==null){obj=new MetaCarta.OLTools.LocationFinderLayer(this.name,this.options);}
obj=OpenLayers.Layer.Markers.prototype.clone.apply(this,[obj]);return obj;},onQueryRun:function(evt){this.events.triggerEvent("loadstart");},onQueryError:function(evt){if(this.features&&this.features.length){this.destroyAllFeatures();}
this.isLoading=false;this.events.triggerEvent("loadend");},onQueryResponse:function(evt){var response=evt.response;if(this.features&&this.features.length){this.destroyAllFeatures();}
for(var i=0;i<response.locs.length;i++){var loc=response.locs[i];if(typeof loc!="function"){var feature=new this.featureClass(this,loc);this.features.push(feature);}}
this.isLoading=false;this.events.triggerEvent("loadend");},destroyAllFeatures:function(){while(this.features.length>0){var feature=this.features.shift();feature.destroy();}},getFeatureFromLocation:function(loc){var lfFeature=null;for(var i=0;i<this.features.length;i++){var feature=this.features[i];if(feature.loc==loc){lfFeature=feature;break;}}
return lfFeature;},setConfigOptions:function(options){if(options.marker){if(options.marker.onMouseOver){var onMouseOver=options.marker.onMouseOver;this.featureClass.prototype.onMarkerMouseOver=function(evt){onMouseOver(evt,this.loc,this.marker,this.layer);};}
if(options.marker.onMouseOut){var onMouseOut=options.marker.onMouseOut;this.featureClass.prototype.onMarkerMouseOut=function(evt){onMouseOut(evt,this.loc,this.marker,this.layer);};}
if(options.marker.onMouseDown){var old_onMarkerMouseDown=this.featureClass.prototype.onMarkerMouseOver;var onMouseDown=options.marker.onMouseDown;this.featureClass.prototype.onMarkerMouseDown=function(evt){onMouseDown(evt,this.loc,this.marker,this.layer);old_onMarkerMouseDown.apply(this,[evt]);};}}
if(options.popup){if(options.popup.closeBox){this.featureClass.prototype.popupCloseBox=options.popup.closeBox;}
var popupClass=options.popup["class"];if(!popupClass){popupClass=OpenLayers.Class(OpenLayers.Popup.FramedCloud,{});}
this.featureClass.prototype.popupClass=popupClass;popupClass.prototype.panMapIfOutOfView=true;var popupSize=options.popup.size;var popupOpacity=options.popup.opacity;var popupBorder=options.popup.border;var popupBackgroundColor=options.popup.backgroundColor;var popupPanMapIfOutOfView=options.popup.panMapIfOutOfView;var popupContentHTML=options.popup.contentHTML;var old_draw=popupClass.prototype.draw;popupClass.prototype.draw=function(px){this.panMapIfOutOfView=(popupPanMapIfOutOfView)?popupPanMapIfOutOfView:true;if(popupBackgroundColor){this.backgroundColor=popupBackgroundColor;}
if(popupOpacity){this.opacity=popupOpacity;}
if(popupBorder){this.border=popupBorder;}
this.autoSize=(popupSize=="auto");if(popupSize&&(typeof popupSize[0]=="number")&&(typeof popupSize[1]=="number")){this.size=new OpenLayers.Size(popupSize[0],popupSize[1])}
if(popupContentHTML){this.contentHTML=popupContentHTML;}
return old_draw.apply(this,[px]);};var popupRenderer=options.popup.renderer;if(popupRenderer){popupClass.prototype.setContentHTML=function(contentHTML){popupRenderer(this.contentDiv,this.feature.loc);MetaCarta.OLTools.LocationFinderLayer.AutoSize.apply(this,[]);};}}},CLASS_NAME:"MetaCarta.OLTools.LocationFinderLayer"});MetaCarta.OLTools.LocationFinderLayer._getImagesLocation=function(){return"";};}
MetaCarta.OLTools.LocationFinderLayer.AutoSize=function(){if(this.autoSize){var contentHTML=this.contentDiv.innerHTML;var realSize=OpenLayers.Util.getRenderedDimensions(contentHTML);var safeSize=this.getSafeContentSize(realSize);var newSize=null;if(safeSize.equals(realSize)){newSize=realSize;}else{var fixedSize=new OpenLayers.Size();fixedSize.w=(safeSize.w<realSize.w)?safeSize.w:null;fixedSize.h=(safeSize.h<realSize.h)?safeSize.h:null;if(fixedSize.w&&fixedSize.h){newSize=safeSize;}else{var clippedSize=OpenLayers.Util.getRenderedDimensions(contentHTML,fixedSize);var currentOverflow=OpenLayers.Element.getStyle(this.contentDiv,"overflow");if((currentOverflow!="hidden")&&(clippedSize.equals(safeSize))){var scrollBar=OpenLayers.Util.getScrollbarWidth();if(fixedSize.w){clippedSize.h+=scrollBar;}else{clippedSize.w+=scrollBar;}}
newSize=this.getSafeContentSize(clippedSize);}}
this.setSize(newSize);}};if(typeof MetaCarta.OLTools=="undefined"){MetaCarta.OLTools={};}
if(MetaCarta.OLTools&&typeof MetaCarta.OLTools.SearchLayer=="undefined"){MetaCarta.OLTools.SearchLayer=OpenLayers.Class(OpenLayers.Layer.Grid,OpenLayers.Layer.Markers,{singleTile:true,ratio:1,queryObject:null,featureClass:MetaCarta.OLTools.SearchFeature,initialize:function(name,options){this.setConfigOptions(options);this.queryObject=options.queryObject;if(!this.queryObject){this.queryObject=new MetaCarta.Query.Search(options);this.queryObject.owner=this;}
OpenLayers.Layer.Markers.prototype.initialize.apply(this,arguments);var gridArgs=[name,null,null,options];OpenLayers.Layer.Grid.prototype.initialize.apply(this,gridArgs);},destroy:function(){if(this.queryObject.owner==this){this.queryObject.destroy();}
OpenLayers.Layer.Grid.prototype.destroy.apply(this,arguments);OpenLayers.Layer.Markers.prototype.destroy.apply(this,arguments);},clone:function(obj){if(obj==null){obj=new MetaCarta.OLTools.SearchLayer(this.name,this.options);}
obj=OpenLayers.Layer.Grid.prototype.clone.apply(this,[obj]);obj=OpenLayers.Layer.Markers.prototype.clone.apply(this,[obj]);return obj;},moveTo:function(){OpenLayers.Layer.Markers.prototype.moveTo.apply(this,arguments);OpenLayers.Layer.Grid.prototype.moveTo.apply(this,arguments);},addTile:function(bounds,position){return new MetaCarta.OLTools.SearchTile(this,position,bounds,null,this.tileSize);},getFeatureFromLocation:function(loc){var searchFeature=null;var searchTile=this.grid[0][0]
for(var i=0;i<searchTile.features.length;i++){var feature=searchTile.features[i];if(feature.loc==loc){searchFeature=feature;break;}}
return searchFeature;},setConfigOptions:function(options){if(options.marker){if(options.marker.onMouseOver){var onMouseOver=options.marker.onMouseOver;this.featureClass.prototype.onMarkerMouseOver=function(evt){onMouseOver(evt,this.loc,this.marker,this.layer);};}
if(options.marker.onMouseOut){var onMouseOut=options.marker.onMouseOut;this.featureClass.prototype.onMarkerMouseOut=function(evt){onMouseOut(evt,this.loc,this.marker,this.layer);};}
if(options.marker.onMouseDown){var old_onMarkerMouseDown=this.featureClass.prototype.onMarkerMouseOver;var onMouseDown=options.marker.onMouseDown;this.featureClass.prototype.onMarkerMouseDown=function(evt){onMouseDown(evt,this.loc,this.marker,this.layer);old_onMarkerMouseDown.apply(this,[evt]);};}}
if(options.popup){if(options.popup.closeBox){this.featureClass.prototype.popupCloseBox=options.popup.closeBox;}
var popupClass=options.popup["class"];if(!popupClass){popupClass=OpenLayers.Class(OpenLayers.Popup.FramedCloud,{});}
this.featureClass.prototype.popupClass=popupClass;popupClass.prototype.panMapIfOutOfView=false;var popupSize=options.popup.size;var popupOpacity=options.popup.opacity;var popupBorder=options.popup.border;var popupBackgroundColor=options.popup.backgroundColor;var popupContentHTML=options.popup.contentHTML;var old_draw=popupClass.prototype.draw;popupClass.prototype.draw=function(px){if(popupBackgroundColor){this.backgroundColor=popupBackgroundColor;}
if(popupOpacity){this.opacity=popupOpacity;}
if(popupBorder){this.border=popupBorder;}
this.autoSize=(popupSize=="auto");if(popupSize&&(typeof popupSize[0]=="number")&&(typeof popupSize[1]=="number")){this.size=new OpenLayers.Size(popupSize[0],popupSize[1])}
if(popupContentHTML){this.contentHTML=popupContentHTML;}
return old_draw.apply(this,[px]);};var popupRenderer=options.popup.renderer;if(popupRenderer){popupClass.prototype.setContentHTML=function(contentHTML){popupRenderer(this.contentDiv,this.feature.loc);MetaCarta.OLTools.SearchLayer.AutoSize.apply(this,[]);};}}},CLASS_NAME:"MetaCarta.OLTools.SearchLayer"});MetaCarta.OLTools.SearchLayer._getImagesLocation=function(){return"";};}
MetaCarta.OLTools.SearchLayer.AutoSize=function(){if(this.autoSize){var contentHTML=this.contentDiv.innerHTML;var realSize=OpenLayers.Util.getRenderedDimensions(contentHTML);var safeSize=this.getSafeContentSize(realSize);var newSize=null;if(safeSize.equals(realSize)){newSize=realSize;}else{var fixedSize=new OpenLayers.Size();fixedSize.w=(safeSize.w<realSize.w)?safeSize.w:null;fixedSize.h=(safeSize.h<realSize.h)?safeSize.h:null;if(fixedSize.w&&fixedSize.h){newSize=safeSize;}else{var clippedSize=OpenLayers.Util.getRenderedDimensions(contentHTML,fixedSize);var currentOverflow=OpenLayers.Element.getStyle(this.contentDiv,"overflow");if((currentOverflow!="hidden")&&(clippedSize.equals(safeSize))){var scrollBar=OpenLayers.Util.getScrollbarWidth();if(fixedSize.w){clippedSize.h+=scrollBar;}else{clippedSize.w+=scrollBar;}}
newSize=this.getSafeContentSize(clippedSize);}}
this.setSize(newSize);}};