// Set up our own namespace, so we don't pollute the windows
// namespace with our global variables

var PSRKMAP = {};
PSRKMAP.arr_mapobjects = [];
PSRKMAP.drag_ready = false;
PSRKMAP.dragging = false;
PSRKMAP.active_map = 0;
PSRKMAP.sliding = false;
PSRKMAP.right_zoom_out = false;
PSRKMAP.right_zoom_in = false;
PSRKMAP.dblclicking = false;
PSRKMAP.dblclick_ready = true;
PSRKMAP.mouseisdown = false;
PSRKMAP.drawing_polygon = false;



//  setup section

// psharkmap member functions

psharkmap.prototype.loadCanvasSpecs = function () {

	this.canvas.margin = this.canvas.obj.style.margin ? parseInt(this.canvas.obj.style.margin,10) : 0;
	this.canvas.padding = 0;
	this.canvas.border_width_user_set = this.canvas.obj.style.borderWidth ? 1:0;
	this.canvas.borderWidth = this.canvas.obj.style.borderWidth ? parseInt(this.canvas.obj.style.borderWidth,10) : 1;
	this.canvas.borderStyle = this.canvas.obj.style.borderStyle ? this.canvas.obj.style.borderStyle.split(' ')[0] : "solid";
	this.canvas.borderColor = "#a5b8c8";
	if (this.canvas.obj.style.borderColor){
			this.canvas.borderColor = this.canvas.obj.style.borderColor.replace(/, /g,/,/).split(' ')[0];
	}

	this.canvas.borderTopWidth = this.canvas.borderRightWidth = this.canvas.borderBottomWidth = this.canvas.borderLeftWidth = this.canvas.borderWidth;

	this.canvas.minWidth = 200;
	this.canvas.minHeight = 180;
	this.canvas.defaultWidth = 600;
	this.canvas.defaultHeight = 480;
	this.canvas.fullWidth = 0;
	this.canvas.fullHeight = 0;

	this.canvas.width = this.canvas.obj.style.width ? parseInt(this.canvas.obj.style.width,10) : this.canvas.defaultWidth;
	this.canvas.height = this.canvas.obj.style.height ? parseInt(this.canvas.obj.style.height,10) : this.canvas.defaultHeight;

	this.checkCanvasMinDim();
	
	this.canvas.hasControlPanel = 0;
	this.canvas.displayControlPanel = 1;
	this.canvas.roomforControlPanel = 1;
	this.canvas.has_keymap = 0;
	this.canvas.has_linksmenu = 0;
	this.canvas.left_offset = 0;
	this.canvas.right_offset = 0;
	
	this.tile_server = PSRKMAP.tile_server;
	
	this.map = [];
	this.map.width = 0;
	this.map.height = 0;
	this.map.minWidth = 200;
	this.map.minHeight = 180;
	
	this.control = [];
	this.control.narrow_width = 254;
	this.control.wide_width = 426;
	this.control.toggle_width = 7;
	this.control.width = this.control.narrow_width;
	this.control.height = 0;
	this.control.backgroundColor = "#fff";
	
	this.tools = [];
	this.tools.margin = 0;
	
	this.tools.zoom_tool = [];
	this.tools.zoom_tool.width=42;
	this.tools.zoom_tool.slider_height = 12;
	this.tools.zoom_tool.micro = 0;
	
	this.tools.keymap = [];
	this.tools.keymap.height=150;
	this.tools.keymap.width=150;
	this.tools.keymap.view_minWidth = 4;
	this.tools.keymap.view_minHeight = 4;
	this.tools.keymap.path = this.tile_server + "/keymap.pl";
	this.tools.keymap.image = "http://propertyshark.com/maps/keymaps/" + this.locale + ".png";
	//this.keymap_obj = null;
	
	this.tools.scalebar = [];
	this.tools.scalebar.height=32;
	this.tools.scalebar.width=100;
	
	this.tools.copyright = [];
	this.tools.copyright.height=10;
	this.tools.copyright.width=242;
	
	this.tools.linksmenu = [];
	this.tools.linksmenu.height = 32;
	this.tools.linksmenu.width = 240;
	
	this.map.focusarea = [];
	this.map.focusarea.x = -1;
	this.map.focusarea.y = -1;
	this.map.focusarea.show = 0;
	this.map.focusarea.default_radius = 12 // px
	this.map.focusarea.radius = this.map.focusarea.default_radius; // px
	
	this.map.focusarea.type = "point";
	this.map.focusarea.radius_feet = 0; // px

	this.map.highlightpolygons = [];
	this.map.highlightpolygons.show = 0;
	
	this.map.report = [];
	this.map.report.width = 260;
	this.map.report.headerHeight = 22;
	this.map.report.x = 0.5;
	this.map.report.y = 0.5;
	this.map.report.show = 0;
	this.map.report.is_showing = 0;
	this.map.report.is_available = 1;
	this.map.report.url = "/mason/Maps/mapclick.html";
	this.map.report.current_photo = 1;
	
	this.map.feature = [];
	this.map.feature.url = "/mason/Maps/mapclick_geopicker.html";
	this.map.feature.loader = [];
	
	this.map.feature.geopicker_subregion_config = {};
	this.map.feature.subregion_type = "";
	this.map.feature.selecthoverColor = "#3b0";
		
	
	this.map.zoom_frame_center_x = 0;
	this.map.zoom_frame_center_y = 0; 
	this.map.zoom_frame_width = 0;
	this.map.zoom_frame_height = 0;
	
	this.legend_dropdown = 0;
	this.display_legend = 1;
	
	this.control.legend = [];
	
	this.tileplaceholder = new Image();
	this.tileplaceholder.src = "/img/spacer.gif";
	
	this.position_from_url = false;
	this.current_zoom = 0;
	this.previous_zoom = -1;

	this.proposed_basemap = "";
	
	if (this.locale == "nyc2"){
		this.current_basemap = this.locale+"/buildings";
	}else{	
		this.current_basemap = this.locale+"/default";
	}
	
	this.current_overlays = [];
	
	this.current_menu_tab_name = "themes";
	
	this.search_results = [];
	this.current_search_address = "";
	
	this.search_text = "Look it up!";
	this.searching_text = "Working...";
	
	this.poi_array = [];
	this.poi_overlays = [];
	this.current_pois = [];
	
	this.overlay_zi_n = 110;
	this.poi_zi_n = 300;

//	this.extra_maps = {};
	
	this.loading = 1;
	
	this.current_scr = 0;
	this.view_count = [];
	
	this.basemap_tile_queue = [];
	this.overlay_tile_queue = [];
	this.tile_queue_timer = false;
	this.free_tiles = 150;
	this.view_locked = false;
	
	this.polygon_enabled = false;
	
	this.mode = "zoom";
	
	this.show_copyright = false;
	this.disable_reportview = false;
	
	this.map.relative = true;
	
	this.xmlhttp = [];
	this.xml_source = "";
	
	this.init_view = true;
	this.init_center_x = 0.5;
	this.init_center_y = 0.5;
	this.init_zoom = 3;
	
	this.variant = false;
	this.use_local = false;
	this.u = false;
	this.max_zoom = null;

	this.current_panels = [];	
	
	this.view_tracker_function = null;
};

psharkmap.prototype.paint = function () {
	PSRKMAP.active_map = this;
	this.setInitValues();
	this.paintToolbar();
	this.paintCanvas();
	this.paintCopyright();
	this.paintMapPanel();
	this.paintBasemap();
	this.setBasemapInfo();
	this.paintOverlaysInit();
	this.paintLockLayer();
	this.loadMapPanel();
	this.hideCanvasLoader();
	this.paintReport();
	this.paintControlPanel();
	this.paintKeyMap();
	this.paintZoomTool();
	this.paintScaleBar();
	this.initLoadFocusArea();
	this.initLoadHighlightPolygons();
	this.loadLayerInfo();
	this.paintPolygonPanel();
	if (this.current_overlays.length>0){
		PSRKMAP.changeView(this.current_basemap+","+this.current_overlays);
	}else{
		PSRKMAP.changeView(this.current_basemap);
	}
	if (this.map.feature.import_array){
		this.importFeatures();
	}
};

psharkmap.prototype.positionComponents = function(){
	this.positionMap();
	this.positionControlPanel();
	this.positionKeyMap();
	this.positionScaleBar();
	this.positionZoomTool();
//	this.positionLinksMenu();
}

psharkmap.prototype.repaint = function () {
	var canvas_pos = this.getPos(this.canvas.obj);
	this.canvas_offset_x = canvas_pos[0];
	this.canvas_offset_y = canvas_pos[1];
 
	if (this.canvas.fullWidth || this.canvas.fullHeight){
		if (this.canvas.fullWidth){
			if (this.canvas.set_in_layout){
				this.canvas.width = this.getAvailDim()[0] - 2 * this.canvas.margin;
			}else{
				this.canvas.width = this.getAvailDim()[0] - 2 * this.canvas.margin - 2 * this.canvas.borderWidth;
			}
		}else{
			this.canvas.width = this.canvas.width;
		}

		this.canvas.height = this.canvas.fullHeight ? this.getAvailDim()[1] - 2 * this.canvas.margin - 2 * this.canvas.borderWidth - this.getPos(this.canvas.obj)[1] : this.canvas.height;
		this.checkCanvasMinDim();
		this.paintToolbar();
		this.paintCopyright();
		this.paintLockLayer();
		this.positionComponents();
		this.paintReport();
		this.paintControlPanel();
		if (this.current_overlays.length>0){
			PSRKMAP.changeView(this.current_basemap+","+this.current_overlays);
		}else{
			PSRKMAP.changeView(this.current_basemap);
		}
	
		this.resizePanel();
		if (this.legenddropdown_obj){
			this.legenddropdown_obj.adjustHeight();
		}
		if (this.map.dialog_layer){
			this.paintDialogLayer();
		}
		this.setControlPanelBorder();
	}
};

psharkmap.prototype.setMapConfig = function () {
	this.map_offset_x = 0;
	this.map_offset_y = 0;
	this.map_placed = false;
	
	this.slide_timer = false;
	this.slide_steps = 10;
	
	if (this.use_local){
		if (!this.path){
			alert("Make sure to specify a local path");
		}
	}else{
		this.path = (PSRKMAP.remote_load) ? "http://www.propertyshark.com/maps/psharkmap/" : "/maps/psharkmap/";
	}
	this.home_link = (PSRKMAP.remote_load || true) ? "/" : "http://www.propertyshark.com";
	this.logo_img =  this.path + "maplogo.gif";

	var config = eval("new "+this.locale+"_config()");
	this.zoomlevel_array = config.zl;
	if (this.max_zoom) {
		this.zoomlevel_array.splice(this.max_zoom+1,this.zoomlevel_array.length);
	}
	this.basemap_array = [];
	this.overlay_array = [];
	
	this.legend_title = config.legend_title;
	this.legend_url = config.legend_url;
	
	this.base_url = "http://propertyshark.com/maps/";
	this.base_url_legends = "http://propertyshark.com/maps/legends/";

	this.subscriber = PSRKMAP.subscriber;
};

psharkmap.prototype.getInput = function () {
	if (!this.position_from_url){
		return;
	}
	var mapstate = this.GetCookie("mapstate");
	var arrmapstate;

	if (mapstate !== null && mapstate != 'undefined'){
		arrmapstate = mapstate.split(",");

		if (arrmapstate.length == 6){
			if (arrmapstate[0] == this.locale){
				this.current_basemap = arrmapstate[1];
				this.current_overlays = arrmapstate[2].split(" ");
				this.map_coord_center_x = arrmapstate[3];
				this.map_coord_center_y = arrmapstate[4];
				this.current_zoom = Math.max(0,Math.min(arrmapstate[5],this.zoomlevel_array.length-1));
				this.DeleteCookie("mapstate");
			}
		}
	}
	
	var inputsource = [window.location.search,window.location.hash];
	var ax = false;
	var ay = false;
	var fullzoom=0;
	var markers = [];
	var len, pairs, key, val, vc, str, mark, marker,vc_arr;
	var i,j,v,k;

	for (var i=0; i < inputsource.length; i++){
		len = inputsource[i].length;
		pairs = inputsource[i].substring(1, len).split("&");

		for (var j=0; j < pairs.length; j++ ) {
			key = pairs[j].split("=")[0];
			val = pairs[j].split("=")[1];
			switch(key) {
				case "zoom": this.current_zoom = Math.max(0,Math.min(val,this.zoomlevel_array.length-1));break;
				case "x": this.map_coord_center_x = val;break;
				case "y": this.map_coord_center_y = val;break;
				case "map":
				if (val != this.locale){
					this.switchLocale(val);
				}
				break;
				case "basemap": this.current_basemap = this.locale+"/"+val;break;
				case "overlay":
					if (val){
						this.current_overlays = val.split(",");
						for (k = 0; k < this.current_overlays.length; k++){
							this.current_overlays[k] = this.locale+"/"+this.current_overlays[k];
						}
					}
					break;
				case "poi":
					this.current_pois = val.split(",");
					for (k = 0; k < this.current_pois.length; k++){
						this.current_pois[k] = this.locale+"/"+this.current_pois[k];
					}
					break;
				case "tab": this.current_menu_tab_name = unescape(val); break;
				case "star": this.map.focusarea.show = parseInt(val,10);break;
				case "ax": this.map.focusarea.x = val; ax=1;break;
				case "ay": this.map.focusarea.y = val; ay=1;break;
				case "report": this.map.report.show = parseInt(val,10);break;
				case "fullzoom": fullzoom = parseInt(val,10);break;
				case "xml": this.xml_source = val;break;
				case "marker": cat = val;
					marker = val.split(',');
					mark = [];
					mark.x = marker[0];
					mark.y = marker[1];
					mark.address = unescape(marker[2]);
					this.search_results.push(mark);
				break;
				case "host":
					this.tile_server = val;
					this.alt_host = true;
					if (this.tile_server.indexOf("http://") !== 0){
						this.tile_server = "http://"+this.tile_server;
					}
				break;
				case "variant": this.variant = val;break;
			}
		}

		this.overlay_array = this.getInitOverlays();
		this.basemap_array = this.getInitBasemap();

		if (this.map.focusarea.show || this.map.report.show){
			if (this.map.focusarea.x < 0){
				this.map.focusarea.x = this.map_coord_center_x;
			}
			if (this.map.focusarea.y < 0){
				this.map.focusarea.y = this.map_coord_center_y;
			}
		}
		
		if (ax && ay){
			this.map.focusarea.show = 1;
		}
		
		if (fullzoom==1){
			this.current_zoom = this.zoomlevel_array.length-1;
		}
		
		if (this.map_offset_x && this.map_offset_y){
			this.map_placed = true;
		}
		
		vc = this.GetCookie(this.locale+"vc");
		if (vc){
			vc_arr = vc.split(";");
			for (v = 0; v < vc_arr.length; v++){
				this.view_count[vc_arr[v].split(":")[0]]=vc_arr[v].split(":")[1];
			}
			str = "";
			for (key in this.view_count){
				if (key != 'removeValue' && key != 'inArray'){
					if (str){
						str += ";";
					}
					str += key + ":" + this.view_count[key];
				}
			}
		}
	}
};

psharkmap.prototype.updateSubscriber = function() {
	var pajax = new psharkmapAJAXobj();
	pajax.method = "POST";
	pajax.setURL("/mason/Maps/js/subscriber.js");
	pajax.setTargetFunction(this.loadLayerInfo);
	pajax.sendRequest();
};

psharkmap.prototype.loadLayerInfo = function (str) {
	var map_obj = this;
	if (PSRKMAP.remote_load){
		this.subscriber = true;
		this.updateLayerInfo("PSRKMAP."+this.locale+"_maps");
	}else{
		if(str) {
			eval(str);
		} else {
			this.updateSubscriber();
	
			var xml_override = (this.xml_source == "new") ? "&xml=new" : "";
			var pajax = new psharkmapAJAXobj();
			pajax.setURL("/mason/Maps/MAP/"+this.locale+".js?v=2&json=1"+xml_override+"&subscriber="+PSRKMAP.subscriber);
			pajax.setTargetFunction(PSRKMAP.updateLayerInfo);
			pajax.pushFunctionArg(this.psharkmap_id);
			pajax.sendRequest();
		}
	}
};

psharkmap.prototype.updateLayerInfo = function (str,id) {
	var info = eval("("+str+")");
	var lg = [];
	var i,j;
	for (i = 0; i < info.overlays.groups.length; i++){
		lg[i] = [];
		lg[i].title = info.overlays.groups[i].title;
		lg[i].la = [];
		for (j = 0; j < info.overlays.groups[i].maps.length; j++){
			lg[i].la[j] = [];
			lg[i].la[j].path = info.overlays.groups[i].maps[j].path;
			lg[i].la[j].name = info.overlays.groups[i].maps[j].name;
			lg[i].la[j].legend_title = info.overlays.groups[i].maps[j].legend_title;
			lg[i].la[j].legend_url = info.overlays.groups[i].maps[j].legend_url;
			lg[i].la[j].desc = info.overlays.groups[i].maps[j].desc;
		}
//			if (this.extra_maps.overlays){
//				for (i2 = 0; i2 < this.extra_maps.overlays.groups.length; i2++){
//					if (info.overlays.groups[i].title == this.extra_maps.overlays.groups[i2].title){
//						for (j2 = 0; j2 < this.extra_maps.overlays.groups[i2].maps.length; j2++){
//							lg[i].la[j] = [];
//							lg[i].la[j].path = this.extra_maps.overlays.groups[i2].maps[j2].path;
//							lg[i].la[j].name = this.extra_maps.overlays.groups[i2].maps[j2].name;
//							lg[i].la[j].legend_title = this.extra_maps.overlays.groups[i2].maps[j2].legend_title;
//							lg[i].la[j].legend_url = this.extra_maps.overlays.groups[i2].maps[j2].legend_url;
//							lg[i].la[j].desc = this.extra_maps.overlays.groups[i2].maps[j2].desc;
//								j++;
//						}
//					}
//				}
//			}
	}
	
	for (i = 0; i < info.basemaps.groups.length; i++){
		this.basemap_array[i] = [];
		this.basemap_array[i].title = info.basemaps.groups[i].title;
		this.basemap_array[i].bm = [];
		for (j = 0; j < info.basemaps.groups[i].maps.length; j++){
			this.basemap_array[i].bm[j] = [];
			this.basemap_array[i].bm[j].path = info.basemaps.groups[i].maps[j].path;
			this.basemap_array[i].bm[j].name = info.basemaps.groups[i].maps[j].name;
			this.basemap_array[i].bm[j].legend_title = info.basemaps.groups[i].maps[j].legend_title;
			this.basemap_array[i].bm[j].legend_url = info.basemaps.groups[i].maps[j].legend_url;
			this.basemap_array[i].bm[j].scr = info.basemaps.groups[i].maps[j].scr;
			this.basemap_array[i].bm[j].desc = info.basemaps.groups[i].maps[j].desc;
			this.basemap_array[i].bm[j].max_zoom = info.basemaps.groups[i].maps[j].max_zoom;
			this.basemap_array[i].bm[j].copyright = info.basemaps.groups[i].maps[j].copyright;
			if (info.basemaps.groups[i].maps[j].path==this.current_basemap){
				this.current_scr = info.basemaps.groups[i].maps[j].scr;
				this.max_zoom = info.basemaps.groups[i].maps[j].max_zoom;
				this.setBasemapCopyright(i,j);
			}
		}
//			if (this.extra_maps.basemaps){
//				for (i2 = 0; i2 < this.extra_maps.basemaps.groups.length; i2++){
//					if (info.basemaps.groups[i].title == this.extra_maps.basemaps.groups[i2].title){
//						for (j2 = 0; j2 < this.extra_maps.basemaps.groups[i2].maps.length; j2++){
//							this.basemap_array[i].bm[j] = [];
//							this.basemap_array[i].bm[j].path = this.extra_maps.basemaps.groups[i2].maps[j2].path;
//							this.basemap_array[i].bm[j].name = this.extra_maps.basemaps.groups[i2].maps[j2].name;
//							this.basemap_array[i].bm[j].legend_title = this.extra_maps.basemaps.groups[i2].maps[j2].legend_title;
//							this.basemap_array[i].bm[j].legend_url = this.extra_maps.basemaps.groups[i2].maps[j2].legend_url;
//							this.basemap_array[i].bm[j].scr = this.extra_maps.basemaps.groups[i2].maps[j2].scr;
//							this.basemap_array[i].bm[j].desc = this.extra_maps.basemaps.groups[i2].maps[j2].desc;
//							this.basemap_array[i].bm[j].max_zoom = this.extra_maps.basemaps.groups[i2].maps[j2].max_zoom;
//							if (this.extra_maps.basemaps.groups[i2].maps[j2].path==this.current_basemap){
//								this.current_scr = this.extra_maps.basemaps.groups[i2].maps[j2].scr;
//								this.max_zoom = this.extra_maps.basemaps.groups[i2].maps[j2].max_zoom;
//							}
//							j++;
//						}
//					}
//				}
//			}
	}
	this.overlay_array = lg;
	this.addPOIsToLayers();
	this.paintOverlays();

	this.paintThemesControl();
	if (!PSRKMAP.remote_load){
		this.paintSearchControl();
//		if (PSRKMAP.map_debug) this.paintSearchTabbedControl();
	}
	this.paintTabsControl();

	this.setThemePanelSize();
	
	if (this.legend_dropdown){
		this.paintLegendDropDown();
	}
	
};

psharkmap.prototype.setInitValues = function(){
	if (this.map_coord_center_x && this.map_coord_center_y) {
		this.init_center_x = this.map_coord_center_x;
		this.init_center_y = this.map_coord_center_y;
	}
	this.init_zoom = this.current_zoom;
};

psharkmap.prototype.mapSelf = function (id) {
	this.map_id = id;
};

psharkmap.prototype.setMapCenter = function(x,y){
	this.map_coord_center_x = x;
	this.map_coord_center_y = y;
};

psharkmap.prototype.setMapZoom = function(z){
	this.current_zoom = parseInt(z,10);
};

psharkmap.prototype.setMaxZoom = function(z){
	this.max_zoom = z;
};

psharkmap.prototype.setOverlays = function () {
	for (var i = 0; i < arguments.length; i++){
		var arg_arr = arguments[i].split(",");
		for (var j = 0; j < arg_arr.length; j++){
			this.current_overlays.push(this.locale+"/"+arg_arr[j]);
		}
	}
};

psharkmap.prototype.setPointsLayers = function () {
	for (var i = 0; i < arguments.length; i++){
		var arg_arr = arguments[i].split(",");
		for (var j = 0; j < arg_arr.length; j++){
			this.current_pois.push(this.locale+"/"+arg_arr[j]);
		}
	}
};
psharkmap.prototype.displayOverlay = function (overlay) {
	this.toggleOverlay(overlay,true);
};
psharkmap.prototype.hideOverlay = function () {
	this.toggleOverlay(arguments[0],false);
};

psharkmap.prototype.setBasemap = function (basemap) {
	this.current_basemap = this.locale+"/"+basemap;
};
psharkmap.prototype.displayBasemap = function (basemap) {
	this.changeBasemapLayer(this.locale+"/"+basemap);
};

psharkmap.prototype.setReport = function(x,y){

};
psharkmap.prototype.setUsage = function(){
	this.u = (!PSRKMAP.remote_load);
};

psharkmap.prototype.setMicroZoom = function(){
	this.tools.zoom_tool.micro = 1;
};

psharkmap.prototype.setStatic = function(){
	this.no_zoom = 1;
	this.no_pan = 1;
}

psharkmap.prototype.setFocusAreaRadiusInFeet = function(r, x, y){
	if (r){
		this.map.focusarea.radius_feet = r;
		this.map.focusarea.type = "circle";
	}else{
		this.map.focusarea.type = "point";
	}
	
	if (x && y){
		this.map.focusarea.x = x;
		this.map.focusarea.y = y;
		this.map.focusarea.show = true;
	}
}

psharkmap.prototype.disableReports = function(){
	this.map.report.is_available = 0;
}

psharkmap.prototype.legendDropdown = function(){
	this.legend_dropdown = 1;
	if (arguments.length){
		this.display_legend = arguments[0];
	}
}

psharkmap.prototype.setFeatureSubRegion = function(subregion){
	this.map.feature.subregion = subregion;
}

psharkmap.prototype.setXMLSource = function(source){
	this.xml_source = source;
};

psharkmap.prototype.setExtraMaps = function(obj){
	// Deprecated
	// this.extra_maps = obj;
}

psharkmap.prototype.useLocal = function(path){ this.use_local=true; this.path = path; };

psharkmap.prototype.displayMaxMin = function () {
	
};

psharkmap.prototype.setBorderWidth = function (w) {
	this.canvas.borderTopWidth = this.canvas.borderRightWidth = this.canvas.borderBottomWidth = this.canvas.borderLeftWidth = this.canvas.borderWidth = w;
};

psharkmap.prototype.setInsideMargin = function (m) {
	this.tools.margin = parseInt(m,10);
}

psharkmap.prototype.getFeatureOnClick = function(bool){
	this.mode = (bool) ? "geopicker" : "zoom";
};

psharkmap.prototype.setFeatureExportFunction = function(f){ this.map.feature.export_function = f; };

psharkmap.prototype.setFeatures = function(arr){ this.map.feature.import_array = arr; };

psharkmap.prototype.setFeatureConfig = function(obj){
	this.map.feature.geopicker_subregion_config = obj;
}
psharkmap.prototype.setFeatureJSONTiles = function(){
	this.map.feature.json_tiles = true;
	this.map.feature.url = "/mason/Maps/mapclick_geopicker2.html";
}
psharkmap.prototype.setFeatureNoTiles = function(){
	this.map.feature.no_tiles = true;
	this.map.feature.url = "/mason/Maps/mapclick_geopicker.html";
}

psharkmap.prototype.setViewTrackerFunction = function(f){ this.view_tracker_function = f; };

psharkmap.prototype.displayMap = function(){
	for (var i=0; i < PSRKMAP.arr_mapobjects.length; i++){
		if (this==PSRKMAP.arr_mapobjects[i]){
			PSRKMAP.singleinit(this);
		}
	}
}

// global functions and objects

PSRKMAP.updateLayerInfo = function(str,id){
	PSRKMAP.active_map = PSRKMAP.getMap(id);
	if (!PSRKMAP.active_map){
		return false;
	}
	PSRKMAP.active_map.updateLayerInfo(str,id);
}


PSRKMAP.changeView = function(view){
 // we need to update an external function
 // which is supposed to override this one!!!
}

PSRKMAP.legendStatus = function(status){}

PSRKMAP.getMapFromChild = function(obj){
	while (obj){
		for (var i=0; i < PSRKMAP.arr_mapobjects.length; i++){
			if (PSRKMAP.arr_mapobjects[i].canvas.obj == obj){
				return PSRKMAP.arr_mapobjects[i];
			}
		}
		obj = obj.parentNode;
	}
	return null;
}

PSRKMAP.getMapById = function(id){
	for (var i=0; i < PSRKMAP.arr_mapobjects.length; i++){
		if (PSRKMAP.arr_mapobjects[i].psharkmap_id == id){
			return PSRKMAP.arr_mapobjects[i];
		}
	}
	return null;
}

// functions not part of the PSRKMAP namespace yet

psharkmapLocale = function(v){
	// this is not moved to the PSRKMAP namespace yet,
	// since it's used from without
	// update all references too...
	var locale = v ? v : "nyc2";
	var inputsource = [window.location.search,window.location.hash];
	var len, pairs, key, val, i, j;
	for (var i=0; i < inputsource.length; i++){
		len   = inputsource[i].length;
		pairs = inputsource[i].substring(1, len).split("&");
		for (var j=0; j < pairs.length;j++) {
			key = pairs[j].split("=")[0];
			val = pairs[j].split("=")[1];
			// use 'if' instead of 'switch' since there is only one case to look for
			if (key == "map") {
				locale = val;
			}
		}
	}
	return locale;
}

//  psharkmap section

// psharkmap member functions

// global functions and objects

function psharkmap(id, locale, locale_pretty){
	var id = id;
	this.psharkmap_id = id;
	
	// make our canvas an object
	this.canvas = [];
	this.canvas.obj = PSRKMAP$(id);
	if ( !this.canvas.obj ){
		this.canvas.obj = id;
		if( this.canvas.obj.className!="psharkmap" ){
			return;
		}
	}
	this.locale = (locale) ? locale : "nyc2";
	this.locale_pretty = (locale_pretty) ? locale_pretty : this.locale;
	
	this.header_text = this.canvas.obj.innerHTML;
	this.canvas.obj.innerHTML = "";
	PSRKMAP.arr_mapobjects.push(this);

	// initial setup complete
	
	// inline members
	
	this.loadCanvasSpecs();
}

// all the extra

//  basemap section

// psharkmap member functions

psharkmap.prototype.paintBasemap = function(){
	if (!this.map.base_map_layer){
	this.map.base_map_layer = this.cE("div",this.map.root);
	this.map.base_map_layer.className = "ps_base_map_layer"
	}
	if (!this.map.load_layer){
	this.map.load_layer = this.cE("div",this.canvas.obj);
	this.map.load_layer.className = "ps_load_layer";
	this.map.load_layer.id = "load_layer";
	}
};

psharkmap.prototype.clearBaseMapLayer = function(){
	if (this.map.base_map_layer){
	this.map.base_map_layer.innerHTML = "";
	}
};

psharkmap.prototype.changeBasemapLayer = function(basemap){
	if (this.isBasemap(basemap)){
	this.clearZoomMapLayer()
	this.clearBaseMapLayer();
	this.current_basemap = basemap;
	this.changeBasemapLegend(basemap);
	this.setBasemapInfo();
	this.lockMap();
	this.clearTileQueue();
	this.loadMapPanel();
	this.setBasemapPanelSize();
	this.basemapMaxZoomThreshold();
	}
};

psharkmap.prototype.isBasemap = function(basemap){
	for (var i=0; i < this.basemap_array.length; i++) {
		for (var j=0; j < this.basemap_array[i].bm.length; j++){
			if (this.basemap_array[i].bm[j].path === basemap){
			return true;
			}
		}
	}
	return false;
};

psharkmap.prototype.setBasemapInfo = function(){
	var basemap = this.current_basemap;
	for(var i=0; i < this.basemap_array.length; i++) {
		for (var j=0; j < this.basemap_array[i].bm.length; j++){
			if (this.basemap_array[i].bm[j].path === basemap){
			this.current_scr = this.basemap_array[i].bm[j].scr;
			this.max_zoom = this.basemap_array[i].bm[j].max_zoom;
			this.setBasemapCopyright(i,j);
			}
		}
	}
	return false;
};

psharkmap.prototype.setBasemapPanelSize = function(){
	this.setThemePanelSize();
};

psharkmap.prototype.getInitBasemap = function(){
	var bg = [];
	bg[0] = [];
	bg[0].title = "";
	bg[0].bm = [];
	bg[0].bm[0] = [];
	bg[0].bm[0].path = this.current_basemap;
	bg[0].bm[0].name = "";
	bg[0].bm[0].legend_title = null;
	bg[0].bm[0].legend_url = null;
	bg[0].bm[0].scr = 0;
	bg[0].bm[0].max_zoom = null;
	return bg;
};

psharkmap.prototype.basemapMaxZoomThreshold = function(){
	this.max_zoom_stepping = false;
	if (this.max_zoom){
		if (!this.use_default_tiles && this.current_zoom>this.max_zoom){
			this.use_default_tiles = 1;
			this.setDialogContent("max_zoom");
			this.map.dialog_layer.style.display = "block";
			this.map.dialog_layer.style.display = "block";
			this.view_locked = true;
			this.max_zoom_stepping = true;
			return true;
		}
		if (this.use_default_tiles && this.current_zoom<=this.max_zoom){
			this.use_default_tiles = 0;
			return true;
		}
	}else{
		this.use_default_tiles = 0;
	}
	return false;
};

psharkmap.prototype.setBasemapCopyright = function(i,j){
	if (this.use_local){
		return;
	}
	if (this.basemap_array[i].bm[j].copyright){	
		var path = this.basemap_array[i].bm[j].path;
		var pajax = new psharkmapAJAXobj();
		pajax.setURL("/mason/Maps/map_copyright.html?path="+path);
		pajax.setTargetFunction(PSRKMAP.setMapCopyright);
		pajax.pushFunctionArg(this.psharkmap_id);
		pajax.sendRequest();
	} else {
		this.setMapCopyright("");
	}
};

psharkmap.prototype.changeBasemap = function(basemap){
	// this was formerly a global function
	// not sure why...
	// JK, 12/30/08
	this.changeBasemapLayer(basemap);
	PSRKMAP.changeView(basemap);
};

// global functions and objects



//  canvas section

// psharkmap member functions

psharkmap.prototype.paintCanvas = function(){
	this.canvas.obj.style.width = this.canvas.width+"px";
	this.canvas.obj.style.height = this.canvas.height+"px";
	this.canvas.obj.style.margin = this.canvas.margin+"px";
	this.canvas.obj.style.padding = this.canvas.padding;
	
	var canvas_pos = this.getPos(this.canvas.obj)
	this.canvas_offset_x = canvas_pos[0]
	this.canvas_offset_y = canvas_pos[1]
};

psharkmap.prototype.setCanvasSize = function(canvasWidth, canvasHeight){
	canvasWidth = parseInt(canvasWidth);
	canvasHeight = parseInt(canvasHeight);
	this.canvas.fullWidth = 0;
	this.canvas.fullHeight = 0;
	this.canvas.width = isNaN(canvasWidth) ? this.canvas.defaultWidth : canvasWidth;
	this.canvas.height = isNaN(canvasHeight) ? this.canvas.defaultHeight : canvasHeight;
};

psharkmap.prototype.setCanvasFullScreen = function(){
	this.show_copyright = true;
	this.canvas.fullWidth = 1;
	this.canvas.fullHeight = 1;
	this.position_from_url = true;
	
	this.canvas.width = this.getAvailDim()[0]-2*this.canvas.margin-2*this.canvas.borderWidth;
	this.canvas.height = this.getAvailDim()[1]-2*this.canvas.margin-2*this.canvas.borderWidth;
	this.tools.zoom_tool.slider_height = 20;
	this.showCanvasLoader();
};

psharkmap.prototype.setCanvasInLayout = function(){
	this.show_copyright = true;
	this.canvas.set_in_layout = true;
	this.canvas.fullWidth = 1;
	this.canvas.fullHeight = 1;
	this.position_from_url = true;

	this.canvas.left_offset = (this.canvas.obj.parentNode.style.paddingLeft) ? parseInt(this.canvas.obj.parentNode.style.paddingLeft,10) : 0;
	this.canvas.right_offset = (this.canvas.obj.parentNode.style.paddingRight) ? parseInt(this.canvas.obj.parentNode.style.paddingRight,10) : 0;

	this.canvas.width = this.getAvailDim()[0]-2*this.canvas.margin;

	this.canvas.borderTopWidth = Math.max(0,this.canvas.borderWidth);
	var top_offset = this.getPos(this.canvas.obj)[1];
	this.canvas.height = this.getAvailDim()[1]-2*this.canvas.margin-this.canvas.borderTopWidth-this.canvas.borderBottomWidth-top_offset;

	this.tools.zoom_tool.slider_height = 20;
	this.showCanvasLoader();
};

psharkmap.prototype.setControlPanel = function(){
	this.canvas.hasControlPanel = 1;
};

psharkmap.prototype.setKeymap = function(open,width,height){
	this.canvas.has_keymap = 1;
	this.canvas.keymap_open = open;
	if (width && height){
		this.tools.keymap.height=height;
		this.tools.keymap.width=width;
	}
};

psharkmap.prototype.checkCanvasMinDim = function(){
	if (this.canvas.width < this.canvas.minWidth){
		this.canvas.width = this.canvas.minWidth;
	}
	if (this.canvas.height < this.canvas.minHeight){
		this.canvas.height = this.canvas.minHeight;
	}
};

psharkmap.prototype.showCanvasLoader = function(){
	this.loader = this.getLoader("w","building map...");
	this.canvas.obj.appendChild(this.loader);
	this.loader.style.position = "absolute"
	this.loader.style.font = "bold 11px arial";
	this.loader.style.top = this.canvas.height/2-10+"px";
	this.loader.style.left = this.canvas.width/2-100+"px";
};

psharkmap.prototype.hideCanvasLoader = function(){
	if (this.loader){
		this.loader.style.display = "none";
	}
};

// global functions and objects

//  control panel section

// psharkmap member functions

psharkmap.prototype.paintControlPanel = function(){
	if (!this.canvas.hasControlPanel){
		return;
	}
	if (!this.canvas.displayControlPanel){
		if (this.control.obj){
			this.control.obj.style.display = "none";
		}
		return;
	}
	
	this.control.height = this.canvas.height;
	if (!this.control.obj){
		this.control.obj = this.cE("div");
		this.canvas.obj.appendChild(this.control.obj);
	}
	this.control.obj.style.width = this.control.width + "px";

	this.control.height = this.map.height + 2*this.canvas.borderWidth;
		
	this.control.obj.style.height = this.control.height + "px";
	this.control.obj.style.borderTop = this.canvas.borderTopWidth + "px " + this.canvas.borderStyle + " " + this.canvas.borderColor;
	
	this.control.obj.style.position = "absolute";
	this.control.obj.style.overflow = "hidden";
	this.control.obj.style.background = "#fff";
			
	this.positionControlPanel();
	
	this.control.obj.style.display = this.canvas.roomforControlPanel ? "block" : "none";
	this.control.obj.style.fontFamily = "arial";
};

psharkmap.prototype.positionControlPanel = function(){
	if (this.control.obj){
		if (!this.map.relative){
			this.control.obj.style.left = this.getPos(this.canvas.obj)[0] + 2*this.canvas.borderWidth + this.map.width + "px";
			this.control.obj.style.top = this.getPos(this.canvas.obj)[1] + "px";
		}else{
			this.setControlPanelOffset();
			if (this.canvas.border_width_user_set){
				this.control.obj.style.padding = (this.controlpanel_offset_y)+"px 0px 1px "+(this.controlpanel_offset_x+this.canvas.borderWidth)+"px";
				this.control.obj.style.clip = "rect("+(this.controlpanel_offset_y)+"px, "+(this.controlpanel_offset_x+this.control.width+this.canvas.borderWidth)+"px, "+(this.controlpanel_offset_y+this.control.height)+"px, "+(this.controlpanel_offset_x-0)+"px)";
			}else{
				this.control.obj.style.padding = (this.controlpanel_offset_y)+"px 0px 0px "+(this.controlpanel_offset_x)+"px";
				this.control.obj.style.clip = "rect("+(this.controlpanel_offset_y)+"px, "+(this.controlpanel_offset_x+this.control.width+this.canvas.borderWidth)+"px, "+(this.controlpanel_offset_y+this.control.height)+"px, "+(this.controlpanel_offset_x-0)+"px)";
			}
		}
		this.setThemePanelSize();
	}
};

psharkmap.prototype.paintSearchControl = function(){
	if (!this.canvas.hasControlPanel)return;
	if (!this.control.searchpanel){
		this.control.searchpanel = this.cE("div");
		
		this.control.searchpanel.style.display = "none";
		this.control.searchpanel.style.padding = "7px 12px";
		this.control.searchpanel.style.paddingBottom = "15px";
//		this.control.searchpanel.style.borderTop = this.canvas.borderTopWidth + "px " + this.canvas.borderStyle + " " + this.canvas.borderColor;
		this.control.themes.appendChild(this.control.searchpanel);
		
		this.control.property_search = this.cE("div");

		var h = this.getHElement("h3","Address Search");
		h.className = "theme_h";
		this.control.property_search.appendChild(h);
	
		this.search_form = this.cE("form");
		this.search_form.setAttribute("action","/mason/Lookup/resolve4.html");
//		this.search_form.setAttribute("action","/mason/Maps/mapparams.html");
		this.search_form.setAttribute("method","get");
		map_obj = this;
		this.search_form.onsubmit = function(){
			map_obj.setSearchCommentSection("");
			var action_url = map_obj.search_form.getAttribute("action");
			var q_string = "";
			
			map_obj.current_search_address = "";
			
			for (var i=0; i < map_obj.search_form.elements.length;i++){
				if (q_string != "") q_string += "&"
				if (map_obj.search_form.elements[i].name != "debug"){
					q_string += map_obj.search_form.elements[i].name + "=" + map_obj.search_form.elements[i].value;
					if (map_obj.search_form.elements[i].type == "text" || map_obj.search_form.elements[i].type == "select-one"){
						map_obj.current_search_address += map_obj.search_form.elements[i].value + " ";
					}
					if (map_obj.search_form.elements[i].type == "submit"){
						map_obj.search_form.elements[i].value = map_obj.searching_text;
						map_obj.search_form.elements[i].disabled = "disabled";
					}
				}		
			}
			
			action_url += "?" + q_string;
			var pajax = new psharkmapAJAXobj();
			pajax.setURL(action_url);
			pajax.setTargetFunction(PSRKMAP.getSearchResultsFlat);
			pajax.pushFunctionArg(map_obj);
			pajax.sendRequest();
			
			return false;
		}
		
		this.search_form.innerHTML = "<input type=\"hidden\" name=\"submit_to\" value=\"/mason/Maps/mapparams.html?loc="+this.locale+"\">";
		
		var search_fields = this.cE("div");
		search_fields.innerHTML = "Getting search form...";
		search_fields.className = "search_fields";
		this.search_form.appendChild(search_fields);
		
		this.control.property_search.appendChild(this.search_form);
		this.control.searchpanel.appendChild(this.control.property_search);
		
		var pajax = new psharkmapAJAXobj();
		pajax.setURL("/mason/Maps/search/"+this.locale+".html");
		pajax.setTargetObj(search_fields);
		pajax.sendRequest();

		this.control.search_results = this.cE("div");
		this.control.search_results.className = "search_results";
		this.control.search_results.style.display = "none";
		this.control.property_search.appendChild(this.control.search_results);

		this.control.search_comments = this.cE("div");
		this.control.search_comments.className = "search_comments";
		this.control.search_comments.style.display = "none";
		this.control.property_search.appendChild(this.control.search_comments);

		this.generateResultList();
		this.placeMarkers();
	}
};

psharkmap.prototype.paintSearchTabbedControl = function(){
	if (!this.canvas.hasControlPanel)return;
	if (!this.control.searchtabbedpanel){
		this.control.searchtabbedpanel = this.cE("div");
		
		this.control.searchtabbedpanel.style.padding = "7px 12px 15px";
		this.control.searchtabbedpanel.style.borderTop = this.canvas.borderTopWidth + "px " + this.canvas.borderStyle + " " + this.canvas.borderColor;
		
		var h = this.getHElement("h3","Address Search (admin only):");
		h.className = "theme_h";
		this.control.searchtabbedpanel.appendChild(h);
		
		this.tabbed_search_form = this.cE("form",this.control.searchtabbedpanel);
		this.tabbed_search_form.setAttribute("action","/mason");
		
		this.tabbed_search_form_body = this.cE("div",this.tabbed_search_form);
		this.tabbed_search_form_body.innerHTML = "Getting form...";

		this.tabbed_search_form_results = this.cE("div",this.tabbed_search_form);

		this.control.themes.appendChild(this.control.searchtabbedpanel);
		
		this.setSearchForm('street');
	}
};

psharkmap.prototype.setSearchForm = function(type) {
	var pajax = new psharkmapAJAXobj();
	pajax.setURL("/mason/Maps/search/forms_"+this.locale+".html?type="+type);
	pajax.setTargetObj(this.tabbed_search_form_body);
	pajax.sendRequest();
};

psharkmap.prototype.submitSearch = function(){	
	var query_string = "?map="+PSRKMAP.map.locale;
	for (var i=0; i < this.tabbed_search_form.elements.length;i++){
		if(this.tabbed_search_form.elements[i].name != 'debug')
			query_string += "&"+this.tabbed_search_form.elements[i].name+'='+this.tabbed_search_form.elements[i].value;
	}
	
	var pajax = new psharkmapAJAXobj();
	pajax.setURL("/mason/services/Maps/search.html"+query_string);
	pajax.setTargetFunction(PSRKMAP.loadSearchResults);
	pajax.sendRequest();
};

psharkmap.prototype.addLink = function(link,link_fn){
	var map_obj;
	var a = this.cE("a");
	a.setAttribute("href","javascript:void(0);");
	if(typeof(link)=="string"){
		var txt = document.createTextNode(link);
		a.appendChild(txt);
	}else{
		a.appendChild(link);
	}
	a.onclick = function(){
		link_fn();
		this.blur();
		return false;
	}
	return a;
};

psharkmap.prototype.attachMenuTab = function(){
	return true;
};

psharkmap.prototype.hideControlPanel = function(){
	// hide control panel
	this.canvas.displayControlPanel = 0;
	this.paint();
};

psharkmap.prototype.showControlPanel = function(){
	// show control panel
	this.canvas.displayControlPanel = 1;
	this.paint();
};

psharkmap.prototype.setPanelSize = function(obj){
	if (!obj) return;
	var scroll = obj.scrollTop;
	
	var avail_height = this.control.height - 2*this.canvas.borderWidth - this.control.map_tabs.offsetHeight;
	
	obj.style.paddingTop = "0";
	obj.style.paddingBottom = "0";

	obj.style.height = avail_height + "px";
	obj.style.overflow = "auto";

	obj.style.borderBottom = this.canvas.borderWidth + "px " + this.canvas.borderStyle + " " + this.canvas.borderColor;
	obj.style.borderRight = obj.style.borderBottom;

	if(scroll){
		obj.scrollTop = scroll;
	}
};

psharkmap.prototype.setThemePanelSize = function(){
	this.setPanelSize(this.control.themes);
	this.setCtrlPanelToggleSize();
};

psharkmap.prototype.setCtrlPanelToggleSize = function(){
	if (this.control.ctrlpanel_toggle){
		this.control.ctrlpanel_toggle.style.width = this.control.toggle_width + "px";
		this.control.ctrlpanel_toggle.style.height = this.control.height - 2*this.canvas.borderWidth + "px";
	}
};

psharkmap.prototype.setSearchPanelSize = function(){
	this.setThemePanelSize();
};

psharkmap.prototype.setControlPanelOffset = function(){
	if (this.canvas.border_width_user_set){
		this.controlpanel_offset_x = this.canvas.borderRightWidth + this.canvas.borderLeftWidth + this.map.width;
	}else{
		if (this.canvas.set_in_layout){
			this.controlpanel_offset_x = this.canvas.borderRightWidth + this.canvas.borderLeftWidth + this.map.width;
		}else{
			this.controlpanel_offset_x = 2*this.canvas.borderWidth + this.map.width;
		}
	}
	this.controlpanel_offset_y = 0;
};

psharkmap.prototype.setControlPanelBorder = function(){
};

psharkmap.prototype.paintTabsControl = function(){
	if (!this.canvas.hasControlPanel || this.control.map_tabs){
		return;
	}	

	this.control.map_tabs = this.cE("div");
	this.control.map_tabs.className = "map_tabs";
	this.control.map_tabs.style.borderRight = this.canvas.borderWidth + "px " + this.canvas.borderStyle + " " + this.canvas.borderColor;
	this.control.map_tabs.style.borderLeft = this.control.toggle_width + "px solid #fff";

	var ul = this.cE("ul");

	var li = this.cE("li");
	li.className = "sel";
	var a = this.cE("a");
	a.setAttribute("href","javascript:void(0)");
	a.innerHTML = "Maps & Layers";
	a.controls = this.control.currently_viewing;
	a.onclick = PSRKMAP.chooseTab;
	li.appendChild(a);
	ul.appendChild(li);

	var li = this.cE("li");
	var a = this.cE("a");
	a.setAttribute("href","javascript:void(0)");
	a.innerHTML = "Search";
	a.controls = this.control.searchpanel;
	a.onclick = PSRKMAP.chooseTab;
	li.appendChild(a);
	ul.appendChild(li);

	var line = this.cE("div");
	line.className = "line";

	this.control.map_tabs.appendChild(ul);
	this.control.map_tabs.appendChild(line);

	this.control.obj.insertBefore(this.control.map_tabs, this.control.obj.lastChild);

	ul.style.paddingLeft = (ul.offsetWidth + 1 - ul.childNodes[0].offsetWidth - ul.childNodes[1].offsetWidth )/2 + "px";
}

PSRKMAP.chooseTab = function(){
	var ul = this.parentNode.parentNode;
	for (var i=0;i<ul.childNodes.length;i++){
		var el = ul.childNodes[i];
		if (el == this.parentNode){
			el.className= "sel";
			this.controls.style.display = "block";
		}else{
			el.className= "";
			el.firstChild.controls.style.display = "none";
		}
	}
	this.blur();
}

psharkmap.prototype.paintThemesControl = function(){
	if (!this.canvas.hasControlPanel){
		this.loadOverlays();
		return;
	}
	
	if (!this.control.themes){
		var padding = 0;
		var d = 0;

		this.control.ctrlpanel_toggle = this.addLink("",PSRKMAP.CtrlPanel_toggle);
		this.control.ctrlpanel_toggle.title = "Hide Control Panel";
		this.control.ctrlpanel_toggle.className = "ctrlpanel_toggle";
		this.control.ctrlpanel_toggle.style.borderBottom = this.canvas.borderWidth + "px " + this.canvas.borderStyle + " " + this.canvas.borderColor;
		this.setCtrlPanelToggleSize();
		this.control.obj.appendChild(this.control.ctrlpanel_toggle);

		this.control.themes = this.cE("div");
		this.control.themes.style.backgroundColor = this.control.backgroundColor;
		this.control.themes.style.borderLeft = this.control.toggle_width + "px solid #fff";
		this.control.obj.appendChild(this.control.themes);
		
		var map_obj = this;
		var is_current_menu_tab = this.attachMenuTab("Themes",this.control.themes,"themes");
		
		this.control.themesPanel = this.paintPanel(this.control.themesPanel,{"width":map_obj.control.wide_width+"px", "height":"100%", "align":"right", "valign":"top", "border":"yes", "padding":"5px", "resize_fn":PSRKMAP.linkMapOptionsAdjust, "close_fn":PSRKMAP.closeMapTheme, "parent":this.control.obj, "stay_open":true, "no_close_button":true},"themesPanel2");

		var cols = 4;
		var panelContent = this.cE("form");

		panelContent.name=this.map_id+"_themes_form";
		var pc_div = this.cE("div");
		pc_div.align="center";
		panelContent.appendChild(pc_div);
		
		this.map_options_table = this.cE("table");
		this.map_options_table.className = "map_options";
		var c_tb = this.cE("tbody",this.map_options_table);
		
		this.map_common_maps_table = this.cE("table");
		this.map_common_maps_table.className = "map_options";
		var map_common_maps_tb = this.cE("tbody",this.map_common_maps_table);

		this.map_common_layers_table = this.cE("table");
		this.map_common_layers_table.className = "map_options";
		var map_common_layers_tb = this.cE("tbody",this.map_common_layers_table);

		this.map_my_layers_table = this.cE("table");
		this.map_my_layers_table.className = "map_options my";
		var map_my_layers_tb = this.cE("tbody",this.map_my_layers_table);
		
		var c_tr = this.cE("tr",c_tb);
		
		// basemaps
		var c_td1 = this.cE("td",c_tr);
		c_td1.style.width = "50%";
		c_td1.style.padding="0 12px 0 0";
		c_td1.style.borderRight="1px solid #ddd";
		
		c_td1.innerHTML ="<h4 style='margin-bottom: 0;'>Maps</h4>";
		var c_t1 = this.cE("table",c_td1);
		c_t1.className = "map_options";
		var c_tb1 = this.cE("tbody",c_t1);
		var c_tr1 = this.cE("tr",c_tb1);

			


		// featured basemaps
		
		var c_tr1 = this.cE("tr",c_tb1);
		var c_td_bmf = this.cE("td",c_tr1);
		c_td_bmf.style.width = "50%";
		c_td_bmf.className = "featured";
	
		// other basemaps
		
		var c_tr1 = this.cE("tr",c_tb1);
		var c_td_bm1 = this.cE("td",c_tr1);
		
		

		
		// overlays
		var c_td3 = this.cE("td",c_tr);
		c_td3.style.width = "50%";
		c_td3.style.padding="0 0 0 12px";
		c_td3.innerHTML ="<h4 style='margin-bottom: 0;'>Map Layers</h4>";
		var c_t3 = this.cE("table",c_td3);
		c_t3.className = "map_options";
		var c_tb3 = this.cE("tbody",c_t3);
		var c_tr3 = this.cE("tr",c_tb3);


		
		
		

		// featured overlays
		var c_tr3 = this.cE("tr",c_tb3);
		var c_td_laf = this.cE("td",c_tr3);
		c_td_laf.style.width = "50%";
		c_td_laf.className = "featured";

		// other overlays
		var c_tr3 = this.cE("tr",c_tb3);
		var c_td_la1 = this.cE("td",c_tr3);
		
		
		// begin basemaps
		var c = 0;
		var cur_td = c_td_bm1;
		for (var i=0; i < this.basemap_array.length; i++) {
			cur_td = (this.basemap_array[i].title) ? c_td_bm1 : c_td_bmf;
			var h = (this.basemap_array[i].title) ?
						this.getHElement("h5",this.basemap_array[i].title) :
						this.getHElement("h5","Basic Maps");
			var group = this.cE("table");


			var g_tb = this.cE("tbody",group);
			var cg = 0;
			for (var j=0; j < this.basemap_array[i].bm.length; j++){
				var is_current = (this.basemap_array[i].bm[j].path == this.current_basemap);
				var tr = this.paintBasemapRow(i,j,is_current);
				g_tb.appendChild(tr);
			}
			cur_td.appendChild(h);
			cur_td.appendChild(group);
		}

		for (var i=0; i < this.basemap_array.length; i++) {
			if (!this.basemap_array[i].title){
				for (var j=0; j < this.basemap_array[i].bm.length; j++){
					var is_current = (this.basemap_array[i].bm[j].path == this.current_basemap);
					var tr = this.paintBasemapRow(i,j,is_current,true);
					map_common_maps_tb.appendChild(tr);
				}
			}
		}
		// end basemaps
		
		
		// begin overlays
		var c = 0;

		this.clicked_overlays = [];
		cur_td = c_td_la1;
		for (var i=0; i < this.overlay_array.length; i++) {
			cur_td = (this.overlay_array[i].title) ? c_td_la1 : c_td_laf;
			var h = (this.overlay_array[i].title) ?
					this.getHElement("h5",this.overlay_array[i].title) :
					this.getHElement("h5","Basic Layers");
			h.className = "theme_group_panel";
			h.id = this.map_id+this.overlay_array[i].title+"_la_";
			var group = this.cE("table");
			var g_tb = this.cE("tbody",group);
			var cg=0;
			for (var j=0; j < this.overlay_array[i].la.length; j++){
				if (this.overlay_array[i].la[j].type == "personal"){
					cur_td = c_td_laf;
				}
				var is_current = (this.current_overlays.inArray(this.overlay_array[i].la[j].path) || this.current_pois.inArray(this.overlay_array[i].la[j].path));
				var tr = this.paintOverlayRow(i,j,d,is_current);
				g_tb.appendChild(tr)
				d++;
			}
			cur_td.appendChild(h);
			cur_td.appendChild(group);
			var this_d = i;
		}

		for (var i=0; i < this.overlay_array.length; i++) {
			if (!this.overlay_array[i].title){
				for (var j=0; j < this.overlay_array[i].la.length; j++){
					var is_current = (this.current_overlays.inArray(this.overlay_array[i].la[j].path) || this.current_pois.inArray(this.overlay_array[i].la[j].path));
					var tr = this.paintOverlayRow(i,j,d,is_current,true);
					map_common_layers_tb.appendChild(tr);
					d++;
				}
			}else{
				for (var j=0; j < this.overlay_array[i].la.length; j++){
					if (this.overlay_array[i].la[j].type != "personal") continue;
					var is_current = (this.current_overlays.inArray(this.overlay_array[i].la[j].path) || this.current_pois.inArray(this.overlay_array[i].la[j].path));
					var tr = this.paintOverlayRow(i,j,d,is_current,true);
					map_my_layers_tb.appendChild(tr);
					d++;
				}
			}
		}
		// end overlays
		
		// add buttons
		c_tr = this.cE("tr",c_tb);
		c_td = this.cE("td",c_tr)
		c_td.style.padding = "10px 5px";
		c_td.style.borderTop = "1px solid #ddd";
		c_td.className = "sup";
		c_td.colSpan = 2;
		c_td.innerHTML="* Access limited to top zoom levels without map subscription.<br />&dagger; Limited access without map subscription.";

		pc_div.appendChild(this.map_options_table);
		
		this.map_options_intro = this.cE("div");
		this.map_options_intro.innerHTML = "Please select one map and as many layers as you want. Each map provides a different presentation or theme of the neighborhood or county in which you are interested. If one or more layers are selected, features are placed on top of the current map.";

		this.map_options_header = this.cE("div");
		
		var h3 = this.getHElement("h3","More Maps & Layers");
		h3.className = "theme_h";
		h3.appendChild(document.createTextNode("\u00a0\u00a0"));
		var az = this.newPanelCancelButton("themesPanel2");
		this.map_options_header.appendChild(az);
		az.style.position = "absolute";
		az.style.right = "24px";
		
		this.map_options_header.appendChild(h3);
		
		this.setPanelContent(this.control.themesPanel,this.map_options_header,panelContent,null);
		
		this.control.currently_viewing = this.cE("div")
		
		this.control.currently_viewing.style.padding = "7px 12px";
		this.control.currently_viewing.style.paddingBottom = "15px";
		this.control.currently_viewing.style.clear = "left";

		var h = this.getHElement("h3","Map Theme Summary");
		h.className = "theme_h";
		this.control.currently_viewing.appendChild(h);
		
		var s_t = this.cE("table");
		var s_tb = this.cE("tbody",s_t);
		var s_tr = this.cE("tr",s_tb);
		var s_th = this.cE("th",s_tr);
		s_th.innerHTML = "Location:";
		var s_td = this.cE("td",s_tr);
		s_td.innerHTML = "<b>"+this.locale_pretty+"</b>";

		var s_tr = this.cE("tr",s_tb);
		var s_th = this.cE("th",s_tr);
		s_th.innerHTML = "Map:";
		this.control.current_view_basemaps = this.cE("td",s_tr);
		
		var s_tr = this.cE("tr",s_tb);
		var s_th = this.cE("th",s_tr);
		s_th.innerHTML = "Map Layers:";
		this.control.current_view_overlays = this.cE("td",s_tr);

		this.control.currently_viewing.appendChild(s_t);
		
		s_t.className = "current_view";

		this.setControlCurrentView();
		
		var h = this.getHElement("h3","Maps & Layers");
		h.className = "theme_h";
		h.style.borderTop = "1px solid #ccc";
		h.style.paddingTop = ".8em";
		this.control.currently_viewing.appendChild(h);
		
		var h = this.getHElement("h5","Common Maps:");
		h.className = "map_options";
		this.control.currently_viewing.appendChild(h);
		this.control.currently_viewing.appendChild(this.map_common_maps_table);
		
		var h = this.getHElement("h5","Common Map Layers:");
		h.className = "map_options";
		this.control.currently_viewing.appendChild(h);
		this.control.currently_viewing.appendChild(this.map_common_layers_table);

		if (this.map_my_layers_table.rows.length){
			var h = this.getHElement("h5","My Layers:");
			h.className = "map_options";
			this.control.currently_viewing.appendChild(h);
			this.control.currently_viewing.appendChild(this.map_my_layers_table);
		}
		
		var a = this.addLink("",PSRKMAP.linkMapOptions)
		a.className = "psharkb get_more_maps";
		this.control.currently_viewing.appendChild(a);
		
		this.control.themes.appendChild(this.control.currently_viewing);
	}
};

psharkmap.prototype.paintGenericRow = function(i,j,is_current,type, is_clone){
	var obj = (type=="basemap") ? this.basemap_array[i].bm[j] : this.overlay_array[i].la[j];
	var row = this.cE("tr");
	row.id = this.map_id+"_"+obj.path+"_row";
	row.className = (is_current) ? "cur" : "";
	
	var td = this.cE("td",row);
	td.className = "td_input";
	
	var c;
	var map_id = this.map_id;
	var map_obj = this;
	
	if (type=="basemap"){
		c = (is_clone) ?
				this.getRadioElement(obj.path, obj.name, is_current, this.map_id+"_"+obj.path+"t_clone", this.map_id+"_basemaps_clone") :
		this.getRadioElement(obj.path, obj.name, is_current, this.map_id+"_"+obj.path+"t", this.map_id+"_basemaps");
		td.appendChild(c);
		c.onclick = function(){
			var my_id = this.id;
			if (is_clone){
				my_id = my_id.substring(0,my_id.indexOf("_clone"));
				var org = PSRKMAP$(my_id);
				if (org){
					org.checked = this.checked;
				}
			}else{
				var clone = PSRKMAP$(map_id+"_"+map_obj.current_basemap+"t_clone");
				if (clone){
					clone.checked = false;
				}
				clone = PSRKMAP$(my_id+"_clone");
				if (clone){
					clone.checked = this.checked;
				}
			}
			map_obj.setClassById(map_id+"_"+map_obj.current_basemap+"_row","");
			map_obj.setClassById(map_id+"_"+obj.path+"_row","cur");
			map_obj.changeBasemap(this.value);
			map_obj.setControlCurrentView();
		}
	}else{
		c = (is_clone) ?
			this.getCheckboxElement(obj.d,obj.name+" clone",is_current,obj.path+"_clone") : 
			this.getCheckboxElement(obj.d,obj.name,is_current,obj.path);
		c.poi = obj.poi;
		td.appendChild(c);

		c.onclick = function(){
			var my_id = this.id;
			if (is_clone){
				my_id = my_id.substring(0,my_id.indexOf("_clone"));
				var org = PSRKMAP$(my_id);
				if (org){
					org.checked = this.checked;
				}
			}else{
				var clone = PSRKMAP$(my_id+"_clone");
				if (clone){
					clone.checked = this.checked;
				}
			}

			map_obj.changeOverlay(my_id,this.value,this.checked,this.poi);

			if (this.checked){
				map_obj.setClassById(map_id+"_"+obj.path+"_row","prop");
			}else{
				map_obj.setClassById(map_id+"_"+obj.path+"_row","");
			}
			map_obj.setControlCurrentView();
		}
	}
	
	var td = this.cE("td",row);
	td.className = "td_label";
	var s = "";
	if (obj.scr==1){
		s = " &dagger;";
	}
	if (obj.scr==2){
		s = " *";
	}
	var l;
	if (type=="basemap"){
		l = this.getLabelElement(this.map_id+"_"+obj.path+"t",obj.name,"",s);
	}else{
		l = (!obj.poi) ? this.getLabelElement(obj.path,obj.name) : this.getLabelElement(obj.path,obj.name,this.path+"poi_"+obj.marker_class+"_tn.png");
	}
	l.style.font = "normal 11px arial";				
	td.appendChild(l);
	var d = this.cE("div",td);
	d.className = "map_expl";
	d.style.display="none";

	var td = this.cE("td",row);
	td.className = "td_q";
	td.align = "right";
	
	if(obj.desc==1){
		var a = this.cE("a",td);
		a.href="javascript:void(0)";
		a.innerHTML="\u00a0";
		var map_obj = this;
		var path = obj.path;
		a.onclick = function(){
			if (!this.loaded){
				d.innerHTML = "Loading...";
				var pajax = new psharkmapAJAXobj();
				pajax.setURL("/mason/Maps/map_explanation.html?path="+path);
				pajax.setTargetObj(d);
				pajax.sendRequest();
				this.loaded = true;
			}
			d.style.display = (d.style.display == "block") ? "none" : "block";
			this.blur();
		}
	}
	 return row;
};

psharkmap.prototype.setClassById = function(id,class_name){
	var r = PSRKMAP$(id);
	if (r){
		r.className = class_name;
	}
};

psharkmap.prototype.paintBasemapRow = function(i,j,is_current, is_clone){
	return this.paintGenericRow(i,j,is_current,"basemap", is_clone);
};

psharkmap.prototype.paintOverlayRow = function(i,j,d,is_current,is_clone){
	return this.paintGenericRow(i,j,is_current,"overlay", is_clone);
};

psharkmap.prototype.newPanelUpdateButton = function(panelContent){
	var map_obj = this;
	var az = this.cE("a");
	az.href="javascript:void(0);"
	var img = this.cE("img",az);
	img.src = this.path+"but_update.gif";
	img.border=0;
	az.style.margin="2px";

	az.onclick = function(){	
	
		var elem = panelContent.elements;
		map_obj.setClassById(map_obj.map_id+"_"+map_obj.current_basemap+"_row","");
		map_obj.setClassById(map_obj.map_id+"_"+map_obj.proposed_basemap+"_row","cur");
			

		for(var i = 0; i < elem.length; i++){
			if (elem[i].type=="radio" && elem[i].name==map_obj.map_id+"_basemaps" && elem[i].checked){
				map_obj.changeBasemap(elem[i].value);
			}
			if (elem[i].type=="checkbox"){
				if (elem[i].checked){
					map_obj.setClassById(map_obj.map_id+"_"+elem[i].id+"_row","cur");
				}else{
					map_obj.setClassById(map_obj.map_id+"_"+elem[i].id+"_row","");
				}
				if(map_obj.clicked_overlays[elem[i].id]%2 == 1){
					
					//alert(elem[i].poi);
					map_obj.changeOverlay(elem[i].id,elem[i].value,elem[i].checked,elem[i].poi);
				}
			}
		} 

		map_obj.clicked_overlays = [];
		map_obj.control.themesPanel.container.style.display="none";
		map_obj.setControlCurrentView();

		return false;
				
	}
	return az;
};

psharkmap.prototype.newPanelCancelButton = function(name){
	var map_obj = this;
	var az = this.cE("a");
	az.href="javascript:void(0);"
	az.className = "psharkb close_panel";
	
	az.onclick = function(){	
		map_obj.closeNamedPanel(name);
		return false;	
	}
	return az;
};

psharkmap.prototype.setControlCurrentView = function(){
	this.control.current_view_basemaps.innerHTML = "<ul>";
	for (var i=0; i < this.basemap_array.length; i++) {
			for (var j=0; j < this.basemap_array[i].bm.length; j++){
			if (this.basemap_array[i].bm[j].path == this.current_basemap){
				this.control.current_view_basemaps.innerHTML = "<li>"+this.basemap_array[i].bm[j].name+"</li>";
			}else{
				var radio_obj = PSRKMAP$(this.map_id+"_"+this.basemap_array[i].bm[j].path+"t");
				if (radio_obj){
					radio_obj.checked = false;
				}
			}
		}
	}
	this.control.current_view_basemaps.innerHTML += "</ul>";
	
	this.control.current_view_overlays.innerHTML = "<ul>";
	if (this.current_overlays.length>0 || this.current_pois.length>0){
		for (var i=0; i < this.overlay_array.length; i++) {
				for (var j=0; j < this.overlay_array[i].la.length; j++){		
					if (this.current_overlays.inArray(this.overlay_array[i].la[j].path)||this.current_pois.inArray(this.overlay_array[i].la[j].path)){
					this.control.current_view_overlays.innerHTML += "<li>"+this.overlay_array[i].la[j].name+"</li>";
				}
			}
		}
	}
	this.control.current_view_overlays.innerHTML += "</ul>";
};

// global functions and objects

PSRKMAP.loadSearchResults = function(str){
	if (!PSRKMAP.active_map)return false;
	var map_obj = PSRKMAP.active_map;
	if (str){
		var mypois = eval("("+str+")");
		map_obj.addNamedMultiPOIs(mypois,'search_results');
	}
}

PSRKMAP.closeMapTheme = function(){
	var map_obj = PSRKMAP.active_map;
	map_obj.setControlCurrentView();
	if (map_obj.control.width == map_obj.control.narrow_width){
		map_obj.control.width = map_obj.control.wide_width;
	} else {
		map_obj.control.width = map_obj.control.narrow_width;
	}
	if (map_obj.control.searchpanel && map_obj.control.searchpanel.stored_visibility != "undefined"){
		map_obj.control.searchpanel.style.visibility = map_obj.control.searchpanel.stored_visibility;
	}
	map_obj.repaint();
}
//  copyright section

// psharkmap member functions

psharkmap.prototype.paintCopyright = function(){
	if (!this.show_copyright) return;
	if (!this.tools.copyright.obj){
		this.tools.copyright.obj = document.createElement("div");
		this.tools.copyright.obj.style.position = "absolute";
		this.tools.copyright.obj.style.left = this.tools.margin+1+"px";

		this.tools.copyright.obj.style.zIndex = "20";
		this.tools.copyright.obj.className = "copyright";
		
		this.tools.copyright.map_obj = this.cE("div",this.tools.copyright.obj);
		this.tools.copyright.locale_obj = this.cE("div",this.tools.copyright.obj);		

		this.tools.copyright.locale_obj.className = (PSRKMAP.subscriber) ? "sub" : "notsub";
		this.tools.copyright.locale_obj.innerHTML += "Copyright 2009 Property Research Partners LLC."

		this.canvas.obj.appendChild(this.tools.copyright.obj);
	}
	this.tools.copyright.obj.style.width = this.getMapWidth()+"px";
	this.tools.copyright.obj.style.bottom = "0px";
	this.tools.copyright.obj.style.left = this.canvas.left_offset+this.canvas.borderLeftWidth+"px";
};

psharkmap.prototype.setMapCopyright = function(str){
	if (this.tools.copyright.map_obj){
		if (str != this.tools.copyright.map_obj.innerHTML){
			this.tools.copyright.map_obj.style.display = (str) ? "block" : "none";
			this.tools.copyright.map_obj.innerHTML = str;

			this.positionMap();
			this.positionZoomTool();
			this.positionKeyMap();
			this.positionScaleBar();

			this.paintControlPanel();
			this.resizePanel();
		}
	}
};

// global functions and objects

PSRKMAP.setMapCopyright = function(str,id){
	PSRKMAP.getMap(id).setMapCopyright(str);
}

//  events section

// psharkmap member functions

psharkmap.prototype.mousedown = function() {
	var e = arguments[0];
	if(!e) e = window.event;
	
	PSRKMAP.active_map = this;
		
	if (PSRKMAP.active_map.no_pan || PSRKMAP.active_map.no_zoom){
		return false;
	}

	var event_pos_obj = this.getEventPosObj(e);
	
	this.canvas_offset_x = this.getPos(this.canvas.obj)[0]
	this.canvas_offset_y = this.getPos(this.canvas.obj)[1]
	
	var posx = event_pos_obj.x-this.canvas_offset_x;

	var posy = (this.canvas.set_in_layout) ? event_pos_obj.y-this.canvas_offset_y-this.toolbar.offsetHeight : event_pos_obj.y-this.canvas_offset_y;
	
	this.old_x = posx;
	this.old_y = posy;
	
	this.mousedown_x = posx;
	this.mousedown_y = posy;

	if(e.button <= 1 && !e.shiftKey){
		// left button, so get ready to drag
		PSRKMAP.drag_ready = true;
		
		PSRKMAP.map_drag = true;
	
		if (this.zoomlevel_array.length-1 == this.current_zoom){
			PSRKMAP.active_map = this;		
		}

		return false;
	}else{
		// right button, so we might be trying to zoom
		PSRKMAP.right_zoom_out = true;
		this.map.obj.style.cursor = "default";
		this.current_x = posx;
		this.current_y = posy;
	}
};

psharkmap.prototype.doubleclick = function() {
	var e = arguments[0];
	if(!e) e = window.event;
	
	if (PSRKMAP.active_map.no_zoom){
		return false;
	}
	
	clearTimeout(this.slide_time);
	
	if (this.mode == "polygon" && this.polygonpanel_obj){
		if (PSRKMAP.drawing_polygon){
			this.polygonpanel_obj.placeVertex()
			return;
		}
	}
	
	PSRKMAP.active_map = this;
	PSRKMAP.drag_ready = false;
	
	var event_pos_obj = this.getEventPosObj(e);
	var posx = event_pos_obj.x;
	var posy = event_pos_obj.y;
	
	
	this.click_coord_x = (posx-this.getPos(this.map.base_map_layer)[0])/(this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size);
	this.click_coord_y = (posy-this.getPos(this.map.base_map_layer)[1])/(this.zoomlevel_array[this.current_zoom].y_tiles*this.zoomlevel_array[this.current_zoom].y_tile_size);
	
	var new_zoom = Math.min(this.zoomlevel_array.length-1,this.current_zoom+1)
	
	if (new_zoom != this.current_zoom){
		// we're not at the top zoom layer yet
		// so clear all layers and let's zoom
		// here is where a smooter zoom might be good
		// instead of a jump
//		this.clearMap();
		this.centerAndZoomMapPanel(this.click_coord_x,this.click_coord_y,new_zoom);
	}else{
		// we're at to zoom level,
		// just center the point that was clicked
//		this.centerMapPanel(this.click_coord_x,this.click_coord_y);
	}

	return false;
};

// global functions and objects


PSRKMAP.mousemove = function(e){
	
	if (PSRKMAP.active_map && PSRKMAP.map_drag){
	if (PSRKMAP.active_map.no_pan){
		return false;
	}
	if (PSRKMAP.active_map != "undefined" && PSRKMAP.active_map){
	
		var e = arguments[0];
		if(!e) e = window.event;
		
		// find delta x and y to see how much the mouse
		// position has changed
		var event_pos_obj = PSRKMAP.active_map.getEventPosObj(e);
		var posx = event_pos_obj.x-PSRKMAP.active_map.canvas_offset_x;
		var posy = event_pos_obj.y-PSRKMAP.active_map.canvas_offset_y;
		var posy = (PSRKMAP.active_map.canvas.set_in_layout) ? event_pos_obj.y-PSRKMAP.active_map.canvas_offset_y-PSRKMAP.active_map.toolbar.offsetHeight : event_pos_obj.y-PSRKMAP.active_map.canvas_offset_y;

		
		if (PSRKMAP.drag_polygon_vertex){	
			PSRKMAP.active_map.polygonpanel_obj.dragVertex(posx-PSRKMAP.active_map.mousedown_x,posy-PSRKMAP.active_map.mousedown_y)

			if (e.preventDefault) e.preventDefault();
			e.returnValue = false;
			return false;
		}
		
		
		if (PSRKMAP.sliding && PSRKMAP.active_map.tools.zoom_tool.slider){
			var max_scroll_down = (PSRKMAP.active_map.zoomlevel_array.length-1-PSRKMAP.active_map.current_zoom)*PSRKMAP.active_map.tools.zoom_tool.slider_height;
			var max_scroll_up = (PSRKMAP.active_map.current_zoom)*PSRKMAP.active_map.tools.zoom_tool.slider_height;

			if (PSRKMAP.active_map.canvas.set_in_layout){
				posy += PSRKMAP.active_map.toolbar.offsetHeight;
			}
			
			if (posy < PSRKMAP.active_map.tools.zoom_tool_slider_click_y+max_scroll_down && posy > PSRKMAP.active_map.tools.zoom_tool_slider_click_y-max_scroll_up){
	
				PSRKMAP.active_map.tools.zoom_tool_slider_cur_y = posy;
				
				var dy = PSRKMAP.active_map.tools.zoom_tool_slider_cur_y - PSRKMAP.active_map.tools.zoom_tool_slider_old_y;
				
				PSRKMAP.active_map.tools.zoom_tool_slider_y += dy;
				
				PSRKMAP.active_map.tools.zoom_tool_slider_y = Math.max(0,PSRKMAP.active_map.tools.zoom_tool_slider_y);
				PSRKMAP.active_map.tools.zoom_tool_slider_y = Math.min(PSRKMAP.active_map.tools.zoom_tool.slider_height*(PSRKMAP.active_map.zoomlevel_array.length-1),PSRKMAP.active_map.tools.zoom_tool_slider_y);
				
				PSRKMAP.active_map.tools.zoom_tool.slider.style.top = PSRKMAP.active_map.tools.zoom_tool_slider_y + "px";
				PSRKMAP.active_map.tools.zoom_tool_slider_old_y = PSRKMAP.active_map.tools.zoom_tool_slider_cur_y;
			}
			return false;
		};
		
		if (PSRKMAP.keymapnav && PSRKMAP.active_map.canvas.has_keymap){
			PSRKMAP.active_map.keymap_move_view(posx,posy);
			return false;	
		}
		
		if (PSRKMAP.right_zoom_out || PSRKMAP.right_zoom_in){
			PSRKMAP.active_map.suspendClick()
			if (abs(posx-PSRKMAP.active_map.old_x)>8 || abs(posy-PSRKMAP.active_map.old_y)>8){
	
				PSRKMAP.right_zoom_out = false;
				PSRKMAP.right_zoom_in = true;
				PSRKMAP.active_map.current_x = posx;
				PSRKMAP.active_map.current_y = posy;
				PSRKMAP.active_map.showRightZoomFrame(PSRKMAP.active_map.old_x-PSRKMAP.active_map.canvas.borderWidth,PSRKMAP.active_map.old_y-PSRKMAP.active_map.canvas.borderWidth,posx,posy);
			}else{
				PSRKMAP.active_map.hideRightZoomFrame();
			}
			return false;
		}
		
		if (PSRKMAP.active_map.mode=="geopicker"){
			if (Math.abs(posx - PSRKMAP.active_map.mousedown_x)>10 || Math.abs(posy - PSRKMAP.active_map.mousedown_y)>10){
				PSRKMAP.active_map.setMapCursorDown();
				PSRKMAP.active_map.map.feature.activated_mouse_listener = false;
			}
		}
	
		PSRKMAP.active_map.current_x = posx;
		PSRKMAP.active_map.current_y = posy;
	
		var dx = PSRKMAP.active_map.old_x - PSRKMAP.active_map.current_x;
		var dy = PSRKMAP.active_map.old_y - PSRKMAP.active_map.current_y;
	
		// if we are PSRKMAP.drag_ready and there
		// is a change in x or y positions
		// we move the map accordingly
		if (PSRKMAP.drag_ready && (dx || dy) && (PSRKMAP.active_map.mode=="zoom" || PSRKMAP.active_map.mode=="geopicker")){
			PSRKMAP.active_map.hideReport();
			PSRKMAP.dragging = true;
			if(PSRKMAP.dblclick_ready) PSRKMAP.active_map.suspendClick()
			
			PSRKMAP.active_map.map_offset_x += dx;
			PSRKMAP.active_map.map_offset_y += dy;
			PSRKMAP.active_map.loadMapPanel();
		}
		PSRKMAP.active_map.old_x = PSRKMAP.active_map.current_x;
		PSRKMAP.active_map.old_y = PSRKMAP.active_map.current_y;
	}
	return false;
	}
}

PSRKMAP.mouseup = function(e,dragpass){

	PSRKMAP.map_drag = false;

	if (!PSRKMAP.active_map)return false;
	
	if (!PSRKMAP.dragging){
		if(PSRKMAP.drag_ready){
			if (PSRKMAP.active_map.zoomlevel_array.length-1 == PSRKMAP.active_map.current_zoom){
				if (PSRKMAP.active_map.mode!="polygon" && !PSRKMAP.active_map.disable_reportview && !PSRKMAP.keymapnav){
				PSRKMAP.setProperty();
				}
			}else{

			}
		}
	}else{
		PSRKMAP.active_map.loadOverlays();
		if (PSRKMAP.active_map.map.feature && PSRKMAP.active_map.map.feature.no_tiles){
			PSRKMAP.active_map.repositionFeatureLayer();
		}
		if (PSRKMAP.active_map.map.feature.json_tiles){
			PSRKMAP.active_map.repositionCanvasLayers();
		}
		
	}
	
	if (!dragpass)PSRKMAP.drag_ready = false;
	if (!dragpass)PSRKMAP.dragging = false;
	
	if (PSRKMAP.sliding)PSRKMAP.active_map.setSlider();
	PSRKMAP.sliding = false;
	
	if (PSRKMAP.keymapnav){
		PSRKMAP.active_map.setViewFromKeyMap();
	}
	PSRKMAP.keymapnav = false;
	
	if (PSRKMAP.right_zoom_out)PSRKMAP.active_map.zoomOutRight();
	PSRKMAP.right_zoom_out = false;
	
	if (PSRKMAP.right_zoom_in){
		PSRKMAP.active_map.zoomRightZoomFrame();
		PSRKMAP.right_zoom_in = false;
	}
	
	if (PSRKMAP.drag_polygon_vertex){
		PSRKMAP.drag_polygon_vertex = false;
	}
	
	if (PSRKMAP.active_map.map.feature.json_tiles && PSRKMAP.active_map.view_tracker_function){
		PSRKMAP.active_map.view_tracker_function(PSRKMAP.active_map.getView());
	}
}

PSRKMAP.resize_timer;

window.onresize = function(){
	clearTimeout(PSRKMAP.resize_timer)
	PSRKMAP.resize_timer=setTimeout(function(){
	for (var i=0; i < PSRKMAP.arr_mapobjects.length; i++){
		PSRKMAP.arr_mapobjects[i].repaint();
	}
	},250);
};

PSRKMAP.mousewheel_delta = 0;

function handle(delta) {
	if (PSRKMAP.active_map){
		if(!PSRKMAP.active_map.canvas.fullWidth || !PSRKMAP.active_map.canvas.fullHeight) return;
	
		if (delta < 0){
			PSRKMAP.mousewheel_delta--;
		}else{
			PSRKMAP.mousewheel_delta++;
		}
		
		if (PSRKMAP.mousewheel_delta>2){
			PSRKMAP.active_map.mouseWheelZoomOut();
			PSRKMAP.mousewheel_delta = 0;
		}
		if (PSRKMAP.mousewheel_delta<-2){
			PSRKMAP.active_map.mouseWheelZoomIn();
			PSRKMAP.mousewheel_delta = 0;
		}
	}
}

// the mouse wheel stuff doesn't seem to work...

// Mousewheel stuff
// http://adomas.org/javascript-mouse-wheel/plain.html
function wheel(event){
	var delta = 0;
	if (!event) event = window.event;
	if (event.wheelDelta) {
		delta = event.wheelDelta/120; 
		if (window.opera) delta = -delta;
	} else if (event.detail) {
		delta = -event.detail/3;
	}
	if (delta){
		handle(delta);
	}
	if (event.preventDefault){
		event.preventDefault();
	}
	event.returnValue = false;
}

// Dean Edwards/Matthias Miller/John Resig
// See http://dean.edwards.name/weblog/2006/06/again/ for details

PSRKMAP.mapinit = function() {
	// quit if this function has already been called
	if (arguments.callee.done) return;
	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;

	// kill the timer
	if (_timer) clearInterval(_timer);

	for (var i=0; i < PSRKMAP.arr_mapobjects.length; i++){
		if (PSRKMAP.arr_mapobjects[i].initialized) continue;

	//	PSRKMAP.arr_mapobjects[i].loadCanvasSpecs();
		PSRKMAP.arr_mapobjects[i].setMapConfig();
		PSRKMAP.arr_mapobjects[i].getInput();
		
		PSRKMAP.arr_mapobjects[i].mapSelf(i);
		document.body.onmousemove = PSRKMAP.mousemove;
		document.body.onmouseup = function(){
			PSRKMAP.mouseup(arguments[0]);
		}
		
		PSRKMAP.arr_mapobjects[i].paint();
		PSRKMAP.arr_mapobjects[i].initialized = true;
	}
}

PSRKMAP.singleinit = function(obj) {
	if (obj.initialized) return;
	var id = PSRKMAP.arr_mapobjects.length-1;

	obj.setMapConfig();
	obj.getInput();
		
	obj.mapSelf(id);
	document.body.onmousemove=PSRKMAP.mousemove;
	document.body.onmouseup = function(){
		PSRKMAP.mouseup(arguments[0]);
	}
	
	obj.paint();
	obj.initialized = true;
}

/* for Mozilla/Opera9 */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", PSRKMAP.mapinit, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
	document.write("<script id=PSRKMAP._ie_onload defer src=javascript:void(0)><\/script>");
	var script = PSRKMAP$("PSRKMAP._ie_onload");
	if (script){
		script.onreadystatechange = function(){
			if (this.readyState == "complete"){
				PSRKMAP.mapinit(); // call the onload handler
			}
		};
	}
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)){ // sniff
	var _timer = setInterval(function(){
		if (/loaded|complete/.test(document.readyState)){
			PSRKMAP.mapinit(); // call the onload handler
		}
	}, 10);
}

/* for other browsers */
addEvent(window,"onload",PSRKMAP.mapinit);

function addEvent( obj, type, fn ) {
	if ( obj.attachEvent ){
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}else{
		obj.addEventListener( type, fn, false );
	}
}


//  focus area section

// psharkmap member functions

psharkmap.prototype.paintFocusArea = function(){
	if (!this.map.focusarea.obj){
		this.map.focusarea.obj = document.createElement("div");
		this.map.focusarea.obj.style.position = "absolute";
		this.map.focusarea.obj.style.visibility = "hidden";
		this.map.focusarea.obj.style.zIndex = "250";

		if (this.map.focusarea.use_canvas && this.map.focusarea.type == "circle" || this.map.focusarea.type == "polygon"){
			this.map.focusarea.obj.img = this.getCanvasElement();
		}else{
			this.map.focusarea.obj.img = document.createElement("img");
		}

		this.map.focusarea.obj.img.onmousedown = function(){
			return false;
		};
		this.map.focusarea.obj.img.onmouseup = function(){
			PSRKMAP.mouseup(arguments[0],true);
		};
		this.map.focusarea.obj.img.onmousemove = PSRKMAP.mousemove;
		
		this.map.focusarea.obj.appendChild(this.map.focusarea.obj.img);
		this.map.root.appendChild(this.map.focusarea.obj);
		
	}
	this.resizeFocusArea();
};

psharkmap.prototype.showFocusArea = function(){
	this.map.focusarea.show = 1;
	if (!this.map.focusarea.obj){
		this.paintFocusArea();
	}
	this.placeFocusArea();
	this.map.focusarea.obj.style.visibility = "visible";
};

psharkmap.prototype.hideFocusArea = function(){
	if (this.map.focusarea.obj){
		this.map.focusarea.obj.style.visibility = "hidden";
		this.map.focusarea.show = 0;
	}
};

psharkmap.prototype.centerFocusArea = function(x,y){
	if (this.map.focusarea.obj){

	}
};

psharkmap.prototype.setFocusAreaType = function(type, r, png){
	if (type){
		if (type=="circle" && r){
			this.map.focusarea.radius_feet = r;
		}
		if (type=="polygon" && r) {
			this.map.focusarea.polygon_points = r;
		}
		this.map.focusarea.type = type;
	}
	this.map.focusarea.use_canvas = (png) ? false : true;
};

psharkmap.prototype.setFocusArea = function(x, y){
	this.map.focusarea.x = x;
	this.map.focusarea.y = y;
	this.map.focusarea.show = 1;
};

psharkmap.prototype.resizeFocusArea = function(){
	var ft = (72*12)/this.zoomlevel_array[this.current_zoom].scale;
	if (this.map.focusarea.type == "circle"){
		this.map.focusarea.radius = Math.max(this.map.focusarea.default_radius,this.map.focusarea.radius_feet * ft);
	}else{
		this.map.focusarea.radius = this.map.focusarea.default_radius
	}

	if (this.map.focusarea.obj){

		if (this.map.focusarea.type == "polygon"){
		
			this.map.focusarea.obj.polygon_o = {"min_x":1,"min_y":1,"max_x":0,"max_y":0};
			for (var i=0; i < this.map.focusarea.polygon_points.length; i++){
				this.map.focusarea.obj.polygon_o.min_x = Math.min(this.map.focusarea.obj.polygon_o.min_x,this.map.focusarea.polygon_points[i].x)
				this.map.focusarea.obj.polygon_o.min_y = Math.min(this.map.focusarea.obj.polygon_o.min_y,this.map.focusarea.polygon_points[i].y)
				this.map.focusarea.obj.polygon_o.max_x = Math.max(this.map.focusarea.obj.polygon_o.max_x,this.map.focusarea.polygon_points[i].x)
				this.map.focusarea.obj.polygon_o.max_y = Math.max(this.map.focusarea.obj.polygon_o.max_y,this.map.focusarea.polygon_points[i].y)
			}
			this.map.focusarea.obj.img.setAttribute("width",parseInt(this.coordToXPx(this.map.focusarea.obj.polygon_o.max_x)) - parseInt(this.coordToXPx(this.map.focusarea.obj.polygon_o.min_x))+2);
			this.map.focusarea.obj.img.setAttribute("height",parseInt(this.coordToYPx(this.map.focusarea.obj.polygon_o.max_y)) - parseInt(this.coordToYPx(this.map.focusarea.obj.polygon_o.min_y))+2);
		}else{
			this.map.focusarea.obj.img.setAttribute("width",2*this.map.focusarea.radius);
			this.map.focusarea.obj.img.setAttribute("height",2*this.map.focusarea.radius);
		}
		this.drawFocusAreaShape();
	}
	if(this.map.focusarea.show){
		this.placeFocusArea();
	}
};

psharkmap.prototype.drawFocusAreaShape = function(){
	if (this.map.focusarea.type == "circle"){
		if (this.map.focusarea.use_canvas){
			var ctx = this.map.focusarea.obj.img.getContext('2d');
			ctx.lineWidth = 1;
			ctx.strokeStyle = "black";
			
			if (this.map.focusarea.radius > this.map.focusarea.default_radius){
				// draw circle
				// circle is using radius that is 2px too small
				ctx.fillStyle = "rgba(255, 0, 0, 0.2)";
				ctx.moveTo(0,0);
				ctx.beginPath();
				ctx.arc(this.map.focusarea.radius,this.map.focusarea.radius,this.map.focusarea.radius-2,0,Math.PI*2,true); // Outer circle
				ctx.closePath();
				ctx.fill();
				ctx.beginPath();
				ctx.arc(this.map.focusarea.radius,this.map.focusarea.radius,this.map.focusarea.radius-2,0,Math.PI*2,true); // Outer circle
				ctx.stroke();
			}else{
				// draw cross-hair
				ctx.fillStyle = "rgba(255, 0, 0, 0.6)";
				ctx.moveTo(0,0);
				ctx.beginPath();
				ctx.arc(this.map.focusarea.radius,this.map.focusarea.radius,4,0,Math.PI*2,true); // filled circle
				ctx.closePath();
				ctx.fill();
				ctx.beginPath();
				ctx.arc(this.map.focusarea.radius,this.map.focusarea.radius,4,0,Math.PI*2,true); // outer circle
				ctx.stroke();
				ctx.beginPath();
				ctx.moveTo(this.map.focusarea.radius,0);
				ctx.lineTo(this.map.focusarea.radius,this.map.focusarea.radius-6);
				ctx.moveTo(this.map.focusarea.radius,this.map.focusarea.radius+6);
				ctx.lineTo(this.map.focusarea.radius,2*this.map.focusarea.radius);
				ctx.moveTo(0,this.map.focusarea.radius);
				ctx.lineTo(this.map.focusarea.radius-6,this.map.focusarea.radius);
				ctx.moveTo(this.map.focusarea.radius+6,this.map.focusarea.radius);
				ctx.lineTo(2*this.map.focusarea.radius,this.map.focusarea.radius);
				ctx.closePath();
				ctx.stroke();
			}
		}else{
			this.map.focusarea.obj.img.src = this.path+"/img/circle.png";
		}
	}else if (this.map.focusarea.type == "polygon") {
		var c = [];

		
		var ctx = this.map.focusarea.obj.img.getContext('2d');
		ctx.lineWidth = 2;
		ctx.strokeStyle = "black";

		ctx.fillStyle = "rgba(255, 0, 0, 0.4)";


		
		var p_offset_x = parseInt(this.coordToXPx(this.map.focusarea.obj.polygon_o.min_x));
		var p_offset_y = parseInt(this.coordToYPx(this.map.focusarea.obj.polygon_o.min_y));
		
		

		
		ctx.beginPath();
		ctx.moveTo(parseInt(this.coordToXPx(this.map.focusarea.polygon_points[0].x))-p_offset_x+1,parseInt(this.coordToYPx(this.map.focusarea.polygon_points[0].y))-p_offset_y+1);
		for (var i=1; i < this.map.focusarea.polygon_points.length; i++){
			ctx.lineTo(parseInt(this.coordToXPx(this.map.focusarea.polygon_points[i].x))-p_offset_x+1,parseInt(this.coordToYPx(this.map.focusarea.polygon_points[i].y))-p_offset_y+1);
		}
		ctx.closePath();
		ctx.fill();
		
		ctx.beginPath();
		ctx.moveTo(parseInt(this.coordToXPx(this.map.focusarea.polygon_points[0].x))-p_offset_x+1,parseInt(this.coordToYPx(this.map.focusarea.polygon_points[0].y))-p_offset_y+1);
		for (var i=1; i < this.map.focusarea.polygon_points.length; i++){
			ctx.lineTo(parseInt(this.coordToXPx(this.map.focusarea.polygon_points[i].x))-p_offset_x+1,parseInt(this.coordToYPx(this.map.focusarea.polygon_points[i].y))-p_offset_y+1);
		}
		ctx.closePath();
		ctx.stroke();
	
		this.map.focusarea.obj.style.left = p_offset_x-1+"px";
		this.map.focusarea.obj.style.top =  p_offset_y-1+"px";		
	}else{
		this.map.focusarea.obj.img.src = this.path+"asterisk.gif";
	}
};

psharkmap.prototype.placeFocusArea = function(){
	if (!isNaN(this.current_zoom)){
		if (this.map.focusarea.type == "polygon"){
			this.map.focusarea.obj.style.left = parseInt(this.coordToXPx(this.map.focusarea.obj.polygon_o.min_x))-1+"px";
			this.map.focusarea.obj.style.top =  parseInt(this.coordToYPx(this.map.focusarea.obj.polygon_o.min_y))-1+"px";
		}else{
			this.map.focusarea.obj.style.left = this.map.focusarea.x * (this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size)-this.map.focusarea.radius+"px";
			this.map.focusarea.obj.style.top =  this.map.focusarea.y * (this.zoomlevel_array[this.current_zoom].y_tiles*this.zoomlevel_array[this.current_zoom].y_tile_size)-this.map.focusarea.radius+"px";
		}
	}
};

psharkmap.prototype.initLoadFocusArea = function(){
	if (this.map.focusarea.show){
		if (this.map.report.show){
			this.loadReport(this.map.focusarea.x,this.map.focusarea.y);
		}else{
			this.showFocusArea();
		}
	}
};

// global functions and objects

// highlight polygons section

psharkmap.prototype.setHighlightPolygons = function(geo){
	this.map.highlightpolygons.show = 1;
	this.map.highlightpolygons.polygons = geo;
}

psharkmap.prototype.initLoadHighlightPolygons = function(){
	if (this.map.highlightpolygons.show){
		this.showHighlightPolygons();
	}
}

psharkmap.prototype.showHighlightPolygons = function(){
	if (!this.map.highlightpolygons.obj){
		this.paintHighlightPolygons();
	}
	this.placeHighlightPolygons();
	this.map.highlightpolygons.obj.style.visibility = "visible";
}

psharkmap.prototype.paintHighlightPolygons = function(){
	if (!this.map.highlightpolygons.obj){
		this.map.highlightpolygons.obj = document.createElement("div");
		this.map.highlightpolygons.obj.style.position = "absolute";
		this.map.highlightpolygons.obj.style.visibility = "hidden";
		this.map.highlightpolygons.obj.style.zIndex = "251";

		this.map.highlightpolygons.obj.img = this.getCanvasElement();

		this.map.highlightpolygons.obj.img.onmousedown = function(){
			return false;
		};
		this.map.highlightpolygons.obj.img.onmouseup = function(){
			PSRKMAP.mouseup(arguments[0],true);
		};
		this.map.highlightpolygons.obj.img.onmousemove = PSRKMAP.mousemove;
		
		this.map.highlightpolygons.obj.appendChild(this.map.highlightpolygons.obj.img);
		this.map.root.appendChild(this.map.highlightpolygons.obj);
	}
	this.resizeHighlightPolygons();
}

psharkmap.prototype.resizeHighlightPolygons = function(){
	if (this.map.highlightpolygons.obj){
		this.map.highlightpolygons.obj.polygon_o = {"min_x":1,"min_y":1,"max_x":0,"max_y":0};
		for (var i=0; i<this.map.highlightpolygons.polygons.features.length; i++){
			var feature = this.map.highlightpolygons.polygons.features[i];
			if (feature.geometry.type == "MultiPolygon"){
				for (var k=0; k<feature.geometry.coordinates.length; k++){
					this.getSizeHighlightPolygons(feature.geometry.coordinates[k][0]);
				}
			}else{
				this.getSizeHighlightPolygons(feature.geometry.coordinates[0]);
			}
		}
		this.map.highlightpolygons.obj.img.setAttribute("width",parseInt(this.coordToXPx(this.map.highlightpolygons.obj.polygon_o.max_x)) - parseInt(this.coordToXPx(this.map.highlightpolygons.obj.polygon_o.min_x))+2);
		this.map.highlightpolygons.obj.img.setAttribute("height",parseInt(this.coordToYPx(this.map.highlightpolygons.obj.polygon_o.max_y)) - parseInt(this.coordToYPx(this.map.highlightpolygons.obj.polygon_o.min_y))+2);

		this.drawHighlightPolygonsShape();
	}
	if(this.map.highlightpolygons.show){
		this.placeHighlightPolygons();
	}
}

psharkmap.prototype.getSizeHighlightPolygons = function(coords){
	for (var j=0; j<coords.length; j++){
		this.map.highlightpolygons.obj.polygon_o.min_x = Math.min(this.map.highlightpolygons.obj.polygon_o.min_x,coords[j][0]);
		this.map.highlightpolygons.obj.polygon_o.min_y = Math.min(this.map.highlightpolygons.obj.polygon_o.min_y,coords[j][1]);
		this.map.highlightpolygons.obj.polygon_o.max_x = Math.max(this.map.highlightpolygons.obj.polygon_o.max_x,coords[j][0]);
		this.map.highlightpolygons.obj.polygon_o.max_y = Math.max(this.map.highlightpolygons.obj.polygon_o.max_y,coords[j][1]);
	}
}

psharkmap.prototype.drawHighlightPolygonsShape = function(){
	var ctx = this.map.highlightpolygons.obj.img.getContext('2d');
	ctx.lineWidth = 2;
	ctx.strokeStyle = "black";
	
	for (var i=0; i<this.map.highlightpolygons.polygons.features.length; i++){
		var feature = this.map.highlightpolygons.polygons.features[i];
		if (feature.geometry.type == "MultiPolygon"){
			for (var k=0; k<feature.geometry.coordinates.length; k++){
				this.drawHighlightPolygonsShapeDo(ctx, feature.geometry.coordinates[k][0], feature.properties.color);
			}
		}else{
			this.drawHighlightPolygonsShapeDo(ctx, feature.geometry.coordinates[0], feature.properties.color);
		}
	}

	this.placeHighlightPolygons();
}

psharkmap.prototype.drawHighlightPolygonsShapeDo = function(ctx, curr_poly, color){
	var p_offset_x = parseInt(this.coordToXPx(this.map.highlightpolygons.obj.polygon_o.min_x));
	var p_offset_y = parseInt(this.coordToYPx(this.map.highlightpolygons.obj.polygon_o.min_y));

	ctx.beginPath();
	ctx.moveTo(parseInt(this.coordToXPx(curr_poly[0][0]))-p_offset_x+1,parseInt(this.coordToYPx(curr_poly[0][1]))-p_offset_y+1);
	for (var i=1; i < curr_poly.length; i++){
		ctx.lineTo(parseInt(this.coordToXPx(curr_poly[i][0]))-p_offset_x+1,parseInt(this.coordToYPx(curr_poly[i][1]))-p_offset_y+1);
	}
	ctx.closePath();

	ctx.fillStyle = "rgba("+color+", 0.9)";
	ctx.fill();
}

psharkmap.prototype.placeHighlightPolygons = function(){
	if (!isNaN(this.current_zoom)){
		this.map.highlightpolygons.obj.style.left = parseInt(this.coordToXPx(this.map.highlightpolygons.obj.polygon_o.min_x))-1+"px";
		this.map.highlightpolygons.obj.style.top =  parseInt(this.coordToYPx(this.map.highlightpolygons.obj.polygon_o.min_y))-1+"px";
	}
}

//  keymap section

// psharkmap member functions

psharkmap.prototype.paintKeyMap = function(){
	if (!this.canvas.has_keymap) return;

	var map_obj = this;

	this.setKeyMapOffset();
	
	this.tools.keymap.borderOffset = (this.tools.margin) ? 2*this.canvas.borderWidth : this.canvas.borderWidth;
	this.tools.keymap.viewOffset = (this.tools.margin) ? this.canvas.borderWidth : 0;
	this.tools.keymap.full_width = this.tools.keymap.width;
	this.tools.keymap.full_height = this.tools.keymap.height;
	
	this.tools.keymap.view_minWidth = 4;
	this.tools.keymap.view_minHeight = 4;
	
	this.tools.keymap.toggle_width = this.tools.keymap.toggle_height = 16;

	if (!this.tools.keymap.el){
		this.tools.keymap.el = document.createElement("div");
		this.tools.keymap.el.style.position = "absolute";
		this.tools.keymap.el.style.width = this.tools.keymap.width+this.tools.keymap.borderOffset+"px";
		this.tools.keymap.el.style.height = this.tools.keymap.width+this.tools.keymap.borderOffset+"px";
		this.tools.keymap.el.style.backgroundColor = "#fff";
		this.tools.keymap.el.style.zIndex = "900";
		this.tools.keymap.el.style.overflow = "hidden";
		this.tools.keymap.el.style.visibility = "hidden";


		this.tools.keymap.img=document.createElement("img");
		this.tools.keymap.img.src=this.tools.keymap.image;
		this.tools.keymap.img.style.border = this.canvas.borderWidth + "px " + this.canvas.borderStyle + " " + this.canvas.borderColor;
		this.tools.keymap.img.style.zIndex = "102";

		this.tools.keymap.img.style.width = this.tools.keymap.width+"px";
		this.tools.keymap.img.style.height = this.tools.keymap.width+"px";
		this.tools.keymap.el.appendChild(this.tools.keymap.img);

		this.tools.keymap.el.ondblclick = function(){ return false; }
		
		this.tools.keymap.el.onmouseover = function(){
			if (PSRKMAP.dragging){
				this.style.cursor = (document.all) ? "move" : "-moz-grabbing";
			}
		}
		
		this.tools.keymap.el.onmouseup = function(){
			if (!PSRKMAP.dragging && map_obj.tools.keymap.click_nav && map_obj.canvas.keymap_open){
				var e = arguments[0];
				if(!e) e = window.event;
				// not ready yet
				map_obj.setKeyMapFromClick(e);
				PSRKMAP.map_drag = false;
			}
		}
		this.tools.keymap.el.onmousedown = function(){
			map_obj.tools.keymap.click_nav = true;
			//parent_obj.mousedown(arguments[0]);
			PSRKMAP.map_drag = true;
		}
		
		this.tools.keymap.el.onselectstart = function(){return false};
		
		this.tools.keymap.toggle = document.createElement("div");
		this.tools.keymap.toggle.style.zIndex = "104";
		this.tools.keymap.toggle.style.height = this.tools.keymap.toggle_height + this.canvas.borderWidth + "px";
		this.tools.keymap.toggle.style.width = this.tools.keymap.toggle_width + this.canvas.borderWidth + "px";
		
		this.tools.keymap.toggle.style.position = "absolute";
		this.tools.keymap.toggle.style.top = "0";
		this.tools.keymap.toggle.style.left = "0";
		this.tools.keymap.el.appendChild(this.tools.keymap.toggle);
		
		this.tools.keymap.toggle_a = document.createElement("a");
		this.tools.keymap.toggle_a.style.height = this.tools.keymap.toggle_height + "px";
		this.tools.keymap.toggle_a.style.width = this.tools.keymap.toggle_height + "px";
		this.tools.keymap.toggle_a.style.display = "block";
		this.tools.keymap.toggle_a.style.border = this.canvas.borderWidth + "px " + this.canvas.borderStyle + " " + this.canvas.borderColor;
		
		this.tools.keymap.toggle_a.style.background = "url('" + this.path + "img/keymap_toggle.png') 0 0 no-repeat";
		this.tools.keymap.toggle_a.style.backgroundPosition = (this.canvas.keymap_open) ? "0 0" : "0 -16px";
		this.tools.keymap.toggle.appendChild(this.tools.keymap.toggle_a);
		this.tools.keymap.toggle_a.style.cursor = "pointer"
		this.tools.keymap.toggle_a.title = (this.canvas.keymap_open) ? "Hide Keymap" : "Show Keymap";

		this.tools.keymap.toggle_a.onmouseup = function(){
			map_obj.canvas.keymap_open = !map_obj.canvas.keymap_open;
			// not ready yet
			map_obj.positionKeyMap();
			var event = (arguments[0])?arguments[0]:window.event;
			event.cancelBubble = true;
			if (event.stopPropagation) event.stopPropagation();
			map_obj.tools.keymap.toggle_a.style.backgroundPosition = (map_obj.canvas.keymap_open) ? "0 0" : "0 -16px";
			map_obj.tools.keymap.toggle_a.title = (map_obj.canvas.keymap_open) ? "Hide Keymap" : "Show Keymap";
		
			var status = (map_obj.canvas.keymap_open) ? 0 : 1;
			
			var url = "/mason/Reports2/customize_item.html?application=psharkmap&deselect_displaykeymap="+status;
			var pajax = new psharkmapAJAXobj();
			pajax.setURL(url);
			pajax.sendRequest();
			return false;		
		}
		
		this.canvas.obj.appendChild(this.tools.keymap.el);
	}
	
	this.tools.keymap.width = parseInt(this.tools.keymap.height*this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size / (this.zoomlevel_array[this.current_zoom].y_tiles*this.zoomlevel_array[this.current_zoom].y_tile_size));
	this.tools.keymap.el.style.width = this.tools.keymap.width+this.tools.keymap.borderOffset+"px";
	this.tools.keymap.img.style.width = this.tools.keymap.width+"px";
	this.tools.keymap.img.style.height = this.tools.keymap.height+"px";

	if (!this.tools.keymap.view){
		this.tools.keymap.view = document.createElement("div");
		this.tools.keymap.view.style.position = "absolute";
		this.tools.keymap.view.style.border = "2px solid #222";
		this.tools.keymap.view.style.zIndex = "103";
		this.tools.keymap.view.style.visibility = "hidden";
		this.tools.keymap.el.appendChild(this.tools.keymap.view);

		this.tools.keymap.view.style.cursor = (document.all) ? "move" : "-moz-grab";
		
		var img = document.createElement("img");
		img.src = this.path+"clear.gif";
		img.style.border = "none";
		this.tools.keymap.view.appendChild(img);
			
		this.tools.keymap.view.onmousedown = function(){
			map_obj.tools.keymap.view_lock = false;
			map_obj.tools.keymap.click_nav = false;
			this.style.cursor = (document.all) ? "move" : "-moz-grabbing";
			map_obj.keyMapNav(arguments[0]);
		}
		this.tools.keymap.view.onmouseup = function(){
			map_obj.tools.keymap.click_nav = false;
			this.style.cursor = (document.all) ? "move" : "-moz-grab";
			map_obj.keyMapNavComplete();
			return false;
		}
	}
	
	this.tools.keymap.view.onmouseover = function(){
		if (PSRKMAP.dragging){
			this.style.cursor = (document.all) ? "move" : "-moz-grabbing";
		}
	}

	this.positionKeyMap();
	this.tools.keymap.el.style.visibility = "visible";
	
	
};

psharkmap.prototype.resizeKeyMapSize = function(width, height){
	this.tools.keymap.width = Math.min(width,this.tools.keymap.full_width);
	this.tools.keymap.height = Math.min(height,this.tools.keymap.full_height);
	
	this.tools.keymap.el.style.width = this.tools.keymap.width+this.tools.keymap.borderOffset+"px";
	this.tools.keymap.el.style.height = this.tools.keymap.height+this.tools.keymap.borderOffset+"px";
	this.tools.keymap.img.style.width = this.tools.keymap.width+"px";
	this.tools.keymap.img.style.height = this.tools.keymap.height+"px";
	
	this.positionKeyMap();
};

psharkmap.prototype.positionKeyMap = function(){
	if (this.tools.keymap.el){		
		if (!this.map.relative){
		alert("are we ever here?")
			this.tools.keymap.el.y = this.map.height - this.tools.keymap.height;
			this.tools.keymap.el.style.top = this.tools.keymap.el.y - this.canvas.borderWidth + "px";
			if (this.canvas.hasControlPanel){
				this.tools.keymap.el.x = this.canvas.borderWidth + this.map.width - this.width;
			}else{
				this.tools.keymap.el.x = this.canvas.width - this.width - this.canvas.borderWidth;
			}
			this.tools.keymap.el.style.left = this.tools.keymap.el.x - this.canvas.borderWidth + "px";
		}else{
			this.setKeyMapOffset()
			this.tools.keymap.el.style.padding = (this.tools.keymap.offset_y - this.tools.keymap.borderOffset)+"px 0 0 "+(this.tools.keymap.offset_x - this.tools.keymap.borderOffset)+"px";
			if (this.canvas.keymap_open){
				this.tools.keymap.el.style.clip = "rect("+(this.tools.keymap.offset_y - this.tools.keymap.borderOffset)+"px, "+(this.tools.keymap.offset_x+this.tools.keymap.width)+"px, "+(this.tools.keymap.offset_y+this.tools.keymap.height)+"px, "+(this.tools.keymap.offset_x - this.tools.keymap.borderOffset)+"px)";
			}else{
				this.tools.keymap.el.style.clip = "rect("+(this.tools.keymap.offset_y + this.tools.keymap.height - this.tools.keymap.toggle_height-this.tools.keymap.borderOffset)+"px, "+(this.tools.keymap.offset_x+this.tools.keymap.width)+"px, "+(this.tools.keymap.offset_y+this.tools.keymap.height)+"px, "+(this.tools.keymap.offset_x + this.tools.keymap.width - this.tools.keymap.toggle_width-this.tools.keymap.borderOffset)+"px)";
			}
		}

		if (this.canvas.keymap_open){
			this.setKeyMapView();
		}
			
		this.tools.keymap.toggle.style.top = this.tools.keymap.offset_y+this.tools.keymap.height-this.tools.keymap.toggle_height-this.tools.keymap.borderOffset+"px";
		this.tools.keymap.toggle.style.left = this.tools.keymap.offset_x+this.tools.keymap.width-this.tools.keymap.toggle_width-this.tools.keymap.borderOffset+"px";
	}
};

psharkmap.prototype.setKeyMapView = function(){
	if (this.tools.keymap.el && this.canvas.keymap_open){
		if (this.tools.keymap.view_lock)return;
		var proposed_width = parseInt(this.tools.keymap.width * this.map.width / (this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size));
		var proposed_height = parseInt(this.tools.keymap.height * this.map.height / (this.zoomlevel_array[this.current_zoom].y_tiles*this.zoomlevel_array[this.current_zoom].y_tile_size));
		
		if (proposed_width<this.tools.keymap.view_minWidth || proposed_height<this.tools.keymap.view_minHeight){
			this.tools.keymap.view.width  = 16;
			this.tools.keymap.view.height = 16;
			this.tools.keymap.view.style.background = "url('"+this.path+"keymap_plus.gif') 50% 50% no-repeat";
			this.tools.keymap.view.style.border = "none";
			
			this.tools.keymap.view.x = parseInt(this.tools.keymap.width * (this.map_offset_x+this.map.width/2) / (this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size));
			this.tools.keymap.view.y = parseInt(this.tools.keymap.height * (this.map_offset_y+this.map.height/2) / (this.zoomlevel_array[this.current_zoom].y_tiles*this.zoomlevel_array[this.current_zoom].y_tile_size));
	
			this.tools.keymap.view.style.width  = this.tools.keymap.view.width+"px";
			this.tools.keymap.view.style.height = this.tools.keymap.view.height+"px";
			
			this.tools.keymap.view.style.left = this.tools.keymap.offset_x - this.tools.keymap.viewOffset + this.tools.keymap.view.x-8+"px";
			this.tools.keymap.view.style.top  = this.tools.keymap.offset_y - this.tools.keymap.viewOffset + this.tools.keymap.view.y-8+"px";
			
			if (this.tools.keymap.view.shape != "crosshair"){
				this.tools.keymap.crosshair_adjust = true;
			}

			this.tools.keymap.view.shape = "crosshair";	
		}else{
			this.tools.keymap.view.width  = proposed_width;
			this.tools.keymap.view.height = proposed_height;
			this.tools.keymap.view.style.border = "1px solid #222";
			this.tools.keymap.view.style.background = (window.XMLHttpRequest) ? "url('"+this.path+"png10.png') 0 0 repeat" : "none";
			
			this.tools.keymap.view.x = parseInt(this.tools.keymap.width  * this.map_offset_x / (this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size));
			this.tools.keymap.view.y = parseInt(this.tools.keymap.height * this.map_offset_y / (this.zoomlevel_array[this.current_zoom].y_tiles*this.zoomlevel_array[this.current_zoom].y_tile_size));
	
			this.tools.keymap.view.style.width  = this.tools.keymap.view.width-2+"px";
			this.tools.keymap.view.style.height = this.tools.keymap.view.height-2+"px";
			
			this.tools.keymap.view.style.left = this.tools.keymap.offset_x - this.tools.keymap.viewOffset + Math.min(this.tools.keymap.width-this.tools.keymap.view.width,this.tools.keymap.view.x)+"px";
			this.tools.keymap.view.style.top = this.tools.keymap.offset_y - this.tools.keymap.viewOffset + Math.min(this.tools.keymap.height-this.tools.keymap.view.height,this.tools.keymap.view.y)+"px";			
			this.tools.keymap.view.shape = "box";
		}
		this.tools.keymap.view.style.visibility = "visible";
	}
};

psharkmap.prototype.keyMapNav = function(){
	var e = arguments[0];
	if(!e) e = window.event;
	
	PSRKMAP.active_map = this;

	var event_pos_obj = this.getEventPosObj(e);
	var posx = event_pos_obj.x-this.canvas_offset_x;
	var posy = event_pos_obj.y-this.canvas_offset_y;
	
	if (this.tools.keymap.crosshair_adjust){
		this.tools.keymap.crosshair_adjust = false;
		this.tools.keymap.nav_click_x = posx+8;
		this.tools.keymap.nav_old_x = posx+8;
		this.tools.keymap.nav_click_y = posy+8;
		this.tools.keymap.nav_old_y = posy+8;
	}else{
		this.tools.keymap.nav_click_x = posx;
		this.tools.keymap.nav_old_x = posx;
		this.tools.keymap.nav_click_y = posy;
		this.tools.keymap.nav_old_y = posy;
	}

	this.tools.keymap.view.style.cursor = (document.all) ? "move" : "-moz-grabbing";
	
	PSRKMAP.keymapnav = true;

};

psharkmap.prototype.keyMapNavComplete = function(){

};

psharkmap.prototype.setViewFromKeyMap = function(){
	this.tools.keymap.click_nav = false;
	
	if (this.tools.keymap.view.shape == "box"){
		this.map_coord_center_x = (this.tools.keymap.view.x + this.tools.keymap.view.width/2)/this.tools.keymap.width;
		this.map_coord_center_y = (this.tools.keymap.view.y + this.tools.keymap.view.height/2)/this.tools.keymap.height;
	}else{
		this.map_coord_center_x = (this.tools.keymap.view.x+8)/this.tools.keymap.width;
		this.map_coord_center_y = (this.tools.keymap.view.y+8)/this.tools.keymap.height;
	}

	this.tools.keymap.view_lock = true;
	this.centerMapPanel(this.map_coord_center_x,this.map_coord_center_y);

};

psharkmap.prototype.setKeyMapFromClick = function(){
	var e = arguments[0];
	if(!e) e = window.event;
	var event_pos_obj = this.getEventPosObj(e);
	var keymap_pos = this.getPos(this.keymap_el)

	var posx = event_pos_obj.x + this.tools.keymap.viewOffset - keymap_pos[0]-this.tools.keymap.offset_x;
	var posy = event_pos_obj.y + this.tools.keymap.viewOffset - keymap_pos[1]-this.tools.keymap.offset_y;
	
	x = posx/this.tools.keymap.width;
	y = posy/this.tools.keymap.height;

	this.centerMapPanel(x,y);
};

psharkmap.prototype.unlockKeyMap = function(){
	if (this.tools.keymap.view){
		this.tools.keymap.view_lock = false;
	}
};

psharkmap.prototype.setKeyMapOffset = function(){
	if (this.canvas.border_width_user_set){
		this.tools.keymap.offset_x = this.map.width-this.tools.keymap.width-this.tools.margin;
		this.tools.keymap.offset_y = this.map.height-this.tools.keymap.height-this.tools.margin;
	}else{
		if (this.canvas.set_in_layout){
			this.tools.keymap.offset_x = this.map.width+this.canvas.borderLeftWidth-this.tools.keymap.width-this.tools.margin;
		}else{
			this.tools.keymap.offset_x = this.canvas.borderWidth + this.map.width-this.tools.keymap.width-this.tools.margin;
		}
		this.tools.keymap.offset_y = this.canvas.borderTopWidth + this.map.height-this.tools.keymap.height-this.tools.margin;
	}
};

psharkmap.prototype.keymap_move_view = function(posx,posy){

	this.tools.keymap.click_nav = false;
	this.tools.keymap.nav_cur_x = posx;
	this.tools.keymap.nav_cur_y = posy;

	if (this.canvas.set_in_layout){
		this.tools.keymap.nav_cur_y += this.toolbar.offsetHeight;
	}
	var dx = this.tools.keymap.nav_cur_x - this.tools.keymap.nav_old_x;
	var dy = this.tools.keymap.nav_cur_y - this.tools.keymap.nav_old_y;
	this.tools.keymap.view.x += dx;
	this.tools.keymap.view.y += dy;
	
	
	
	this.tools.keymap.view.x = Math.max( this.tools.keymap.view.x, 0 );
	this.tools.keymap.view.x = Math.min( this.tools.keymap.view.x, this.tools.keymap.width - this.tools.keymap.view.width);
	this.tools.keymap.view.y = Math.max( this.tools.keymap.view.y, 0);
	this.tools.keymap.view.y = Math.min( this.tools.keymap.view.y, this.tools.keymap.height - this.tools.keymap.view.height);
	
	this.tools.keymap.view.style.left = this.tools.keymap.view.x + this.tools.keymap.offset_x - this.tools.keymap.viewOffset + "px";
	this.tools.keymap.view.style.top  = this.tools.keymap.view.y + this.tools.keymap.offset_y - this.tools.keymap.viewOffset + "px";

	this.tools.keymap.nav_old_x = this.tools.keymap.nav_cur_x;
	this.tools.keymap.nav_old_y = this.tools.keymap.nav_cur_y;
	
	
};


// global functions and objects




//  legends section

// psharkmap member functions

psharkmap.prototype.paintLegendDropDown = function(){
	if (this.legend_dropdown){
		if (!this.legenddropdown_obj){
			this.legenddropdown_obj = new PSRKMAP.legend_dropdown({path:this.path,offset:this.tools.margin,parent_obj:this});
			this.legenddropdown_obj.appendTo(this.canvas.obj);
		}
	}
};

psharkmap.prototype.legendsShowing = function(){
	if (this.legend_dropdown && this.legenddropdown_obj){
		return (this.legenddropdown_obj.obj.style.display == "block");
	}
	return false;
};

psharkmap.prototype.highLightLegendTab = function(){
	if (this.legendsShowing()){
		this.toolbar_legends.className = "active";
	}
};

psharkmap.prototype.showOverlayLegend = function(overlay){
	if (this.legend_dropdown && this.legenddropdown_obj){
		this.legenddropdown_obj.showOverlayLegend(overlay);
		return;
	}
	if (this.control.legend["la"+overlay]){
		if (!this.control.legend["la"+overlay].childNodes[1].src){
			this.control.legend["la"+overlay].childNodes[1].src = this.control.legend["la"+overlay].childNodes[1].url;
		}
		this.control.legend["la"+overlay].style.display = "block";
	}
};

psharkmap.prototype.hideOverlayLegend = function(overlay){
	if (this.legend_dropdown && this.legenddropdown_obj){
		this.legenddropdown_obj.hideOverlayLegend(overlay);
		return;
	}
	if (this.control.legend["la"+overlay]){
		this.control.legend["la"+overlay].style.display = "none";
	}
};

psharkmap.prototype.displayOverlayLegendDefault = function(){
	var n = 0;
	
	for (var i=0;i < this.current_overlays.length; i++){
		if (this.control.legend["la"+this.current_overlays[i]]){
			n++;
		}
	}
};

psharkmap.prototype.changeBasemapLegend = function(basemap){
	if (this.legend_dropdown && this.legenddropdown_obj){
		this.legenddropdown_obj.changeBasemapLegend(basemap);
		return;
	}
	
	for (var i=0; i < this.basemap_array.length; i++) {
		for (var j=0; j < this.basemap_array[i].bm.length; j++){
			if (this.control.legend["bm"+this.basemap_array[i].bm[j].path]){
				if (this.basemap_array[i].bm[j].path == basemap){
					if (!this.control.legend["bm"+basemap].childNodes[1].src){
						this.control.legend["bm"+basemap].childNodes[1].src = this.control.legend["bm"+basemap].childNodes[1].url;
					}
					this.control.legend["bm"+this.basemap_array[i].bm[j].path].style.display = "block";
				}else{
					this.control.legend["bm"+this.basemap_array[i].bm[j].path].style.display = "none";
				}
			}
		}
	}
};

psharkmap.prototype.loadLegendControl = function(){
	if (this.control.legend.obj){
		this.control.legend.height = Math.max(0,this.canvas.height-2*this.canvas.borderWidth+this.getPos(this.control.obj)[1]-this.getPos(this.control.legend.obj)[1]-10);

		this.control.legend.obj.style.height = this.control.legend.height+"px";
		this.control.legend.obj.style.visibility = (this.control.legend.height) ? "visible" : "hidden";
	}	
};

// global functions and objects



PSRKMAP.legend_dropdown = function(obj_config){
	var legend_obj = this;
	this.width = obj_config.width;
	this.height = obj_config.height;
	this.path = obj_config.path;
	this.offset = obj_config.offset;
	this.parent_obj = obj_config.parent_obj;
	
	this.basemaps = [];
	this.overlays = [];
	
	this.min_height = 18;
	this.min_width = 214;
	this.scroll_width = this.parent_obj.getScrollerWidth();
	this.scroll_dist = 2;
	this.max_height = 2*this.parent_obj.map.height/3;
	this.legend_width = 0;
	
	this.obj = document.createElement("div");
	this.obj.style.position = "relative";
	this.obj.style.display = "block";
	this.obj.style.textAlign = "left";
	this.obj.style.zIndex = "900";
	this.obj.style.padding = "0px";
	this.obj.style.font = "bold 11px arial";
	this.obj.style.textAlign = "left";
//	this.obj.style.height = this.min_height+"px";
	this.obj.style.width = Math.max(this.legend_width,this.min_width)+this.scroll_width+"px";
	this.obj.style.overflow = "hidden";
	this.obj.style.top = this.parent_obj.canvas.borderTopWidth+"px";
	this.obj.style.left = this.parent_obj.canvas.borderLeftWidth+"px";
	this.obj.style.border = "1px solid "+this.parent_obj.canvas.borderColor;
	this.obj.style.borderWidth = "0 1px 1px 0";
	
	this.header_obj = document.createElement("div");
	this.header_obj.style.padding = "2px 5px 3px";
	this.header_obj.innerHTML = "<h3 style='font-size:12px; padding: 0;'>Current Map Legends</h3>";
	this.obj.appendChild(this.header_obj);
	
	this.obj.style.background = (window.XMLHttpRequest) ? "url('"+legend_obj.path+"pngw90.png')" : "#fff";
	this.legend = '';
	this.legend_images = [];
	
	this.scroll_timer = null;
	
	this.show_legends = this.parent_obj.display_legend;
		
	this.legends_obj = document.createElement("div");
	this.legends_obj.style.overflow = "auto";
	this.obj.style.display = (this.show_legends) ? "block" : "none";
	if (this.parent_obj.toolbar_legends){
		this.parent_obj.toolbar_legends.className = (this.show_legends) ? "active" : "";
	}
	this.obj.appendChild(this.legends_obj);

	this.basemaps_obj = document.createElement("div");
//	this.basemaps_obj.style.width = this.min_width+"px";
	this.basemaps_obj.style.overflow = "hidden";
	this.basemaps_obj.style.display = "none";
	this.basemaps_obj.style.padding = "0px";
	this.legends_obj.appendChild(this.basemaps_obj);
	this.overlays_obj = document.createElement("div");
//	this.overlays_obj.style.width = this.min_width+"px";
	this.overlays_obj.style.overflow = "hidden";
	this.overlays_obj.style.display = "none";
	this.overlays_obj.style.paddingLeft = "0px";
	this.legends_obj.appendChild(this.overlays_obj);
	this.general_obj = document.createElement("div");
//	this.general_obj.style.width = this.min_width+"px";
	this.general_obj.style.overflow = "hidden";
	this.general_obj.style.display = "none";
	this.general_obj.style.paddingLeft = "0px";
	this.legends_obj.appendChild(this.general_obj);

	this.closer_obj = document.createElement("a");
	this.closer_obj.className = "report_closer";
	this.closer_obj.style.position = "absolute";
	this.closer_obj.style.padding = "0px";
	this.closer_obj.style.top = "0px";
	this.closer_obj.style.right = "0px";
	this.closer_obj.href="javascript:void(0)";
	this.closer_obj.onclick = function(){
		this.blur();
		legend_obj.toggleView();
	}
	this.obj.appendChild(this.closer_obj);
	
	if (legend_obj.parent_obj.legend_title && legend_obj.parent_obj.legend_url){
	
		var title = legend_obj.parent_obj.legend_title;
		var url = "basemaps/" + legend_obj.parent_obj.legend_url;

		var legend = this.createLegend(title,url);

		this.general_obj.appendChild(legend);
		this.general_obj.style.display = "block";
		this.basemaps["default"] = {legend:legend};
	}
	
	for (var i=0; i < legend_obj.parent_obj.basemap_array.length; i++) {
		for (var j=0; j < legend_obj.parent_obj.basemap_array[i].bm.length; j++){
			if (legend_obj.parent_obj.current_basemap == legend_obj.parent_obj.basemap_array[i].bm[j].path ){
				if (legend_obj.parent_obj.current_basemap != legend_obj.legend){
					if (legend_obj.parent_obj.basemap_array[i].bm[j].legend_url){
						var legend = this.createLegend(legend_obj.parent_obj.basemap_array[i].bm[j].legend_title,"basemaps/" + legend_obj.parent_obj.basemap_array[i].bm[j].legend_url);
						this.basemaps_obj.appendChild(legend);
						this.basemaps[legend_obj.parent_obj.basemap_array[i].bm[j].path] = {legend:legend};
						this.basemaps_obj.style.display = "block";
					}
				}
			}
		}
	}

	for (var i=0; i < legend_obj.parent_obj.overlay_array.length; i++) {
		for (var j=0; j < legend_obj.parent_obj.overlay_array[i].la.length; j++){
			if (legend_obj.parent_obj.overlay_array[i].la[j].legend_url || legend_obj.parent_obj.overlay_array[i].la[j].poi){
				
				if (legend_obj.parent_obj.current_overlays.inArray(legend_obj.parent_obj.overlay_array[i].la[j].path)
					||
					legend_obj.parent_obj.current_pois.inArray(legend_obj.parent_obj.overlay_array[i].la[j].path)){
					
					var overlay = (legend_obj.parent_obj.overlay_array[i].la[j].poi) ?
							legend_obj.parent_obj.overlay_array[i].la[j].title
							:
							legend_obj.parent_obj.overlay_array[i].la[j].path
							;
					
					if (!this.overlays[overlay]){
					
						var legend = (legend_obj.parent_obj.overlay_array[i].la[j].poi) ?
							this.createLegend(legend_obj.parent_obj.overlay_array[i].la[j].legend_title,"legends/poi_" + legend_obj.parent_obj.overlay_array[i].la[j].marker_class + "_legend.png", true)
							:
							this.createLegend(legend_obj.parent_obj.overlay_array[i].la[j].legend_title,"overlays/" + legend_obj.parent_obj.overlay_array[i].la[j].legend_url)
							;
							
						this.overlays_obj.appendChild(legend);
						this.overlays[overlay] = (legend_obj.parent_obj.overlay_array[i].la[j].poi) ? {legend:legend,poi_count:1} : {legend:legend};
						this.overlays_obj.style.display = "block";
					}else{
						this.overlays[overlay].poi_count++;
					}
				}
			}
		}
	}		
	
	this.obj.onmouseover = function(){
		if (PSRKMAP.dragging){
			this.style.cursor = (document.all) ? "move" : "-moz-dragging";
		}
	};
}

PSRKMAP.legend_dropdown.prototype.appendTo = function(parent){
	if (parent){
		parent.appendChild(this.obj);
	}
};


PSRKMAP.legend_dropdown.prototype.createLegend = function(title,url,poi){
	Math.random();
	var legend_obj = this;
	var legend = document.createElement("div");
	legend.style.display = "block";
	var h = this.parent_obj.getHElement("h5",title);
	h.className = "h5_legend";
	legend.appendChild(h);
	var img = document.createElement("img");
	if (this.parent_obj.use_local){
		img.src = this.parent_obj.path + "legends/legend.png?3asdfr";
	}else{
	 	if (poi){
			img.src = legend_obj.parent_obj.path + url + "?" + Math.random();
		}else{
			img.src = legend_obj.parent_obj.base_url_legends + url + "?" + Math.random();
		}
	}
	
	img.i = this.legend_images.length;
	this.legend_images.push({img:img,loaded:false});
	legend.appendChild(img);
	
	img.onload = function(){
		legend_obj.getHeight();
	}
	if(img.complete){
		this.getHeight();
	}
	return legend;
};

PSRKMAP.legend_dropdown.prototype.adjustHeight = function(){

	this.max_height = 2*this.parent_obj.map.height/3;
	this.obj.style.width = (this.min_width + this.scroll_width) + "px";
	this.legends_obj.style.width = (Math.max(this.legend_width,this.min_width) + this.scroll_width) + "px";
	this.legends_obj.style.height = (Math.min((this.basemaps_obj.offsetHeight + this.overlays_obj.offsetHeight + this.general_obj.offsetHeight), this.max_height)) + "px";
	this.obj.style.height = (this.legends_obj.offsetHeight + this.header_obj.offsetHeight) + "px";
	this.obj.style.width = Math.max(this.legend_width,this.min_width)+this.scroll_width+"px";

//	this.obj.style.width = "400px";
};

PSRKMAP.legend_dropdown.prototype.imgLoaded = function(img){
	this.adjustHeight();
	if (!this.legend_images[img.i].loaded){
		this.legend_images[img.i].loaded = true;
		this.legend_images[img.i].height = img.height;
		this.legend_images[img.i].width = img.width;
		this.getHeight();
	}
};

PSRKMAP.legend_dropdown.prototype.getHeight = function(){

	var fully_loaded = true;
	this.legend_height = 0;
	this.legend_width = 0;
	for (var i=0; i < this.legend_images.length; i++){
	if(this.legend_images[i].img.parentNode.style.display=="block"){
		this.legend_height += this.legend_images[i].height+20;
		fully_loaded = (fully_loaded && this.legend_images[i].loaded);
		this.legend_width = Math.max(this.legend_width,this.legend_images[i].img.width);
	}
	}
	this.adjustHeight();
};

PSRKMAP.legend_dropdown.prototype.changeBasemapLegend = function(basemap){
	var legend_obj = this;
	for (var i=0; i < this.parent_obj.basemap_array.length; i++) {
		for (var j=0; j < this.parent_obj.basemap_array[i].bm.length; j++){
			if (this.basemaps[this.parent_obj.basemap_array[i].bm[j].path]){
				this.basemaps[this.parent_obj.basemap_array[i].bm[j].path].legend.style.display = (this.parent_obj.basemap_array[i].bm[j].path == basemap) ? "block" : "none";
			} else {
				if (this.parent_obj.basemap_array[i].bm[j].path == basemap && this.parent_obj.basemap_array[i].bm[j].legend_url){
				
					var legend = this.createLegend(legend_obj.parent_obj.basemap_array[i].bm[j].legend_title,"basemaps/"+legend_obj.parent_obj.basemap_array[i].bm[j].legend_url);

						this.basemaps_obj.appendChild(legend);
						this.basemaps[legend_obj.parent_obj.basemap_array[i].bm[j].path] = {legend:legend};
						this.basemaps_obj.style.display = "block";
						
				}
			}
		}
	}
	this.getHeight();
};

PSRKMAP.legend_dropdown.prototype.showOverlayLegend = function(overlay){
	var cur_overlay = null;
	var next_overlay = null;
	for (var i=0; i < this.parent_obj.overlay_array.length; i++) {
		for (var j=0; j < this.parent_obj.overlay_array[i].la.length; j++){
			if (this.overlays[this.parent_obj.overlay_array[i].la[j].path]){
				cur_overlay = this.overlays[this.parent_obj.overlay_array[i].la[j].path].legend;
				next_overlay = cur_overlay.nextSibling;
			}
			
			if (this.parent_obj.overlay_array[i].la[j].path == overlay && ( this.parent_obj.overlay_array[i].la[j].legend_url || this.parent_obj.overlay_array[i].la[j].poi )){
				if (this.parent_obj.overlay_array[i].la[j].poi){
					overlay = this.parent_obj.overlay_array[i].la[j].title;
				}
				if (this.overlays[overlay]){
					this.overlays[overlay].legend.style.display = "block";
					if (this.parent_obj.overlay_array[i].la[j].poi) {
						this.overlays[overlay].poi_count++;
					}
				}else{
					var legend = (this.parent_obj.overlay_array[i].la[j].poi) ?
									this.createLegend(this.parent_obj.overlay_array[i].la[j].legend_title,"legends/poi_" + this.parent_obj.overlay_array[i].la[j].marker_class + "_legend.png", true) :
									this.createLegend(this.parent_obj.overlay_array[i].la[j].legend_title,"overlays/" + this.parent_obj.overlay_array[i].la[j].legend_url);
					if (next_overlay){
						this.overlays_obj.insertBefore(legend,next_overlay);
					}else{
						this.overlays_obj.appendChild(legend);
					}
					this.overlays[overlay] = (this.parent_obj.overlay_array[i].la[j].poi) ? {legend:legend,poi_count:1} : {legend:legend};
					this.overlays_obj.style.display = "block";
				}
			} else {
				//alert("false: " + this.parent_obj.overlay_array[i].la[j].path + " ==? " + overlay)
			}
		}
	}
	this.getHeight();
};

PSRKMAP.legend_dropdown.prototype.hideOverlayLegend = function(overlay){

	if (this.overlays[overlay]){
		this.overlays[overlay].legend.style.display = "none";
	}else{
		for (var i=0; i < this.parent_obj.overlay_array.length; i++) {
			for (var j=0; j < this.parent_obj.overlay_array[i].la.length; j++){
				if (this.parent_obj.overlay_array[i].la[j].path == overlay && this.overlays[this.parent_obj.overlay_array[i].la[j].title] && this.parent_obj.overlay_array[i].la[j].poi){
					this.overlays[this.parent_obj.overlay_array[i].la[j].title].poi_count--;
					if (this.overlays[this.parent_obj.overlay_array[i].la[j].title].poi_count == 0){
						this.overlays[this.parent_obj.overlay_array[i].la[j].title].legend.style.display = "none";
					}
					break;
				}
			}
		}
	}
	this.getHeight();
};

PSRKMAP.legend_dropdown.prototype.toggleView = function(){

	this.show_legends = (!this.show_legends);
	if (!this.parent_obj.canvas.fullWidth){
		if (this.show_legends){
			this.legends_obj.style.display = "block";
			this.getHeight();
			this.closer_obj.className = "report_closer";	
			this.header_obj.onclick = null;
			this.header_obj.style.cursor = "default";
			
		}else{
			this.legends_obj.style.display = "none";
			this.getHeight();
			this.closer_obj.className = "report_closer pull_down";
			var legend_obj = this;
			this.header_obj.onclick = function(){
				legend_obj.toggleView()
			}
			this.header_obj.style.cursor = "pointer";
		}
	}else{
		if (this.show_legends){
			this.obj.style.display = "block";
			this.getHeight();	
			this.parent_obj.toolbar_legends.className = "active";
		}else{
			this.obj.style.display = "none";
			this.parent_obj.toolbar_legends.className = "";
		}
	}

	var status = (this.show_legends) ? 0 : 1;
	var url = "/mason/Reports2/customize_item.html?application=psharkmap&deselect_displaylegend="+status;
	var pajax = new psharkmapAJAXobj();
	pajax.setURL(url);
	pajax.sendRequest();
	return false;
};



PSRKMAP.linkLegends = function(){
	if (!PSRKMAP.active_map.legenddropdown_obj.show_legends){
		PSRKMAP.active_map.legenddropdown_obj.toggleView();
		PSRKMAP.active_map.legenddropdown_obj.adjustHeight();
		
	}
	PSRKMAP.active_map.hideReport();
	PSRKMAP.active_map.toolbar_legends.className = "active";
}


//  library section

// psharkmap member functions

psharkmap.prototype.getOptionElement = function(v, t, c){
	var option_obj = document.createElement("option");
	option_obj.setAttribute('value',v);
  	var txt = document.createTextNode(t);
	if (v==c){
		option_obj.setAttribute("selected","selected");
	}
  	option_obj.appendChild(txt)
	return option_obj;
};

psharkmap.prototype.getHElement = function(h, t, wrap){
	var h_obj = document.createElement(h);
	var txt = document.createTextNode(t);
	if (wrap){
		var w = document.createElement(wrap)
		w.appendChild(txt);
		h_obj.appendChild(w);
	}else{
		h_obj.appendChild(txt);
	}
	return h_obj;
};

psharkmap.prototype.getLabelElement = function(f, t, i, s){
	var label_obj;
	try{
		label_obj = document.createElement('<label for="'+f+'"></label>');
	}catch(err){
		label_obj = document.createElement("label");
		label_obj.setAttribute("for",f);
	}

	if (i){
		img = document.createElement("img");
		img.src = i;
		img.style.height = "12px";
		img.style.width = "12px";
		label_obj.appendChild(img);
	}
	var txt = document.createTextNode(t);
	label_obj.appendChild(txt);
	if(s){
		var sup = this.cE("span",label_obj);
		sup.innerHTML = s;
		sup.className = "sup";
	}
	return label_obj;
};

psharkmap.prototype.getCheckboxElement = function(v, t, c, id){
	
	var checkbox_obj;
	
	try{
		if (c){
			checkbox_obj = document.createElement('<input type="checkbox" name="'+id+'" checked="checked" />');
		}else{
			checkbox_obj = document.createElement('<input type="checkbox" name="'+id+'" />');
		}
	}catch(err){
		checkbox_obj = document.createElement('input');
		checkbox_obj.setAttribute('type','checkbox');
		checkbox_obj.setAttribute('name',id);
	}

	checkbox_obj.setAttribute('value',v);
	checkbox_obj.setAttribute('id',id);
  	var txt = document.createTextNode(t);
	if (c){
		checkbox_obj.setAttribute("checked","checked");
	}
	return checkbox_obj;
};

psharkmap.prototype.getRadioElement = function(v, t, c, id, name){
	
	var radio_obj;
	
	try{
		if (c){
			radio_obj = document.createElement('<input type="radio" name="'+name+'" value="'+v+'" id="'+id+'" checked="checked" />');
		}else{
			radio_obj = document.createElement('<input type="radio" name="'+name+'" value="'+v+'" id="'+id+'" />');
		}
	}catch(err){
		radio_obj = document.createElement('input');
		radio_obj.setAttribute('type','radio');
		radio_obj.setAttribute('name',name);
		radio_obj.setAttribute('value',v);
		radio_obj.setAttribute('id',id);
	
		if (c){
			radio_obj.setAttribute("checked","checked");
		}
	
	}
	
	return radio_obj;
};

psharkmap.prototype.getLoader = function(c,t){
	var loader = document.createElement("span")
	loader.className = c + "_loader";
	var txt = document.createTextNode(t);
	loader.appendChild(txt);
	return loader;
};
	
psharkmap.prototype.getAvailDim = function(){
	var availWidth = 0;
	var availHeight = 0;
	if( typeof( PSRKMAP.innerWidth ) == 'number' ) { //Non-IE
		availWidth = PSRKMAP.innerWidth;
		availHeight = PSRKMAP.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode'
		availWidth = document.documentElement.clientWidth;
		availHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible
		availWidth = document.body.clientWidth;
		availHeight = document.body.clientHeight;
	}
	return new Array(availWidth-this.canvas.left_offset-this.canvas.right_offset,availHeight);
};

psharkmap.prototype.getPos = function(elm){
	var left = elm.offsetLeft;
	var top = elm.offsetTop;
	while((elm = elm.offsetParent) != null)
	{
		left += elm.offsetLeft;
		top += elm.offsetTop;
	}
	return new Array(left,top);
};

psharkmap.prototype.getEventPosObj = function(){
	var e = arguments[0];
	if(!e) e = window.event;

	var posx = 0;
	var posy = 0;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	} else if (e.clientX || e.clientY) {
		posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	
	var event_pos_obj = new Array();
	event_pos_obj.x = posx;
	event_pos_obj.y = posy;
	
	
	return event_pos_obj;
};

psharkmap.prototype.xPxOffsetToCoordCenter = function(x){
	return (x+(this.map.width/2))/(this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size);
};

psharkmap.prototype.yPxOffsetToCoordCenter = function(y){
	return (y+(this.map.height/2))/(this.zoomlevel_array[this.current_zoom].y_tiles*this.zoomlevel_array[this.current_zoom].y_tile_size);
};

psharkmap.prototype.xCoordCenterToPxOffset = function(x){
	return parseInt((x*this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size)-(this.map.width/2));
};

psharkmap.prototype.yCoordCenterToPxOffset = function(y){
	return parseInt((y*this.zoomlevel_array[this.current_zoom].y_tiles*this.zoomlevel_array[this.current_zoom].y_tile_size)-(this.map.height/2));
};

psharkmap.prototype.xPxToCoord = function(x){
	return x/(this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size);
};

psharkmap.prototype.yPxToCoord = function(y){
	return y/(this.zoomlevel_array[this.current_zoom].y_tiles*this.zoomlevel_array[this.current_zoom].y_tile_size);
};

psharkmap.prototype.coordToXPx = function(x){
	return x*(this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size);
};

psharkmap.prototype.coordToYPx = function(y){
	return y*(this.zoomlevel_array[this.current_zoom].y_tiles*this.zoomlevel_array[this.current_zoom].y_tile_size);
};
	
psharkmap.prototype.getRemoteContent = function(url, obj, call_back, fn, arg1, arg2, arg2, arg3, arg4, arg5){
	call_back = (call_back) ? call_back : null;
	fn = fn ? fn : null;
	
	var id = "generic"
	
	var method = "GET";
	var call_back_elm = ""
	
	var map_obj = this;
	
	if (!obj) obj = PSRKMAP$(obj);
	
	
	
	if (obj && !fn && arg1 || fn && arg1){
		id = arg1; 
	}
	

		this.xmlhttp[id]=false;
		
		/* for Internet Explorer */
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		try {
			this.xmlhttp[id] = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				this.xmlhttp[id] = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				this.xmlhttp[id] = false;
			}
		}
		@end @*/
	
		if (!this.xmlhttp[id] && typeof XMLHttpRequest != 'undefined') {
			this.xmlhttp[id] = new XMLHttpRequest();
		}

	
	if (call_back){
		call_back_elm = "<img src=\""+this.path+"/clear.gif\" onload=\""+call_back+";this.parentNode.removeChild(this);\" />";
	}
	
	this.xmlhttp[id].open(method, url);
	this.xmlhttp[id].onreadystatechange = function() {
		if (map_obj.xmlhttp[id].readyState == 4 && map_obj.xmlhttp[id].status == 200) {
			if (obj){
				if (fn){
					obj.innerHTML = fn(map_obj.xmlhttp[id].responseText,arg1,arg2,arg3,arg4,arg5) + call_back_elm;
				}else{
					obj.innerHTML = map_obj.xmlhttp[id].responseText + call_back_elm;
				}
			}else{
				if (fn){
					fn(map_obj.xmlhttp[id].responseText,arg1,arg2,arg3,arg4,arg5);
				}else{
					if (call_back){
						call_back();
					}		
				}
			}
		}
		if (map_obj.xmlhttp[id].readyState == 4 && map_obj.xmlhttp[id].status == 404) {
			alert("Sorry, but we had a problem finding " + url);
		}
	}
	this.xmlhttp[id].send(null);
};				

psharkmap.prototype.setView = function(){
	if (!this.position_from_url){
		return false;
	}else{
		window.location.hash = this.getView();
		this.setViewCookie();
	}
};

psharkmap.prototype.getView = function(){
	var zoom = this.current_zoom;
	var x = this.xPxOffsetToCoordCenter(this.map_offset_x);
	var y = this.yPxOffsetToCoordCenter(this.map_offset_y);
	var map = this.locale;
	var basemap = this.current_basemap.replace(this.locale+"/","");
	var overlays = this.current_overlays;
	var overlay = "";
	var poi = "";
	for (var i=0; i < this.current_overlays.length; i++){
		if (this.isPOI(this.current_overlays[i])){
		//	if (poi != "") poi += ",";
		//	poi += this.current_overlays[i].replace(this.locale+"/","");
		}else{
			if (overlay != "") overlay += ",";
			overlay += this.current_overlays[i].replace(this.locale+"/","");
		}
	}
	for (var i=0; i < this.current_pois.length; i++){
		if (poi != "") poi += ",";
		poi += this.current_pois[i].replace(this.locale+"/","");
	}
	
	var hash = "";
							
	var hash="map="+map;
	hash += (x) ? "&x="+x : "&x=0.5";
	hash += (y) ? "&y="+y : "&y=0.5";
	hash += "&zoom="+zoom+"&basemap="+basemap;
	if (overlay != "") hash += "&overlay="+overlay;
	if (poi != "") hash += "&poi="+poi;
	if (this.map.report.is_showing == 1){
		hash += "&report=1";
		if (this.map.focusarea.x && this.map.focusarea.y){
			hash += "&ax="+this.map.focusarea.x;
			hash += "&ay="+this.map.focusarea.y;
		}
	}
	 
	if (this.map.focusarea.show == 1){
		hash += "&star=1";
	}

	
	for (var i = 0; i < this.search_results.length; i++){
		if (this.search_results[i].marker){
			hash += "&marker="+this.search_results[i].x+","+this.search_results[i].y+","+this.search_results[i].address;
		}
	}
	
	hash += "&tab="+this.current_menu_tab_name;
	
	if (this.alt_host){
		hash += "&host="+this.tile_server.replace("http://","");
	}
	if (this.variant){
		hash += "&variant="+this.variant;
	}
	return hash;
};

psharkmap.prototype.getForCopy = function(){
	var zoom = this.current_zoom;
	var x = this.xPxOffsetToCoordCenter(this.map_offset_x);
	var y = this.yPxOffsetToCoordCenter(this.map_offset_y);
	var map = this.locale;
	var basemap = this.current_basemap.replace(this.locale+"/","");
	var overlays = this.current_overlays;

	var hash = "";
							
	var hash="map="+map+"&x="+x+"&y="+y+"&z="+zoom+"&basemap="+basemap;
	
	for (var i=0; i < this.current_overlays.length; i++){
		if (this.isOverlay(this.current_overlays[i])){
			hash += "&layer=" + this.current_overlays[i].replace(this.locale+"/","");
		}
	}
	
	return hash;
};

psharkmap.prototype.setViewCookie = function(){
	var mapstate = this.locale+","+this.current_basemap+","+this.current_overlays.join(" ")+","+this.xPxOffsetToCoordCenter(this.map_offset_x)+","+this.yPxOffsetToCoordCenter(this.map_offset_y)+","+this.current_zoom;
	this.SetCookie("mapstate",mapstate,null,"/");
};

psharkmap.prototype.getScrollerWidth = function() {

	var scr = null;
	var inn = null;
	var wNoScroll = 0;
	var wScroll = 0;

	// Outer scrolling div
	scr = document.createElement('div');
	scr.style.position = 'absolute';
	scr.style.top = '-1000px';
	scr.style.left = '-1000px';
	scr.style.width = '100px';
	scr.style.height = '50px';
	// Start with no scrollbar
	scr.style.overflow = 'hidden';

	// Inner content div
	inn = document.createElement('div');
	inn.style.width = '100%';
	inn.style.height = '200px';

	// Put the inner div in the scrolling div
	scr.appendChild(inn);
	// Append the scrolling div to the doc
	document.body.appendChild(scr);

	// Width of the inner div sans scrollbar
	wNoScroll = inn.offsetWidth;
	// Add the scrollbar
	scr.style.overflow = 'auto';
	// Width of the inner div width scrollbar
	wScroll = inn.offsetWidth;

	// Remove the scrolling div from the doc
	document.body.removeChild(
		document.body.lastChild);

	// Pixel width of the scroller
	// return (wNoScroll - wScroll);
	return 17;
};

psharkmap.prototype.setStyles = function(obj,style_obj){
	if (!obj){
		return false;
	}
	for (var s in style_obj){
		obj.style[s] = style_obj[s];
	}
};

psharkmap.prototype.cE = function(o,p){
	var el = document.createElement(o);
	if (p){
		p.appendChild(el);
	}
	return el;
};

psharkmap.prototype.getCanvasElement = function(width, height, id){
	// new canvas element
	var canvasElem = document.createElement('canvas');
	document.body.appendChild(canvasElem);
	// if it is IE...
	if (typeof G_vmlCanvasManager != 'undefined') {
		// you've to reassign the variable to the new element created by initElement
		canvasElem = G_vmlCanvasManager.initElement(canvasElem);
	}
	return canvasElem;
};

// global functions and objects


		Array.prototype.inArray = function (value)
// Returns true if the passed value is found in the
// array.  Returns false if it is not.
{
	var i;
	for (var i=0; i < this.length; i++) {
		// Matches identical (===), not just similar (==).
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};	

Array.prototype.removeValue = function (value)
// Removes value if the passed value is found in the
// array.  Returns true if found, false if it is not.
{
	var i;
	var found = 0;
	var len = this.length;
	var str = "try to remove: " + value + "\n\nfrom:\n";
	for (var i=0; i < this.length; i++) {
		str+=this[i]+"\n";
	} 
	for (var i=0; i < this.length; i++) {
		if (found) {
			this[i-found] = this[i];
		}
		// Matches identical (===), not just similar (==).
		if (this[i] == value) {
			found++;
		}
	}
	if (found){
		for (var i=0;i < found;i++) this.pop();
		return true;
	}
	return false;
};

function setView(){
	if (!PSRKMAP.active_map)return false;
	PSRKMAP.active_map.setView();
};

function abs(n){
	if (n<0) return -n;
	return n;
}
function _alert(str){
	alert(str);
}

function purge(d) {
	var a = d.attributes, i, l, n;
	if (a) {
		l = a.length;
		for (i = 0; i < l; i += 1) {
			n = a[i].name;
			if (typeof d[n] === 'function') {
				d[n] = null;
			}
		}
	}
	a = d.childNodes;
	if (a) {
		l = a.length;
		for (i = 0; i < l; i += 1) {
			purge(d.childNodes[i]);
		}
	}
}

PSRKMAP.getMap = function(id){
	for (var i=0; i < PSRKMAP.arr_mapobjects.length; i++){
		if (PSRKMAP.arr_mapobjects[i].psharkmap_id == id){
			return PSRKMAP.arr_mapobjects[i];
		}
	}
}

// ********************
// custom AJAX object
// ********************

function psharkmapAJAXobj(){
	this.url = null;
	this.target_obj = null;
	this.target_obj_id = null;
	this.target_function = null;
	this.call_back_function = null;
	this.method = "GET";
	this.call_back_obj = "";
	this.call_back_img = "/maps/psharkmap/clear.gif";
	this.parent_obj = null;
	this.function_args = [];
	this.xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");

}
	
psharkmapAJAXobj.prototype.setURL = function(url){ this.url = url; };
psharkmapAJAXobj.prototype.setTargetObj = function(obj){ this.target_obj = obj; };
psharkmapAJAXobj.prototype.setTargetObjById = function(id){ this.target_obj = PSRKMAP$(id); };
psharkmapAJAXobj.prototype.setTargetFunction = function(fn){ this.target_function = fn; };
psharkmapAJAXobj.prototype.setCallBackFunction = function(fn){ this.call_back_function = fn; };
psharkmapAJAXobj.prototype.setMethod = function(m){ this.method = m; };
psharkmapAJAXobj.prototype.setParentObj = function(obj){ this.parent_obj = obj; };
psharkmapAJAXobj.prototype.pushFunctionArg = function(arg){ this.function_args.push(arg); };


psharkmapAJAXobj.prototype.sendRequest = function(){
	if (!this.url ){
		alert("Error, no url specified for AJAX request");
		return;
	}
 
	var call_back_elm = "";
	if (this.call_back_function){
		call_back_elm = "<img src=\""+this.call_back_img+"\" onload=\""+this.call_back_function+";this.parentNode.removeChild(this);\" />";
	}
	
	var ajax_obj = this;
	
	this.xmlhttp.open(this.method, this.url);
	this.xmlhttp.onreadystatechange = function() {
		if (ajax_obj.xmlhttp.readyState == 4 && ajax_obj.xmlhttp.status == 200) {
			if (ajax_obj.target_obj){
				if (ajax_obj.target_function){
					ajax_obj.target_obj.innerHTML = ajax_obj.target_function(ajax_obj.xmlhttp.responseText, ajax_obj.function_args[0], ajax_obj.function_args[1], ajax_obj.function_args[2], ajax_obj.function_args[3], ajax_obj.function_args[4], ajax_obj.function_args[5], ajax_obj.function_args[6], ajax_obj.function_args[7], ajax_obj.function_args[8], ajax_obj.function_args[9]) + call_back_elm;
				}else{
					ajax_obj.target_obj.innerHTML = ajax_obj.xmlhttp.responseText + call_back_elm;
				}
			}else{
				if (ajax_obj.target_function){
					ajax_obj.target_function(ajax_obj.xmlhttp.responseText, ajax_obj.function_args[0], ajax_obj.function_args[1], ajax_obj.function_args[2], ajax_obj.function_args[3], ajax_obj.function_args[4], ajax_obj.function_args[5], ajax_obj.function_args[6], ajax_obj.function_args[7], ajax_obj.function_args[8], ajax_obj.function_args[9]);
				}else{
					if (ajax_obj.call_back_function){
						ajax_obj.call_back_function();
					}		
				}
			}
		}
		if (ajax_obj.xmlhttp.readyState == 4 && ajax_obj.xmlhttp.status == 404) {
			alert("Sorry, but we had a problem finding " + ajax_obj.url);
		}
	}
	this.xmlhttp.send(null);
};

function PSRKMAP$(i) {
	return document.getElementById(i);
}

//  map section

// psharkmap member functions

psharkmap.prototype.paintMapPanel =  function(){
	var map_obj = this;
 		

	if (!this.map.obj){
  	this.map.obj = document.createElement("div");
	
	/* Initialize scroll wheel code. */
	if (window.addEventListener){
		this.map.obj.addEventListener('DOMMouseScroll', wheel, false);
	}
	this.map.obj.onmousewheel = wheel;
	
	
  	this.setZoomClass();
  	this.canvas.obj.appendChild(this.map.obj);
			
  	this.map.obj.onmousedown = function(){
		map_obj.mousedown(arguments[0]);
		if (map_obj.mode == "geopicker" && map_obj.map.feature.no_tiles){
			map_obj.map.feature.activated_mouse_listener = true;
			return;
		}
  		map_obj.setMapCursorDown();

		PSRKMAP.mouseisdown = true;
		map_obj.mousedowntimer = setTimeout(map_obj.cancelMouseDown, "500");
  	};
  	
	this.map.obj.onmouseup = function(){
  		map_obj.setMapCursor();
			if (map_obj.mode == "geopicker" && map_obj.map.feature.activated_mouse_listener && map_obj.map.feature.no_tiles ){
				var e = arguments[0];
				if(!e) e = window.event;
				if(e.button <= 1 && !e.shiftKey){
				if (map_obj.map.feature.dbl_click){
					clearTimeout(map_obj.map.feature.mouseuptimer);
					map_obj.map.feature.dbl_click = false;
					map_obj.doubleclick(arguments[0]);
				}else{
					map_obj.map.feature.dbl_click = true;
					map_obj.map.feature.mouseuptimer = setTimeout(function(){
						map_obj.getAvailableFeatures();
						map_obj.map.feature.dbl_click = false;
					},"350");
				}
				}
				return;
			}

			if (map_obj.mode == "zoom" && (map_obj.zoomlevel_array.length - 1) > map_obj.current_zoom && PSRKMAP.mouseisdown){
				if (!PSRKMAP.dragging && PSRKMAP.dblclicking){
					map_obj.doubleclick(arguments[0]);
					PSRKMAP.dblclicking = false;
					clearTimeout(map_obj.dblTimer);
				}else{
					if (PSRKMAP.dblclick_ready){
						PSRKMAP.dblclicking = true;
						map_obj.dblTimer = setTimeout(map_obj.cancelDBLClicking,"500");
					}
					PSRKMAP.dblclick_ready = true;
				}
			}
			if (map_obj.mode == "polygon" && !PSRKMAP.dragging && PSRKMAP.drag_ready && map_obj.polygonpanel_obj){
				if (map_obj.mode == "polygon" && !PSRKMAP.drag_polygon_point){
					if (!PSRKMAP.drawing_polygon && map_obj.polygonpanel_obj.polygon_array.length>0 && !map_obj.polygonpanel_obj.polygon_mode){
						return;
					}
					if (!PSRKMAP.drawing_polygon){
						PSRKMAP.drawing_polygon = true;
						map_obj.polygonpanel_obj.clearPolygon();
					}
					map_obj.polygonpanel_obj.placeVertex();
				}
			}
		};
		this.map.obj.onmouseover = function(){
			map_obj.setMapCursor();
		};
		this.map.obj.ondblclick = function(){
		};
		this.map.obj.oncontextmenu = function(){return false};
		this.map.obj.onselectstart = function(){return false};
	}
	 


	this.positionMap();
	this.map.obj.style.overflow = "hidden";
	this.setMapCursor();


	if (!this.map.root){
		this.map.root = document.createElement("div");
		this.map.root.id="map_root";
		this.map.root.style.position="absolute";
		this.map.root.style.top = 0;
		this.map.root.style.left = 0;
		this.map.root.style.display = "none";
		this.map.root.style.backgroundImage = "url('/img/jk/loadingmap.gif')";
		this.map.root.style.width = this.zoomlevel_array[this.zoomlevel_array.length-1].x_tiles * this.zoomlevel_array[this.zoomlevel_array.length-1].x_tile_size + "px";
		this.map.root.style.height = this.zoomlevel_array[this.zoomlevel_array.length-1].y_tiles * this.zoomlevel_array[this.zoomlevel_array.length-1].y_tile_size + "px";
		this.map.obj.appendChild(this.map.root);
	}
};

psharkmap.prototype.getMapWidth = function(){
	var map_width = 0;
	if (this.canvas.hasControlPanel){
		if (this.canvas.fullWidth){
			map_width = this.canvas.width - this.control.width - this.canvas.borderRightWidth - this.canvas.borderLeftWidth;
		}else{
			map_width = this.canvas.width - this.control.width - 3 * this.canvas.borderWidth;
		}
	}else{
		if (this.canvas.border_width_user_set){
			map_width = this.canvas.width;
		}else{
			map_width = this.canvas.width-2*this.canvas.borderWidth;
		}
	}
	if (this.canvas.hasControlPanel && map_width < this.map.minWidth){
		this.canvas.roomforControlPanel =  0;
		map_width = this.canvas.width;
	}else{
		this.canvas.roomforControlPanel =  1;
	} 
	if (!this.canvas.displayControlPanel){
		map_width = this.canvas.width;
	}
	return map_width;
};

psharkmap.prototype.getMapHeight = function(){
	var map_height = 0;
	if (this.show_copyright){
		if (this.canvas.border_width_user_set){
			map_height = this.canvas.height - this.tools.copyright.obj.offsetHeight;
		}else{
			map_height = this.canvas.height - this.tools.copyright.obj.offsetHeight;
		}
		if (this.canvas.set_in_layout){
			map_height -= this.toolbar.offsetHeight;
		}
	}else{
		map_height = this.canvas.height;
	}
	return map_height;
};

psharkmap.prototype.cancelDBLClicking = function(){
	var map_obj = PSRKMAP.active_map;
	PSRKMAP.dblclicking = false;
	
	if (map_obj.mode == "polygon"){
		return;
	}
	
	PSRKMAP.centerMapPanel(map_obj.xPxToCoord(map_obj.mousedown_x+map_obj.map_offset_x),map_obj.yPxToCoord(map_obj.mousedown_y+map_obj.map_offset_y));
};

psharkmap.prototype.dblClickNotReady = function(){
	PSRKMAP.dblclick_ready = true;
};

psharkmap.prototype.cancelMouseDown = function(){
	PSRKMAP.mouseisdown = false;
};

psharkmap.prototype.suspendClick = function(n){
	if (!n){
		n = "500";
	}
	var map_obj = this;
	PSRKMAP.dblclicking = false;
	PSRKMAP.dblclick_ready = false;
	clearTimeout(map_obj.dblTimer);
	clearTimeout(map_obj.dblClickReadyTimer);
	this.dblClickReadyTimer = setTimeout(map_obj.dblClickNotReady,n);
};

psharkmap.prototype.positionMap = function(){
	if(this.map.obj){

 	this.map.width = this.getMapWidth();
	this.map.height = this.getMapHeight();
   
	this.map.obj.style.width = this.map.width + "px";
	this.map.obj.style.height = this.map.height + "px";
	this.map.obj.style.position = "absolute";

		this.map.obj.style.border = this.canvas.borderWidth + "px " + this.canvas.borderStyle + " " + this.canvas.borderColor;
		this.map.obj.style.borderWidth = this.canvas.borderTopWidth + "px " + this.canvas.borderRightWidth + "px " + this.canvas.borderBottomWidth + "px " + this.canvas.borderLeftWidth + "px";

		if (!this.map.relative || this.canvas.border_width_user_set){
			this.map.obj.style.left = (document.all && !this.canvas.fullWidth) ? this.getPos(this.canvas.obj)[0] + "px" :  this.getPos(this.canvas.obj)[0] + "px";
			this.map.obj.style.top = (document.all && !this.canvas.fullHeight) ? this.getPos(this.canvas.obj)[1] + "px" :  this.getPos(this.canvas.obj)[1] + "px";
		}
	}
};

psharkmap.prototype.clearMap = function(){
	this.clearBaseMapLayer();
	this.clearOverlayLayers();
};
	
psharkmap.prototype.loadMapPanel = function(){
	var map_obj = this;
	if (!this.map_placed){
		if (!isNaN(this.map_coord_center_x) && !isNaN(this.map_coord_center_x)){
			this.map_offset_x = this.xCoordCenterToPxOffset(this.map_coord_center_x);
			this.map_offset_y = this.yCoordCenterToPxOffset(this.map_coord_center_y);
		}else{
		// we don't have the map placed yet, so let's center it
			this.map_offset_x = parseInt((this.zoomlevel_array[this.current_zoom].x_tiles * this.zoomlevel_array[this.current_zoom].x_tile_size - this.map.width)/2,10);
			this.map_offset_y = parseInt((this.zoomlevel_array[this.current_zoom].y_tiles * this.zoomlevel_array[this.current_zoom].y_tile_size - this.map.height)/2,10);
		}
		this.map_placed = true;
	}

	// get the corner tiles
	this.left_tile_n = Math.floor(this.map_offset_x/this.zoomlevel_array[this.current_zoom].x_tile_size);
	this.right_tile_n = Math.ceil((this.map_offset_x+this.map.width)/this.zoomlevel_array[this.current_zoom].x_tile_size);

	this.top_tile_n = Math.floor(this.map_offset_y/this.zoomlevel_array[this.current_zoom].y_tile_size);
	this.bottom_tile_n = Math.ceil((this.map_offset_y+this.map.height)/this.zoomlevel_array[this.current_zoom].y_tile_size);

			
	if (this.map.base_map_layer){
		// load tiles
			
		this.map_offset_x = Math.min(this.zoomlevel_array[this.current_zoom].x_tiles * this.zoomlevel_array[this.current_zoom].x_tile_size - this.map.width,this.map_offset_x);
		this.map_offset_y = Math.min(this.zoomlevel_array[this.current_zoom].y_tiles * this.zoomlevel_array[this.current_zoom].y_tile_size - this.map.height,this.map_offset_y);
		
		this.map_offset_x = Math.max(0,this.map_offset_x);
		this.map_offset_y = Math.max(0,this.map_offset_y);
			
		this.map.root.style.left = -this.map_offset_x+"px";
		this.map.root.style.top = -this.map_offset_y+"px";

		if (this.do_smooth_zoom){
			if (this.previous_zoom>=0 && this.previous_zoom < this.current_zoom && this.previous_zoom >= this.current_zoom-2){
				if (!this.zooming){
					this.zooming=true;
					this.setZoomMapLayer(this.previous_zoom,this.current_zoom,this.old_map_offset_x,this.old_map_offset_y);
					this.clearMap();
				}
			}
			this.do_smooth_zoom = false;
		}

		if (!this.zooming){
			this.map.base_map_layer.style.display="block";
		}
		
		clearTimeout(this.tile_queue_timer);
		this.loadBasemaps();
		if (!PSRKMAP.dragging){
			this.loadOverlays();
		}
		this.tile_queue_timer = window.setTimeout(function () { map_obj.purgeTileQueue(); }, 5000);
	
	}

	this.setKeyMapView();
	if(this.map.root){
		this.map.root.style.display = "block";
	}
};
	
psharkmap.prototype.loadBasemaps = function () {
	for (var x = Math.max(this.left_tile_n,0); x <= Math.min(this.right_tile_n,this.zoomlevel_array[this.current_zoom].x_tiles-1); x++){
		for (var y = Math.max(this.top_tile_n,0); y <= Math.min(this.bottom_tile_n,this.zoomlevel_array[this.current_zoom].y_tiles-1); y++){
			var d = -1;
			var img_id = this.map_id+"-"+this.current_basemap.replace("_","").replace("/","")+"-i_"+this.current_zoom+"_"+d+"_"+x+"_"+y;
			
			if (!this.basemap_tile_queue.inArray(img_id)){
				var loadedImg = PSRKMAP$(img_id);
				if (!loadedImg || (loadedImg && !loadedImg.className == "loaded") || (loadedImg && loadedImg.style.visibility == "hidden")){
					// don't generate images that were already loaded
					if (this.updateViewCount()){
						this.basemap_tile_queue.push(img_id);
						img = this.generateImg(x,y,d,this.current_basemap,this.current_zoom)
					}else{
						return;
					}
				}else{
					if (loadedImg && loadedImg.className == "zoom"){
						img = this.placeImg(x,y,loadedImg);
					}
				}
			}else{
			}
		}
	}
};
	
psharkmap.prototype.getOverlaysArray = function(){
	str = ""
	for (var i=0; i < this.overlay_array.length; i++) {
		for (var j=0; j < this.overlay_array[i].la.length; j++){
			str += "this.overlay_array["+i+"].la["+j+"].name = " + this.overlay_array[i].la[j].name + "\n";
		}
	}
	return str;
};
	
psharkmap.prototype.loadOverlays = function () {
	//alert(this.getOverlaysArray())
	if (this.view_locked || this.current_overlays.length+this.current_pois.length==0){
		return;
	}
	for (var i=0; i < this.overlay_array.length; i++) {
		for (var j=0; j < this.overlay_array[i].la.length; j++){		
			if (this.current_overlays.inArray(this.overlay_array[i].la[j].path)||this.current_pois.inArray(this.overlay_array[i].la[j].path)){
				var d = this.overlay_array[i].la[j].d;
				if(this.overlay_array[i].la[j].poi){
					if (this.overlay_array[i].la[j].external && !this.overlay_array[i].la[j].loaded){
						this.loadExternalPOI(i,j,d);
					}else{
						if (this.overlay_array[i].la[j].placed != this.current_zoom){
							this.placePOIMarkers(d,i,j);
						}
					}
				}else{
					for (var x = Math.max(this.left_tile_n,0); x <= Math.min(this.right_tile_n,this.zoomlevel_array[this.current_zoom].x_tiles-1); x++){
						for (var y = Math.max(this.top_tile_n,0); y <= Math.min(this.bottom_tile_n,this.zoomlevel_array[this.current_zoom].y_tiles-1); y++){
							
							var img_id = this.map_id+"-i_"+this.current_zoom+"_"+d+"_"+x+"_"+y;
							if (!this.overlay_tile_queue[d].inArray(img_id)){
								var loadedImg = PSRKMAP$(img_id);
								if (!loadedImg || (loadedImg && !loadedImg.className == "loaded") || (loadedImg && loadedImg.style.visibility == "hidden")){
									// don't generate images that were already loaded
									img = this.generateImg(x,y,d,this.overlay_array[i].la[j].path,this.current_zoom)
								}
							}
						}
					}
				}
			}
		}
	}
//	if (this.map.feature.json_tiles){
//		if (this.canvaslayers || true){
//			this.loadCanvasLayers();
//		}
//	}
};
	
	
psharkmap.prototype.generateImg = function(x,y,d,d_path,z){

	var map_obj = this;
	x = parseInt(x);
	y = parseInt(y);
	d = parseInt(d);
	z = parseInt(z);
	
	var path;
	
	if (!d_path)return;

	if (x>=0 && y>=0 && x<this.zoomlevel_array[this.current_zoom].x_tiles && y<this.zoomlevel_array[this.current_zoom].y_tiles){
		var img = document.createElement("img");

		if (d >= 0){
		//	return
			path = this.getPathToLayer(d_path,this.current_zoom,x,y);
			
			
			if (window.XMLHttpRequest){
				img.src = path;
			}else{
				img.src=this.path+"clear.gif";
				img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'"+path+"\', sizingMethod=\'scale\')"
			}
		}else{
			path = this.getPathToImg(this.locale,d_path,this.current_zoom,x,y);
			img.setAttribute("src" ,path);
			img.path = d_path;
		}
		
		img.className = "loading";
		img.id = this.map_id+"-"+d_path.replace("_","").replace("/","")+"-i_"+z+"_"+d+"_"+x+"_"+y
		img.setAttribute("galleryimg","no");
		img.style.position="absolute";
		if (window.XMLHttpRequest)img.style.visibility = "hidden";
		
		img.style.width=this.zoomlevel_array[this.current_zoom].x_tile_size+"px";
		img.style.height=this.zoomlevel_array[this.current_zoom].y_tile_size+"px";
		img.style.top=y*this.zoomlevel_array[this.current_zoom].y_tile_size+"px";
		img.style.left=x*this.zoomlevel_array[this.current_zoom].x_tile_size+"px";
		
		img.setAttribute("alt" ,"");
		
		if (d >= 0){
			if (!this.map.overlays[d]){
				return;
			}
		
			this.map.overlays[d].obj.appendChild(img);
		
			img.onload = function(){
				map_obj.loadOverlayImg(this,d);
			};
			if (img.complete){
				this.loadOverlayImg(img,d);
			}
			img.onerror = function(){
				if (this.parentNode){
					this.parentNode.removeChild(this);
				}else{
					this.id="";
				}
				map_obj.overlay_tile_queue.removeValue(this.id);
			};
		}else{
		
			this.map.load_layer.appendChild(img);
		
			img.onload = function(){
				map_obj.loadBasemapImg(this);
			};
			if (img.complete){
				this.loadBasemapImg(img);
			}
			
			img.onerror = function(){
				if (this.parentNode){
					this.parentNode.removeChild(this);
				}else{
					this.id="";
				}
				map_obj.basemap_tile_queue.removeValue(this.id);
			};
		}
		

		img.onmousedown = function(){
			return false;
		};

		img.onmouseup = function(){
			PSRKMAP.mouseup(arguments[0],true);
		};
		img.onmousemove = PSRKMAP.mousemove;
		return img;
	}else{
		return false;
	}		
};
	
psharkmap.prototype.placeImg = function(x, y, img){

	var x = parseInt(x,10);
	var y = parseInt(y,10);
	
	img.style.width=this.zoomlevel_array[this.current_zoom].x_tile_size+"px";
	img.style.height=this.zoomlevel_array[this.current_zoom].y_tile_size+"px";
	img.style.top=y*this.zoomlevel_array[this.current_zoom].y_tile_size+"px";
	img.style.left=x*this.zoomlevel_array[this.current_zoom].x_tile_size+"px";
	img.className = "loaded";
	this.loadBasemapImg(img);
};
	
psharkmap.prototype.loadBasemapImg = function(img){
	img.className = "loaded";
	img.style.backgroundColor = "#fff";
	img.style.visibility = "visible";
	if (img.path == this.current_basemap){
		this.map.base_map_layer.appendChild(img);
	}else{
		if (img){
			try{
				this.map.load_layer.removeChild(img);
			}
			catch(err){
			}
		}
	}
	this.basemap_tile_queue.removeValue(img.id);
};

psharkmap.prototype.loadOverlayImg = function(img,d){
	img.className = "loaded";
	img.style.visibility = "visible";
	this.map.overlays[d].obj.appendChild(img);
	this.overlay_tile_queue[d].removeValue(img.id);
};

psharkmap.prototype.getPathToImg = function(locale, path, z, x, y){

	if (this.use_default_tiles){
		path = this.locale+"/default"
	}
	
	// Assume that the args are already ints
	// Jens 12/29/08
	// z = parseInt(z,10);
	// x = parseInt(x,10);
	// y = parseInt(y,10);
	
	if (this.use_local)return this.path + "tiles/tile" + parseInt(Math.random()*16) + ".png";
	
	return this.tile_server+"/map_"+path.replace('/','_')+"_"+z+"_"+x+"_"+y+".png";
};

psharkmap.prototype.getPathToLayer = function(path, z, x, y){
	// Assume that the args are already ints
	// Jens 12/29/08
	//z = parseInt(z,10);
	//x = parseInt(x,10);
	//y = parseInt(y,10);

	return this.tile_server+"/map_"+path.replace('/','_')+"_"+z+"_"+x+"_"+y+".png";
};

psharkmap.prototype.clearTileQueue = function(){
	this.basemap_tile_queue.length=0;
	for (var d=0; d<this.overlay_tile_queue.length; d++){
		this.overlay_tile_queue[d].length=0;
	}
};

psharkmap.prototype.updateViewCount = function(){
	if (this.u){
		this.view_locked = false;
		return true;
	}
	var vc="";

	if (this.subscriber || this.current_zoom < this.zoomlevel_array.length/2){
		this.lockMap();
		return true;
	}
	if (this.current_scr==1){
		
		if (!this.view_count[this.current_basemap]){
			this.view_count[this.current_basemap] = 0;
		}
		this.view_count[this.current_basemap]++;
		if (this.view_count[this.current_basemap] % 25 === 0){
	
			var expires = new Date();
			expires.setTime(expires.getTime() + this.getremainingseconds(3,0,0) * 1000);
			
			for (var key in this.view_count){
				if (key != 'removeValue' && key != 'inArray'){
					if (vc){
						vc += ";";
					}
					vc += key + ":" + this.view_count[key];
				}
			}
			this.SetCookie (this.locale+"vc",vc,expires,"/");
			
			if (this.view_count[this.current_basemap] >= this.free_tiles){
				this.lockMap();
				return false;
			}
		}
	}
	if (this.current_scr==2){
		this.lockMap();
		return false;
	}
	this.view_locked = false;
	return true;
};

psharkmap.prototype.lockMap = function(){
	if (this.max_zoom_stepping){
		return false;
	}
	
	if (this.subscriber || this.current_zoom < this.zoomlevel_array.length/2){
		this.map.dialog_layer.style.display = "none";
		this.view_locked = false;
		return false;
	}
	
	if ((this.current_scr==1 && this.view_count[this.current_basemap]>=this.free_tiles) || this.current_scr==2){
		this.setDialogContent("subscription");
		this.map.dialog_layer.style.display = "block";
		this.view_locked = true;
		return true;
	}
		this.map.dialog_layer.style.display = "none";
		this.view_locked = false;
		return false;
};

psharkmap.prototype.unlockMap = function(){
	this.map.dialog_layer.style.display = "none";
	this.view_locked = false;
};

psharkmap.prototype.paintDialogLayer = function(){
	if (!this.map.dialog_layer){
				var map_obj = this;
				this.map.dialog_layer = this.cE("div",this.canvas.obj);
		this.map.dialog_layer.className = "dialog";

				this.map.dialog = this.cE("div",this.map.dialog_layer);
				this.map.dialog.className = "subscribe";
		this.setStyles(this.map.dialog,{"borderWidth":this.canvas.borderWidth+"px","borderStyle":this.canvas.borderStyle,"borderColor":this.canvas.borderColor});
	}
	this.setStyles(this.map.dialog_layer,{"top":(this.canvas.set_in_layout) ? this.getPos(this.map.obj)[1]+this.canvas.borderTopWidth+"px" : this.canvas.borderWidth+"px","left":this.canvas.borderLeftWidth+this.canvas.left_offset+"px","width":this.map.width + "px","height":this.map.height + "px"});
	this.setStyles(this.map.dialog,{"width":Math.min(this.map.width-105,this.map.report.width+60) +"px","left":(this.map.width-Math.min(this.map.width-105,this.map.report.width+60)-60)/2+"px","top":this.map.height/3+"px"});
};

psharkmap.prototype.setDialogContent = function(content){

	if (!this.map.dialog){
		this.paintDialogLayer();
	}
	this.map.dialog.innerHTML = "";
	var map_obj = this;
	var a, p, txt;
	if (content == "subscription"){
		p = document.createElement("p");
		txt = document.createTextNode("We're sorry, but you are either not signed in or your PropertyShark subscription does not include unlimited usage of the current zoom level of this map. ");
		p.appendChild(txt);
		a = document.createElement("a");
		a.setAttribute("href","javascript:void(0)");
		txt = document.createTextNode("Zoom out.");
		a.appendChild(txt);
		p.appendChild(a);
			
		a.onclick = function(){
			map_obj.unlockMap()
			map_obj.zoomMapPanel(Math.floor((map_obj.zoomlevel_array.length-1)/2));
		}
		this.map.dialog.appendChild(p);
		p = document.createElement("p");
		p.innerHTML = "For unrestricted access, please <a href=\"/mason/Accounts/logon.html\">sign in</a> or <a href=\"/mason/Subscribe/\">subscribe</a>.";
		this.map.dialog.appendChild(p);
		this.map.dialog_layer.style.background = "#fff url('"+this.path+"subscribe.png')";
	}
	if (content == "max_zoom"){
		this.map.dialog_layer.style.background = "none";
		this.map.dialog.innerHTML = "The current map is not available for the zoom level you requested. It has been substituted by the default map.<br /><br />";
		var a_use_default = document.createElement("a");
		a_use_default.setAttribute("href","javascript:void(0)");
		a_use_default.innerHTML = "Use default map for this zoom level";
		a_use_default.onclick = function(){
			map_obj.view_locked = false;
			map_obj.map.dialog_layer.style.display = "none";
		}
		this.map.dialog.appendChild(a_use_default);
		var br = document.createElement("br");
		this.map.dialog.appendChild(br);
		this.map.dialog.appendChild(br);
		this.map.dialog.appendChild(br);
		a = document.createElement("a");
		a.setAttribute("href","javascript:void(0)");
		a.innerHTML = "Zoom out to where current map is available";
		a.onclick = function(){
			map_obj.zoomMapPanel(map_obj.max_zoom);
			map_obj.view_locked = false;
			map_obj.map.dialog_layer.style.display = "none";
		}
		this.map.dialog.appendChild(a);
	}
};
	
psharkmap.prototype.paintLockLayer = function(){
	this.setDialogContent("subscription");
};
	
psharkmap.prototype.getremainingseconds = function(h,m,s){
	if (!m){m=0};
	if (!s){s=0};
	var currentTime = new Date();
	var hours = currentTime.getHours();
	var minutes = currentTime.getMinutes();
	var seconds = currentTime.getSeconds();
	var rs,rm,rh;
	if(seconds<=s){rs = s-seconds;}else{rs = s-seconds+60;minutes++;}
	if(minutes<=m){rm = m-minutes;}else{rm = m-minutes+60;hours++;}
	if(hours<=h){rh = h-hours;}else{rh = h-hours+24;}
	return (rh*60*60) + (rm*60) + rs;
};

psharkmap.prototype.SetCookie = function(name,value,expires,path,domain,secure){
	document.cookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? ";secure" : "")
};

psharkmap.prototype.getCookieVal = function(offset){
	var endstr = document.cookie.indexOf(";", offset);
	if (endstr == -1){
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
};

psharkmap.prototype.GetCookie = function(name){
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen){
		var j = i + alen;
		if (document.cookie.substring(i,j) == arg){
			return this.getCookieVal(j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i === 0){
			break;
		}
	}
	return null;
};

psharkmap.prototype.DeleteCookie = function( name ){
	var expires = new Date ( );  // current date & time
	expires.setTime ( expires.getTime() - 1 );
	this.SetCookie (name,null,expires,"/");
};

psharkmap.prototype.setMapCursor = function(){
	if (this.no_pan){
		return false;
	}

	var map_obj = this;
	switch(this.mode) {
		case "polygon" :
			if (map_obj.polygonpanel_obj){
				if (map_obj.polygonpanel_obj.polygon_mode == "+" || map_obj.polygonpanel_obj.polygon_mode == "-")
					this.map.obj.style.cursor = "url(/maps/psharkmap/polygon/vertex_join.cur), auto";
				else if (!map_obj.polygonpanel_obj.polygon_mode){
					if (map_obj.polygonpanel_obj.polygon_completed)
						this.map.obj.style.cursor = "default";
					else
						this.map.obj.style.cursor = "url(/maps/psharkmap/polygon/vertex_draw.cur), auto";
				}
			}
			break;
		case "geopicker" :
			this.map.obj.style.cursor = "default";
			break;
		default :
			this.map.obj.style.cursor = (document.all) ? "move" : "-moz-grab";
	}
};

psharkmap.prototype.setMapCursorDown = function(){
	if (this.no_pan){
		return false;
	}
	this.map.obj.style.cursor = (this.mode=="polygon")?"default":(document.all) ? "move" : "-moz-grabbing";
};

psharkmap.prototype.purgeTileQueue = function(){
	var basemap_arr = this.basemap_tile_queue;
	var overlay_arr = this.overlay_tile_queue;

	for (var i=0;i < basemap_arr.length; i++){
		var obj = PSRKMAP$(basemap_arr[i]);
		if (obj){
			if (obj.src) obj.src = obj.src;
		}
	}

	for (var i=0;i < overlay_arr.length; i++){
		for (var j=0;j < overlay_arr[i].length; j++){
			var obj = PSRKMAP$(overlay_arr[i][j]);
			if (obj){
				if (obj.src){
					obj.src = obj.src;
				}
			}
		}
	}
};

// global functions and objects




/* ***********************************************************
   *  The following are geopicker functions
   *  Removed 12/29/08 by Jens
   ***********************************************************
psharkmap.prototype.loadCanvasLayers = function () {
	if (!this.map.feature.json_tiles){
		return;
	}
	if (!this.map.feature.layer){
		this.paintCanvasLayer();
	}

	if (!this.load_canvas_layers_obj){
		this.load_canvas_layers_obj = [];
	}
	if (!this.map.feature.subregion_type || !this.map.feature.geopicker_subregion_config || !this.map.feature.geopicker_subregion_config[this.map.feature.subregion_type]){
		return;
	}
	for (var x = Math.max(this.left_tile_n,0); x <= Math.min(this.right_tile_n,this.zoomlevel_array[this.current_zoom].x_tiles-1); x++){
		for (var y = Math.max(this.top_tile_n,0); y <= Math.min(this.bottom_tile_n,this.zoomlevel_array[this.current_zoom].y_tiles-1); y++){
			if (!this.load_canvas_layers_obj[this.current_zoom+"_"+x+"_"+y]){
				var solid=false;
				for (var i=this.map.feature.geopicker_subregion_config[this.map.feature.subregion_type].length-1; i>=0; i--){
					for (var j=0; j < this.map.feature.geopicker_subregion_config[this.map.feature.subregion_type][i].zoom_levels.length; j++){
						if (this.current_zoom == this.map.feature.geopicker_subregion_config[this.map.feature.subregion_type][i].zoom_levels[j]){
							var hover_type = 'outline';
							if (!solid){
									hover_type = 'solid';
									solid=true;
							}
								
							if (this.load_canvas_layers_obj[this.map.feature.geopicker_subregion_config[this.map.feature.subregion_type][i].group+"_"+this.current_zoom+"_"+x+"_"+y]){
								this.featureLoaded(null,'outline',this.current_zoom,x,y,hover_type,this.map.feature.geopicker_subregion_config[this.map.feature.subregion_type][i].group);
							}else{
								var url = "/mason/Maps/canvaslayer.html?map="+this.locale+"&x="+x+"&y="+y+"&z="+this.current_zoom+"&subregion="+this.map.feature.geopicker_subregion_config[this.map.feature.subregion_type][i].group;
								var pajax = new psharkmapAJAXobj();
								pajax.setURL(url);
								pajax.setTargetFunction(PSRKMAP.canvaslayerloaded);
								pajax.pushFunctionArg(this.current_zoom);
								pajax.pushFunctionArg(x);
								pajax.pushFunctionArg(y);
								pajax.pushFunctionArg(hover_type);
								pajax.pushFunctionArg(this.map.feature.geopicker_subregion_config[this.map.feature.subregion_type][i].group);

								pajax.sendRequest();
							}
							this.load_canvas_layers_obj[this.map.feature.geopicker_subregion_config[this.map.feature.subregion_type][i].group+"_"+this.current_zoom+"_"+x+"_"+y] = 1;
						}
					}
				}
			}
		}
	}

};

PSRKMAP.canvaslayerloaded = function(str,z,x,y,hover_type,group){
	if (!PSRKMAP.active_map) return false;
	PSRKMAP.active_map.featureLoaded(str,'outline',z,x,y,hover_type,group);
}

*/

//  overlay section

// psharkmap member functions

psharkmap.prototype.paintOverlaysInit = function(){
	this.map.overlays = new Array();
	// regular overlays
	for (var d = 0; d < this.current_overlays.length; d++){
		if (!this.map.overlays[d]){
			this.map.overlays[d] = [];
			this.map.overlays[d].obj = document.createElement("div");
			this.map.overlays[d].obj.style.position="absolute";
			this.map.overlays[d].obj.style.top = 0;
			this.map.overlays[d].obj.style.left = 0;
			this.map.overlays[d].obj.style.zIndex = this.overlay_zi_n;
			this.map.overlays[d].obj.className = "layer";
			this.map.root.appendChild(this.map.overlays[d].obj);
			this.overlay_tile_queue[d] = new Array();
			this.overlay_zi_n++;
		}
	}
	// pois
	var dp = this.map.overlays.length
	for (var d = dp; d < this.current_pois.length+dp; d++){
		if (!this.map.overlays[d]){
			this.map.overlays[d] = [];
			this.map.overlays[d].obj = document.createElement("div");
			this.map.overlays[d].obj.style.position="absolute";
			this.map.overlays[d].obj.style.top = 0;
			this.map.overlays[d].obj.style.left = 0;
			this.map.overlays[d].obj.style.zIndex = this.poi_zi_n;
			this.map.overlays[d].obj.className = "pois";
			this.map.root.appendChild(this.map.overlays[d].obj);
			this.overlay_tile_queue[d] = new Array();
			this.poi_zi_n++;
		}
	}
};

psharkmap.prototype.paintOverlays = function(){
	if (!this.map.overlays){
		return;
	}
	var d = this.map.overlays.length
	var d_adjust = this.current_overlays.length-d;		

	for (var i = 0; i < this.overlay_array.length; i++){
		for (var j = 0; j < this.overlay_array[i].la.length; j++){
			var cur=false
			var cur_id

			if (!this.map.overlays[d]){
				for (var c=0; c<this.current_overlays.length;c++){
					if (this.overlay_array[i].la[j].path == this.current_overlays[c]){
						cur=true;
						this.overlay_array[i].la[j].d = c;
						if (this.map.overlays[c]){
							this.map.overlays[c].i = i;
							this.map.overlays[c].j = j;
						}
					}
				}
				
				for (var c=0; c<this.current_pois.length;c++){
					if (this.overlay_array[i].la[j].path == this.current_pois[c]){
						cur=true;
						this.overlay_array[i].la[j].d = c+this.current_overlays.length;
						if (this.map.overlays[c+this.current_overlays.length]){
							this.map.overlays[c+this.current_overlays.length].i = i;
							this.map.overlays[c+this.current_overlays.length].j = j;
						}
					}
				}
				
				if (!cur){
					this.overlay_array[i].la[j].d = d;
					this.createOverlayLayer(d, i, j, this.overlay_array[i].la[j].poi);
					d++;
				}
			}
		}
	}
};

psharkmap.prototype.createOverlayLayer = function(d, i, j, poi){
	this.map.overlays[d] = [];
	this.map.overlays[d].i = i;
	this.map.overlays[d].j = j;
	this.map.overlays[d].obj = document.createElement("div");
	this.map.overlays[d].obj.style.position="absolute";
	this.map.overlays[d].obj.style.top = 0;
	this.map.overlays[d].obj.style.left = 0;
	if (!poi){
		this.map.overlays[d].obj.className = "layer";
		this.map.overlays[d].obj.style.zIndex = this.overlay_zi_n;
		this.overlay_zi_n++;
	}else{
		this.map.overlays[d].obj.className = "pois";
		this.map.overlays[d].obj.style.zIndex = this.poi_zi_n;
		this.poi_zi_n++;
	}
	
	this.map.root.appendChild(this.map.overlays[d].obj);
	this.overlay_tile_queue[d] = [];
};

psharkmap.prototype.clearOverlayLayers = function(){
	for (var i = 0; i < this.overlay_array.length; i++){
		this.clearOverlayLayer(i);
	}
};

psharkmap.prototype.clearOverlayLayer = function(d){
	d = parseInt(d);
	if (this.map.overlays[d]){
		this.map.overlays[d].obj.innerHTML = "";
	}
};

psharkmap.prototype.hideOverlayLayer = function(d){
	d = parseInt(d);
	
	if (this.map.overlays[d]){
		this.map.overlays[d].obj.style.display = "none";
	}
};

psharkmap.prototype.showOverlayLayer = function(d){
	d = parseInt(d);
	
	
	if (this.map.overlays[d]){
	
		for (var i=0; i < this.map.overlays.length; i++){
			if (this.map.overlays[i].obj.className == this.map.overlays[d].obj.className){
				if (this.map.overlays[i].obj.style.zIndex > this.map.overlays[d].obj.style.zIndex){
					this.map.overlays[d].obj.style.zIndex = this.map.overlays[i].obj.style.zIndex;
					this.map.overlays[i].obj.style.zIndex--;
				}
			}
		}
		this.map.overlays[d].obj.style.display = "block";
		if(this.map.overlays[d].obj.className == "pois"){

				this.centerPOIMarkers(d);

				this.pending_centerpoi = d;

		}
	}
};

psharkmap.prototype.changeOverlayLayer = function(overlay, layer, active, pois){
	var overlay = arguments[0];
	var layer = arguments[1];
	var active = arguments[2];
	var arr = pois ? this.current_pois : this.current_overlays;
	if (this.isOverlay(overlay)){
		if (active){
			arr.push(overlay); 
			this.showOverlayLayer(layer);
			this.showOverlayLegend(overlay);
		}else{
			arr.removeValue(overlay); 
			this.hideOverlayLayer(layer);
			this.hideOverlayLegend(overlay);
		}
		this.clearTileQueue();
		this.loadMapPanel();
		this.setOverlayPanelSize();
	}
};

psharkmap.prototype.isOverlay = function(overlay){
	for (var i=0; i < this.overlay_array.length; i++) {
		for (var j=0; j < this.overlay_array[i].la.length; j++){
			if (this.overlay_array[i].la[j].path === overlay){
				return true;
			}
		}
	}
	return false;
};

psharkmap.prototype.setOverlayPanelSize = function(){
	this.setThemePanelSize();
};

psharkmap.prototype.getInitOverlays = function(){
	var lg = new Array();
	var di = 0;
	var n = 0
	if (this.current_overlays.length){
		lg[n] = new Array();
		lg[n].title = "";
		lg[n].la = new Array();
		for (var i=0; i < this.current_overlays.length; i++){
			lg[n].la[i] = new Array();
			lg[n].la[i].path = this.current_overlays[i];
			lg[n].la[i].name = "";
			lg[n].la[i].z = 3;
			lg[n].la[i].legend_title = null;
			lg[n].la[i].legend_url = null;
			lg[n].la[i].d = i;
			di = i
		}
		n++;
	}
	
	if (this.current_pois.length){
		lg[n] = new Array();
		lg[n].title = "";
		lg[n].la = new Array();
		for (var i=0; i < this.current_pois.length; i++){
			for (var j=0; j < this.poi_overlays.length; j++){
				if (this.poi_overlays[j].path == this.current_pois[i]){
					lg[n].la[i] = new Array();
					lg[n].la[i].path = this.current_pois[i];
					lg[n].la[i].external = true;
					
					lg[n].la[i].name = "";
					lg[n].la[i].z = 3;
					lg[n].la[i].legend_title = null;
					lg[n].la[i].legend_url = null;
					lg[n].la[i].d = di+i;
					lg[n].la[i].poi = true;
	
					lg[n].la[i].source = this.poi_overlays[j].source;
					lg[n].la[i].marker_class = this.poi_overlays[j].marker_class
					lg[n].la[i].external = this.poi_overlays[j].external;
				}			
			}
		}
	}
	return lg;
};

psharkmap.prototype.toggleOverlay = function (overlay,show) {
	// what is this? why is it not in the overlay section of our code
	// is it even used any more?
	var overlay = this.locale+"/"+overlay;
	for (var i=0; i < this.overlay_array.length; i++) {
		for (var j=0; j < this.overlay_array[i].la.length; j++){
			if (this.overlay_array[i].la[j].path === overlay){
				this.changeOverlayLayer(overlay,this.overlay_array[i].la[j].d,show,false);
				return;
			}
		}
	}
};

psharkmap.prototype.changeOverlay = function(overlay,layer,active,is_poi){
	// this was formerly a global function
	// not sure why...
	// Jens, 12/31/08
	this.changeOverlayLayer(overlay,layer,active,is_poi);
	if (active){
		PSRKMAP.changeView(overlay);
	}
};


// global functions and objects


//  poi section

// psharkmap member functions

psharkmap.prototype.createPOI = function(title,x,y,txt,open){
	var mypoints = {
		"points":[
			{
				"title": title,
				"txt": txt,
				"x": x,
				"y": y,
				"open": open
			}
		]
	}
	this.createPointsLayer("Points Of Interest","Points Of Interest","static_poi",mypoints,false,"red",true);
	this.setPointsLayers("static_poi");
};

psharkmap.prototype.createPOIs = function(arr){
	for (var i=0; i < arr.length; i++){
		this.poi_array.push(arr[i])
	}
};

psharkmap.prototype.createPOILayer = function(name,path,obj,ext,marker_class,open){
	var overlay = new Array()
	overlay.title = "Points of Interest";
	overlay.path = this.locale+"/"+path;
	overlay.name = name;
	overlay.z = 0;
	overlay.legend_title = overlay.title;
	overlay.legend_url = "";
	overlay.external = ext;
	overlay.loaded = false;
	overlay.source = obj;
	overlay.poi = true;
	overlay.placed = -1;
	overlay.has_layer = false;
	overlay.marker_class = (marker_class) ? marker_class:"";
	overlay.open = open;
	this.poi_overlays.push(overlay)
};

psharkmap.prototype.createPointsLayer = function(group,name,path,obj,ext,marker_class,report,type){
	var overlay = new Array()
	overlay.title = group;
	overlay.path = this.locale+"/"+path;
	overlay.name = name;
	overlay.report = report;
	overlay.z = 0;
	overlay.legend_title = overlay.title;
	overlay.legend_url = "";
	overlay.external = ext;
	overlay.loaded = false;
	overlay.source = obj;
	overlay.poi = true;
	overlay.placed = -1;
	overlay.has_layer = false;
	overlay.marker_class = (marker_class) ? marker_class:"";
	overlay.type = (type) ? type : "public";
	this.poi_overlays.push(overlay)
};

psharkmap.prototype.addPOIsToLayers = function(){
	// add pois
	if(this.poi_overlays.length){
		this.poi_overlays.sort(this.sort_by_title);
		var prev_group = "";
		for (var i=0; i < this.poi_overlays.length; i++){
			if (!this.poi_overlays[i].has_layer){
				var cur_group = this.poi_overlays[i].title
				if (prev_group != cur_group){
					var pois = new Array();
					pois.title = this.poi_overlays[i].title;
					pois.la = new Array();
					this.overlay_array.push(pois);
					prev_group = cur_group
				}
				pois.la.push(this.poi_overlays[i]);
				this.poi_overlays[i].has_layer = true;
				
				
				
				var d = this.map.overlays.length;
				this.poi_overlays[i].d = d;

				this.createOverlayLayer(d, this.overlay_array.length, pois.la.length, this.poi_overlays[i].poi);
				
			}
		}
		this.overlay_array.sort(this.sort_by_title);

	}
};

psharkmap.prototype.addMultiPOIs = function(obj,marker_class){
	this.addNamedMultiPOIs(obj,"MPL",marker_class)
};

psharkmap.prototype.addNamedMultiPOIs = function(obj,name,marker_class){
	var ext = (typeof(obj)=="string");
	this.addPointsLayer("MPL",name,"multi_points_layer",obj,ext,marker_class,false);
};

psharkmap.prototype.addSinglePOI = function(title,x,y,txt,marker_class,open){
	this.addNamedSinglePOI(title,x,y,txt,"SPL",marker_class,open);
};

psharkmap.prototype.addNamedSinglePOI = function(title,x,y,txt,name,marker_class,open){
	var obj = {
		"points":[
			{
				"title": title,
				"txt": txt,
				"x": x,
				"y": y,
				"open": open
			}
		]
	}
	this.addPointsLayer("SPL",name,"single_point_layer",obj,false,marker_class,false);
};

psharkmap.prototype.addPointsLayer = function(group,name,path,obj,ext,marker_class,report){
	if(this.poi_overlays.length){
		for (var i=0; i < this.poi_overlays.length; i++){
			if (this.poi_overlays[i].path == this.locale+"/"+path){
				this.updatePointsLayer(name,path,obj,ext,marker_class,report);
				return;
			}
		}
	}
	this.createPointsLayer(group,name,path,obj,ext,marker_class,report);
	this.addPOIsToLayers();
	this.updatePointsLayer(name,path,obj,ext,marker_class,report);
};

psharkmap.prototype.updatePointsLayer = function (name,path,obj,ext,marker_class,report){
	for (var i=0; i < this.overlay_array.length; i++) {
		for (var j=0; j < this.overlay_array[i].la.length; j++){
			if(this.overlay_array[i].la[j].poi){
				if (this.overlay_array[i].la[j].path == this.locale+"/"+path){
					var d = this.overlay_array[i].la[j].d;
					this.overlay_array[i].la[j].loaded = false;
					this.overlay_array[i].la[j].source = obj;
					this.overlay_array[i].la[j].external = ext;
					this.overlay_array[i].la[j].marker_class = marker_class;
					this.overlay_array[i].la[j].report = report;
					this.overlay_array[i].la[j].placed = -1;
					
					this.changeOverlay(this.locale+"/"+path,d,true,true);
				}
			}
		}
	}
};

psharkmap.prototype.sort_by_title = function(a,b) {
	x = 0;
	if (a.title == b.title){
		if (a.name < b.name) x=-1;
		else x=1;
	}else{
		if (a.title < b.title) x=-1;
		else x=1;
	}
	return x;
};

psharkmap.prototype.loadExternalPOI = function(i,j,d){
	this.overlay_array[i].la[j].loading=true;
	this.loadingPOI(this.overlay_array[i].la[j].name,d);
	var url = this.overlay_array[i].la[j].source;

	var pajax = new psharkmapAJAXobj();
	pajax.setURL(url);
	pajax.setTargetFunction(PSRKMAP.getPOI);
	pajax.pushFunctionArg("external"+d);
	pajax.pushFunctionArg(this);
	pajax.pushFunctionArg(i);
	pajax.pushFunctionArg(j);
	pajax.pushFunctionArg(d);
	pajax.sendRequest();			
};

psharkmap.prototype.loadingPOI = function(name,d){
	if (!this.tools.loading_poi){	
		this.tools.loading_poi = document.createElement("div");
		this.tools.loading_poi.style.position = "absolute";
		this.tools.loading_poi.style.width = "252px";
		this.tools.loading_poi.style.height = "20px";
		this.tools.loading_poi.style.padding = "18px 20px 22px 20px";
		
		this.tools.loading_poi.style.font = "bold 12px arial";
		this.tools.loading_poi.style.background = (window.XMLHttpRequest) ? "url('"+this.path+"poi_load.png') 3px 3px no-repeat" : "url('"+this.path+"poi_load.gif') 3px 3px no-repeat";
		this.map.overlays[d].obj.appendChild(this.tools.loading_poi);
	}

	this.map.overlays[d].obj.appendChild(this.tools.loading_poi);
	
	this.tools.loading_poi.innerHTML = "<span style='padding:4px 2px 4px 26px;display:block;background: url("+this.path+"load_w.gif) 3px 3px no-repeat;'> Loading "+name+"</span>";
	this.tools.loading_poi.style.top = this.map_offset_y+2*this.map.height/5+"px";
	this.tools.loading_poi.style.left = this.map_offset_x+this.map.width/2-116+"px";
	this.tools.loading_poi.style.display = "block";
};

psharkmap.prototype.loadingPOICompleted = function(){
	if (this.tools.loading_poi){
		this.tools.loading_poi.style.display = "none";
	}
};

psharkmap.prototype.isPOI = function(overlay){
	for (var i=0; i < this.overlay_array.length; i++) {
		for (var j=0; j < this.overlay_array[i].la.length; j++){
			if (this.overlay_array[i].la[j].path === overlay && this.overlay_array[i].la[j].poi){
				return true;
			}
		}
	}
	return false;
};
	
psharkmap.prototype.clearPOIMarkers = function(d,i,j){ 
	if (!this.map.overlays[d].obj){
		return;
	}
	while (this.map.overlays[d].obj.childNodes.length){
		//alert("remove a child node")
		var obj = this.map.overlays[d].obj.childNodes[0];
		var popup = PSRKMAP$("poi_"+obj.id);
		if (popup){
			//alert("remove popup")
			popup.parentNode.removeChild(popup);
		}
		if (obj){
			//alert("remove marker")
			obj.parentNode.removeChild(obj);
		}
	}
};

psharkmap.prototype.placePOIMarkers = function(d,myi,myj){
	var map_obj = this;

	var destination = (this.map.overlays[d].obj);
	if (!destination) return;
	
	this.clearPOIMarkers(d);

	var marker_class = this.overlay_array[myi].la[myj].marker_class;
	var arr = this.overlay_array[myi].la[myj].source;
	
	if (arr.type){
		if (arr.type == "FeatureCollection" && arr.members){
			// potential problem: externals get rebuilt every time, internals do not
			var arr_from_objs = [];
			var c = 0;
			for (var i=0; i < arr.members.length; i++){
				if (arr.members[i].type && arr.members[i].id && arr.members[i].geometry && arr.members[i].properties){
					arr_from_objs[c] = [];
					arr_from_objs[c].x = arr.members[i].geometry.coordinates[0];
					arr_from_objs[c].y = arr.members[i].geometry.coordinates[1];
					arr_from_objs[c].title = arr.members[i].properties.title;
					arr_from_objs[c].txt = arr.members[i].properties.txt;
					if (arr.members[i].properties.label_id){
						arr_from_objs[c].id = arr.members[i].properties.label_id;
					}
					c++;
				}
			}
			arr = arr_from_objs;
		}
	}

	var pz = this.zoomlevel_array.length-1;
	var path = this.overlay_array[myi].la[myj].path.replace(this.locale+"/","");
	
	if (arr.points){
		arr = arr.points;
	}
	
	var x_sum = 0, y_sum = 0;

	for (var i = 0; i < arr.length; i++){
		x_sum += parseFloat(arr[i].x);
		y_sum += parseFloat(arr[i].y);

		if (!arr[i].marker){
		
			var marker = document.createElement("div")
			marker.style.position = "absolute";
			marker.style.cursor = "default";
			marker.style.zIndex = "799";
			arr[i].marker = marker;
			arr[i].marker.style.cursor = "pointer";
			
			if (arr[i].id){
				arr[i].marker.innerHTML = arr[i].id;
				arr[i].marker.style.font = "bold 12px arial";
				arr[i].marker.style.textAlign = "center";
				arr[i].width = 33;
				arr[i].height = 31;
				arr[i].marker.style.width = "27px";
				arr[i].marker.style.height = "18px";
				arr[i].marker.style.padding = "3px 4px 10px 2px";
				if(!marker_class){
					marker_class = "red";
				}
				if (marker_class.indexOf("box")<0){
					marker_class+="box";
				}
			}else{
				arr[i].width = 30;
				arr[i].height = 30;
				arr[i].marker.style.width = "24px";
				arr[i].marker.style.height = "18px";
				arr[i].marker.style.padding = "4px 4px 8px 2px";
			
			}
			destination.appendChild(marker);
			
			arr[i].marker.title = (arr[i].id) ? arr[i].id : "";
			
			if (arr[i].title){
				arr[i].marker.title += (arr[i].id) ? ".\u00a0\u00a0 "+arr[i].title : arr[i].title;
			}
			
			arr[i].marker.txt=arr[i].txt
			arr[i].marker.report=this.overlay_array[myi].la[myj].report
			arr[i].marker.x=arr[i].x
			arr[i].marker.y=arr[i].y
			arr[i].marker.built=false;
			arr[i].marker.open = arr[i].open;
			if (arr[i].args){
				arr[i].marker.args=arr[i].args;
			}
			
			arr[i].marker.id = (arr[i].id) ? this.psharkmap_id+"_"+path+"_marker_"+arr[i].id : this.psharkmap_id+"_"+path+"_marker_"+i;
		
			if (arr[i].open == 1){
				PSRKMAP.markerFocus(arr[i].marker,map_obj,true);
			}
			
			arr[i].marker.onclick = function(){
				if (this.hasfocus){
					this.hasfocus = false;
					PSRKMAP.losePOIFocus(this);
				} else {
					PSRKMAP.markerFocus(this,map_obj,true);
				}
			}
			arr[i].marker.onmouseup = function(){
				PSRKMAP.drag_ready=false;
				PSRKMAP.dragging=false;
				var event = (arguments[0])?arguments[0]:window.event;
				event.cancelBubble = true;
				if (event.stopPropagation) event.stopPropagation();
			}
		}else{
			if (arr[i].marker.parentNode != destination){
				//alert("we changed destination" + destination.className);
				destination.appendChild(arr[i].marker);
			}
			if (arr[i].id){
				arr[i].marker.innerHTML = arr[i].id;
			}
		}

		arr[i].marker.className = "poi";
		if(marker_class){
			arr[i].marker.style.background = (window.XMLHttpRequest) ? "url('"+this.path+"poi_"+marker_class+".png') 0 100% no-repeat" : "url('"+this.path+"poi_"+marker_class+".gif') 0 100% no-repeat";
		}

		arr[i].marker.style.left = arr[i].x * (this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size)-2+"px";
		arr[i].marker.style.top =  arr[i].y * (this.zoomlevel_array[this.current_zoom].y_tiles*this.zoomlevel_array[this.current_zoom].y_tile_size)-27+"px";
		var popup = PSRKMAP$("poi_"+arr[i].marker.id)
		
		if (popup){
			if (popup.style.visibility == "visible"){
				this.placePOIPopup(arr[i].marker,popup);
			}
		}else{
			arr[i].marker.hasfocus = false;
			arr[i].marker.built = false;
		}
		if (arr[i].marker.open){
			PSRKMAP.markerFocus(arr[i].marker,this,false);
		}
		
	}
	
	if (this.overlay_array[myi].la[myj].placed<0){
		var center_x = x_sum/arr.length;
		var center_y = y_sum/arr.length;
		
		var ci=0;
		for (var i = 0; i < arr.length; i++){
			if (Math.pow(center_x-parseFloat(arr[i].x),2)+Math.pow(center_y-parseFloat(arr[i].y),2) < Math.pow(center_x-parseFloat(arr[ci].x),2)+Math.pow(center_y-parseFloat(arr[ci].y),2)){
				ci = i;
			}
		}
	
		this.map.overlays[d].center_x = arr[ci].x;
		this.map.overlays[d].center_y = arr[ci].y;
	}
		
	if (myi){
		this.overlay_array[myi].la[myj].placed = this.current_zoom;
	}
	if (this.pending_centerpoi == d){
		this.centerPOIMarkers(d);
		this.pending_centerpoi = false;
	}
	
};

psharkmap.prototype.placePOIPopup = function(obj,pop,scroll){
	var ol = isNaN(parseInt(obj.style.left)) ? 0 : parseInt(obj.style.left);
	var ot = isNaN(parseInt(obj.style.top)) ? 0 : parseInt(obj.style.top);
	var pop_left = Math.min(ol+obj.offsetWidth, this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size-pop.offsetWidth)
	var pop_top = Math.min(ot, this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size - pop.offsetHeight)
	pop.style.left = pop_left+"px";
	pop.style.top = pop_top+"px";
	
	if (scroll){
		var right_overflow = Math.max(0,(pop_left+pop.offsetWidth)-(this.map_offset_x+this.map.width))
		var bottom_overflow = Math.max(0,(pop_top+pop.offsetHeight)-(this.map_offset_y+this.map.height))
		if (right_overflow || bottom_overflow) this.scrollDistance(-right_overflow,-bottom_overflow)
	}
};

psharkmap.prototype.cretePOIDisplayLayer = function(){
	this.map.poi_display_layer = document.createElement("div");
	this.map.poi_display_layer.id = "poidisplay";
	this.map.poi_display_layer.style.position="absolute";
	this.map.poi_display_layer.style.top = 0;
	this.map.poi_display_layer.style.left = 0;
	this.map.poi_display_layer.style.zIndex = 1300;
	this.map.poi_display_layer.className = "layer";
	this.map.root.appendChild(this.map.poi_display_layer);
};

psharkmap.prototype.createPOIPop = function(obj){
	var map_obj = this;
	var address = document.createElement("table")
	address.onclick = function(){
		map_obj.suspendClick()
	}
	var tbody = document.createElement("tbody")
	var trow=document.createElement("tr");
	var tcell=document.createElement("td");
	tcell.colSpan="2";

	if (obj.title && obj.title!="undefined"){
		var h5 = document.createElement("h5");
		h5.style.textAlign = "left";
		h5.appendChild(document.createTextNode(obj.title));
		tcell.appendChild(h5);
	}
		
	tcell.vAlign="top";
	tcell.style.padding="0 0 0 12px";
	tcell.style.background = (window.XMLHttpRequest) ? "url('"+this.path+"poi_popup_hor.png') 0 -30px no-repeat" : "url('"+this.path+"poi_popup_hor.gif') 0 -30px no-repeat";
	trow.appendChild(tcell)

	var tcell=document.createElement("td");
	tcell.style.padding="3px 5px 0 0";
	tcell.align="right";
	tcell.vAlign="top";

	var a = document.createElement("a")
	a.href="javascript:void(0);"
	a.onclick = function(){
		var marker = PSRKMAP$(obj.id);
		marker.hasfocus = false;
		window.setTimeout(function () { PSRKMAP.losePOIFocus(marker); }, 100);
	}

	a.className = "close_button";
	tcell.appendChild(a);

	
	tcell.style.background = (window.XMLHttpRequest) ? "url('"+this.path+"poi_popup_hor.png') 100% -30px no-repeat" : "url('"+this.path+"poi_popup_hor.gif') 100% -30px no-repeat";
	trow.appendChild(tcell)
	var tcell=document.createElement("td");
	tbody.appendChild(trow);
	
	var trow=document.createElement("tr");
	var tcell=document.createElement("td");
	tcell.innerHTML = "<img src='"+this.path+"clear.gif' width=6 height=4 />"
	tcell.style.background = (window.XMLHttpRequest) ? "url('"+this.path+"poi_popup_ver.png') 0 0 repeat-y" : "url('"+this.path+"poi_popup_ver.gif') 0 0 repeat-y";
	
	trow.appendChild(tcell)
	var tcell=document.createElement("td");
	tcell.className = "info_center"
	
	tcell.style.borderTop = "1px solid #E1EFFA";

	if (obj.txt){
		var p = document.createElement("div");
		p.style.marginBottom = "10px";
		p.innerHTML = obj.txt;
		tcell.appendChild(p);
	}

	var tip_links = document.createElement("div");
	tip_links.className = "links";
	tcell.appendChild(tip_links);	

	if (obj.report && this.map.report.is_available){
		var a = document.createElement("a");
		a.setAttribute("href","javascript:void(0)");
		a.style.color = "#369";
		a.style.font = "bold 10px arial";
		a.onclick = function(){
			var id = this.parentNode.parentNode.parentNode.parentNode.parentNode.id
			if (obj.args){
				map_obj.ShowSearchedForReport(obj.x,obj.y,obj.args);
			}else{
				map_obj.ShowSearchedForReport(obj.x,obj.y);
			}
			map_obj.suspendClick()
		}

		var label = document.createTextNode("Show Mini-Report");
		a.appendChild(label);
	
		tip_links.appendChild(a);
		tip_links.appendChild(document.createTextNode(" \u00a0 "));
	}
	if (obj.x && obj.y){
		var a = document.createElement("a");
		a.setAttribute("href","javascript:void(0)");
		a.className="zoom_in";

		a.onclick = function(){
			if (map_obj.current_zoom<map_obj.zoomlevel_array.length-1){
				var z = Math.min(map_obj.current_zoom+3,map_obj.zoomlevel_array.length-1);
				var nx = obj.x - (map_obj.coordToXPx(obj.x) - (map_obj.map_offset_x+map_obj.map.width/2))/(map_obj.zoomlevel_array[z].x_tiles*map_obj.zoomlevel_array[z].x_tile_size);
				var ny = obj.y - (map_obj.coordToYPx(obj.y) - (map_obj.map_offset_y+map_obj.map.height/2))/(map_obj.zoomlevel_array[z].y_tiles*map_obj.zoomlevel_array[z].y_tile_size);
				map_obj.centerAndZoomMapPanel(nx,ny,z);
			}
		}

		a.appendChild(document.createTextNode("Zoom In"));
		tip_links.appendChild(a);

		tip_links.appendChild(document.createTextNode(" | "));

		var a = document.createElement("a");
		a.setAttribute("href","javascript:void(0)");
		a.className="zoom_out";
		a.onclick = function(){
			if (map_obj.current_zoom>0){
				var z = Math.max(map_obj.current_zoom-3,0);
				var nx = obj.x - (map_obj.coordToXPx(obj.x) - (map_obj.map_offset_x+map_obj.map.width/2))/(map_obj.zoomlevel_array[z].x_tiles*map_obj.zoomlevel_array[z].x_tile_size);
				var ny = obj.y - (map_obj.coordToYPx(obj.y) - (map_obj.map_offset_y+map_obj.map.height/2))/(map_obj.zoomlevel_array[z].y_tiles*map_obj.zoomlevel_array[z].y_tile_size);
				map_obj.centerAndZoomMapPanel(nx,ny,z);
			}
		}

		a.appendChild(document.createTextNode("Zoom Out"));
		tip_links.appendChild(a);
		
		tip_links.appendChild(document.createTextNode(" \u00a0 "));
		
	}
	
	tcell.style.textAlign = "left";
	trow.appendChild(tcell);
	
	var tcell=document.createElement("td");
	tcell.innerHTML = "<img src='"+this.path+"clear.gif' width=4 height=4 />"
	tcell.style.background = (window.XMLHttpRequest) ? "url('"+this.path+"poi_popup_ver.png') 100% 0 repeat-y" : "url('"+this.path+"poi_popup_ver.gif') 100% 0 repeat-y";
	trow.appendChild(tcell);
	tbody.appendChild(trow);
	
	var trow=document.createElement("tr");
	var tcell=document.createElement("td");
	tcell.colSpan="2";
	tcell.innerHTML = "<img src='"+this.path+"clear.gif' width=5 height=12 />"
	tcell.style.background = (window.XMLHttpRequest) ? "url('"+this.path+"poi_popup_hor.png') 0 0 no-repeat" : "url('"+this.path+"poi_popup_hor.gif') 0 0 no-repeat";
	trow.appendChild(tcell);
	var tcell=document.createElement("td");
	tcell.innerHTML = "<img src='"+this.path+"clear.gif' width=4 height=12 />"
	tcell.style.background = (window.XMLHttpRequest) ? "url('"+this.path+"poi_popup_hor.png') 100% 0 no-repeat" : "url('"+this.path+"poi_popup_hor.gif') 100% 0 no-repeat";
	trow.appendChild(tcell)
	var tcell=document.createElement("td");
	tbody.appendChild(trow);
	
	address.style.zIndex = "999";
					
	address.className = "marker_pop";
	address.style.position = "absolute";

	address.style.left = "20px";
	address.style.top = "-5px";
	
	address.appendChild(tbody)
	
	return address;	

};

psharkmap.prototype.centerPOIMarkers = function(d){
	if (this.current_zoom < this.zoomlevel_array.length-1 || !this.map.report.is_available){
		if (this.map.overlays[d].center_x && this.map.overlays[d].center_y){
			this.centerMapPanel(this.map.overlays[d].center_x,this.map.overlays[d].center_y);
		}
	}
	
};

psharkmap.prototype.centerMarker = function(path,id){
	for (var i=0; i < this.overlay_array.length; i++){
		for (var j=0; j < this.overlay_array[i].la.length; j++){
			if (this.overlay_array[i].la[j].path == this.locale + "/" + path){
				if (this.overlay_array[i].la[j].source){
					var arr = (this.overlay_array[i].la[j].source.points)?this.overlay_array[i].la[j].source.points:this.overlay_array[i].la[j].source;
					for (var k=0; k<arr.length; k++){
						if (arr[k].id == id){
							this.centerMapPanel(arr[k].x,arr[k].y,-50,-20);
							var d = this.overlay_array[i].la[j].d;

							this.placePOIMarkers(d,i,j);
							if (this.marker_prev_focus){
								this.marker_prev_focus.hasfocus=false;
								PSRKMAP.losePOIFocus(this.marker_prev_focus);
							}
							PSRKMAP.markerFocus(arr[k].marker,this,false);
						}
					}
				}
			}
		}		
	}
};

// global functions and objects


PSRKMAP.getPOI = function(str,n,map_obj,i,j,d){
	map_obj.overlay_array[i].la[j].source=eval("("+str+")");
	map_obj.overlay_array[i].la[j].loaded=true;
	map_obj.overlay_array[i].la[j].loading=null;
	map_obj.placePOIMarkers(d,i,j);
	map_obj.loadingPOICompleted();
}

PSRKMAP.markerFocus = function(obj,map_obj,scroll){
	if (PSRKMAP.right_zoom_out) return;
	if (!map_obj.map.poi_display_layer){
		map_obj.cretePOIDisplayLayer()
	}

	if (!obj.built){
		var address = map_obj.createPOIPop(obj);
		
		address.id="poi_"+obj.id;

				address.style.cursor = "auto";
		
				address.onclick = function(){
					PSRKMAP.drag_ready=false;
					PSRKMAP.dragging=false;
					var event = (arguments[0])?arguments[0]:window.event;
					event.cancelBubble = true;
					if (event.stopPropagation) event.stopPropagation();
				}
				address.onmouseup = function(){
					PSRKMAP.drag_ready=false;
					PSRKMAP.dragging=false;
					var event = (arguments[0])?arguments[0]:window.event;
					event.cancelBubble = true;
					if (event.stopPropagation) event.stopPropagation();
				}
				address.onmousedown = function(){
					PSRKMAP.drag_ready=false;
					PSRKMAP.dragging=false;
					var event = (arguments[0])?arguments[0]:window.event;
					event.cancelBubble = true;
					if (event.stopPropagation) event.stopPropagation();
				}	
		map_obj.map.poi_display_layer.appendChild(address);
		obj.built = true;
	}		
	var address = PSRKMAP$("poi_"+obj.id)
	map_obj.placePOIPopup(obj,address);
	PSRKMAP$("poi_"+obj.id).style.visibility = "visible";
	obj.hasfocus = true;
	obj.style.zIndex=800;
	map_obj.marker_prev_focus = obj;
	obj.open = true;
	map_obj.placePOIPopup(obj,address,scroll);
}

PSRKMAP.losePOIFocus = function(obj){
	if (!obj.hasfocus){
		obj.style.visibility = "visible";
		
		if (PSRKMAP$("poi_"+obj.id)){
		PSRKMAP$("poi_"+obj.id).style.visibility = "hidden";
		}
		obj.style.zIndex = "799";
	}
	obj.open = false;
}

PSRKMAP.focusmarker = function(map_id,layer_path,marker_id){
	PSRKMAP.active_map = PSRKMAP.getMap(map_id);
	if (PSRKMAP.active_map){
		PSRKMAP.active_map.centerMarker(layer_path,marker_id);
	}
}

//  polygon section

// psharkmap member functions

psharkmap.prototype.enablePolygon = function(fn){
	this.polygon_enabled = true;
	this.mode = "polygon";
	this.polygon_caller = fn
	this.disable_reportview = true;
};

psharkmap.prototype.paintPolygonPanel = function(){
	if(!this.polygon_enabled || this.canvas.hasControlPanel || this.canvas.fullWidth) return;
	var map_obj = this;
	if (this.polygonpanel_obj){
		this.polygonpanel_obj.paintKeyMap();
		return;
	}
	try{
		this.polygonpanel_obj = new psharkmap_polygonpanel({parent_obj:this});
	}catch(err){
		return;
	}
};

// global functions and objects

//  report section

// psharkmap member functions

psharkmap.prototype.paintReport = function(){
	if (!this.map.report.obj && this.map.report.is_available){
		this.map.report.obj = this.paintPanel(this.map.report.obj,{"width":this.map.report.width+"px", "height":"100%", "align":"left", "valign":"top", "border":"yes", "zIndex":"900","stay_open":true,"close_fn":PSRKMAP.closeReport},"reportPanel");
	}
	if (this.map.report.is_showing){
		PSRKMAP.reportLoaded();
	}
};

psharkmap.prototype.loadReport = function(x,y,args){
	if(!this.map.report.is_available){
		return false;
	}
	this.map.report.obj.container.style.display = "none";

	this.setFocusArea(x,y);
	this.showFocusArea();
	if (PSRKMAP.remote_load){
		alert("report function not supported for remote maps yet");
		return;
	}
	if (!this.map.report.obj) this.paintReport();
	this.getReportData(x,y,args);
};

psharkmap.prototype.getReportData = function(x,y,args){
	var zl_a = this.zoomlevel_array;
	var c_z = this.current_zoom;
	
	x = x*zl_a[zl_a.length-1].x_tile_size*zl_a[zl_a.length-1].x_tiles;
	y = y*zl_a[zl_a.length-1].y_tile_size*zl_a[zl_a.length-1].y_tiles;

	var x_tile = parseInt(x / zl_a[c_z].x_tile_size);
	var y_tile = parseInt(y / zl_a[c_z].y_tile_size);
	var x_pixel = x - x_tile * zl_a[c_z].x_tile_size;
	var y_pixel = y - y_tile * zl_a[c_z].y_tile_size;
	
	var url = this.map.report.url+"?map="+this.locale+"&xtile="+x_tile+"&ytile="+y_tile+"&xpixel="+x_pixel+"&ypixel="+y_pixel;
	if (args){
		url += "&"+args;
	}
	url += "&basemap=" + this.current_basemap.replace(this.locale+"/","");
	
	var overlay = "";
	for (var i=0; i < this.current_overlays.length; i++){
		if (overlay != "") overlay += ",";
		overlay += this.current_overlays[i].replace(this.locale+"/","");
	}
	if (overlay != ""){
		url += "&overlay=" + overlay;
	}
	
	if (this.map.report.obj){
		this.map.report.obj.container.className = "report";
		this.map.report.obj.container.style.visibility = "visible";
		this.map.report.obj.header.className = "report_header";
		this.map.report.obj.header.style.paddingBottom = "6px";
		this.map.report.obj.sub_header.className = "report_summary";
		this.invalidatePanelContent(this.map.report.obj);
		this.setPanelContent(this.map.report.obj,"Mini-Report","","<h3>Loading report...</h3><br>\u00a0<br>\u00a0<br>");
		this.showPanel(this.map.report.obj);

		var pajax = new psharkmapAJAXobj();
		pajax.setURL(url);
		pajax.setTargetObj(this.map.report.obj.content);
		pajax.setCallBackFunction("PSRKMAP.reportLoaded()");
		pajax.sendRequest();
	}
};

PSRKMAP.reportLoaded = function(){
	var map_obj = PSRKMAP.active_map;
	if (!map_obj)return false;
	var obj_rs = PSRKMAP$("report_summary");
	if (obj_rs){
		map_obj.map.report.obj.sub_header.style.display = "none";
		map_obj.map.report.obj.sub_header.innerHTML = obj_rs.innerHTML;
		obj_rs.parentNode.removeChild(obj_rs);
		map_obj.map.report.obj.sub_header.style.display = "block";
		map_obj.setPanelPlaceAndSize(PSRKMAP.active_map.map.report.obj);
	}
	map_obj.map.report.report_available = 1;
	map_obj.map.report.is_showing = 1;
	map_obj.toolbar_report.className = "";
	map_obj.toolbar_legends.className = "";
};

psharkmap.prototype.showReport = function(){
	if (this.map.report.obj) this.map.report.show = 1;
};

psharkmap.prototype.hideReport = function(){
	if (this.map.report.obj && this.map.report.is_showing){
	
		this.map.report.obj.container.style.display = "none";
		this.map.report.is_showing = 0;
		this.toolbar_report.className = "";
		PSRKMAP.active_map.highLightLegendTab();
	}
};

psharkmap.prototype.displayReport = function(){
	if (this.map.report.obj){
		this.map.report.obj.container.style.display = "block";
		this.map.report.is_showing = 1;
	}
	this.toolbar_report.className = "active";
	this.toolbar_legends.className = "";
};

// global functions and objects

PSRKMAP.setProperty = function(){
	if (!PSRKMAP.active_map)return false;
	var obj_am = PSRKMAP.active_map;
	var zl_a = obj_am.zoomlevel_array
	var c_z = obj_am.current_zoom
	var posx = obj_am.old_x;
	var posy = obj_am.old_y;
	
	if (obj_am.map){
		obj_am.click_coord_x = (posx+obj_am.map_offset_x-obj_am.canvas.borderWidth)/(zl_a[c_z].x_tiles*zl_a[c_z].x_tile_size);
		obj_am.click_coord_y = (posy+obj_am.map_offset_y-obj_am.canvas.borderWidth)/(zl_a[c_z].y_tiles*zl_a[c_z].y_tile_size);
		
		if (zl_a.length-1 == c_z && PSRKMAP.drag_ready && !PSRKMAP.dragging){
			PSRKMAP.drag_ready = false;
			PSRKMAP.dragging = false;
			obj_am.loadReport(obj_am.click_coord_x,obj_am.click_coord_y);
		}
	}
}

PSRKMAP.closeReport = function(){
	PSRKMAP.active_map.toolbar_report.className = "";
	PSRKMAP.active_map.highLightLegendTab();
	PSRKMAP.active_map.map.report.is_showing = 0;
}

//  scalebar section

// psharkmap member functions

psharkmap.prototype.paintScaleBar = function(){
	
	var map_obj = this;
	if (!this.tools.scalebar.el){
	
		// set up the element
		this.tools.scalebar.el = document.createElement("div");
		this.tools.scalebar.el.style.position = "absolute";
		this.tools.scalebar.el.style.display = "none";
		this.tools.scalebar.el.style.textAlign = "center";
		this.tools.scalebar.el.style.zIndex = "900";
		this.tools.scalebar.el.style.padding = "2px";
		this.tools.scalebar.el.style.height = this.tools.scalebar.height+"px";
		this.tools.scalebar.show_details = false;
		
		// add even handlers to the element	
		this.tools.scalebar.el.onmouseover = function(){
			if (!PSRKMAP.dragging){
				this.style.background = " url('"+map_obj.path+"pngw67.png')";
				this.style.cursor = "auto";
			}else{
				this.style.cursor = (document.all) ? "move" : "-moz-dragging";
			}
		};
		this.tools.scalebar.el.onmouseout = function(){
			this.style.background= "none";
		};
		
		// the element exists and can be manipulated
		
		this.displayScaleBarDetails(this.canvas.fullWidth);
		this.map.obj.appendChild(this.tools.scalebar.el);
		this.positionScaleBar();
	}
};

psharkmap.prototype.positionScaleBar = function(){
	if (this.tools.scalebar.el){
		this.positionElement(this.tools.scalebar.el, this.tools.margin+1+"px", this.map.height - this.tools.scalebar.height - this.tools.margin-4+"px");
		this.setScaleBar(this.zoomlevel_array[this.current_zoom].scale,this.map.width/3);
	}
};
	
psharkmap.prototype.displayScaleBarDetails = function(detailed){
	this.tools.scalebar.show_details = detailed;
};
	
psharkmap.prototype.positionElement = function(el, x, y){
	el.style.left = x;
	el.style.top = y;
	el.style.display = "block";
};
	
psharkmap.prototype.setScaleBar = function(){
	// set up array to hold possible levels
	var levels = [];
	levels[0] = {ft: 50, label: "50 ft", units: "feet", divisions: 5};
	levels[1] = {ft: 150, label: "150 ft", units: "feet", divisions: 5};
	levels[2] = {ft: 300, label: "300 ft", units: "feet", divisions: 5};
	levels[3] = {ft: 750, label: "750 ft", units: "feet", divisions: 5};
	levels[4] = {ft: 1500, label: "1500 ft", units: "feet", divisions: 5};
	levels[5] = {ft: 2640, label: "0.5 mi", units: "miles", divisions: 5};
	levels[6] = {ft: 5280, label: "1.0 mi", units: "miles", divisions: 5};
	levels[7] = {ft: 13200, label: "2.5 mi", units: "miles", divisions: 5};
	levels[8] = {ft: 26400, label: "5.0 mi", units: "miles", divisions: 5};
	levels[9] = {ft: 52800, label: "10 mi", units: "miles", divisions: 5};
	levels[10] = {ft: 105600, label: "20 mi", units: "miles", divisions: 5};
	levels[11] = {ft: 264000, label: "50 mi", units: "miles", divisions: 5};
	levels[12] = {ft: 528000, label: "100 mi", units: "miles", divisions: 5};
	levels[13] = {ft: 1056000, label: "200 mi", units: "miles", divisions: 5};
	levels[14] = {ft: 2640000, label: "500 mi", units: "miles", divisions: 5};
				
	// max width depends on screen size and pre-determined max value
	var max_width = Math.min(350,2*this.map.width/3);
	
	var scale = this.zoomlevel_array[this.current_zoom].scale;
	var m = (72*12*3*1760)/scale;
	ft = (72*12)/scale;
	
	var units;
	var txt = "";
	var bar = document.createElement("div");
	

	for (var i=levels.length-1; i>=0; i--){
		
		if (levels[i].ft*ft < max_width){
			bar.style.width = parseInt(levels[i].ft*ft)+20 + "px";
			
			for (var j=0; j < levels[i].divisions; j++){
				img = document.createElement("img")
				img.src = this.path+"scale_divider.gif"
				img.style.width="3px";
				img.style.height="9px";
				img.style.position = "absolute";
				img.style.zIndex = "10";
				img.style.top = "15px";
				img.style.left = j*parseInt(levels[i].ft*ft/levels[i].divisions)+5+"px";
				bar.appendChild(img);
				
				img = document.createElement("img")
				img.src = (j%2==0)?this.path+"scale_dark.gif":this.path+"scale_light.gif";
				img.style.width = parseInt(levels[i].ft*ft/levels[i].divisions)-1 + "px";
				img.style.position = "absolute";
				img.style.zIndex = "12";
				img.style.top = "18px";
				img.style.left = j*parseInt(levels[i].ft*ft/levels[i].divisions)+7+"px";
	
				img.style.height="6px";
				bar.appendChild(img);
				if (j < 2 || this.tools.scalebar.show_details){
					var d = document.createElement("div");
					d.style.width="30px";
					d.style.height="10px";
					d.style.position = "absolute";

					d.style.zIndex = "10";
					d.style.top = "3px";
					d.style.left = j*parseInt(levels[i].ft*ft/levels[i].divisions)-5+"px";
				
					txt = (levels[i].units=="feet") ? j*levels[i].ft/levels[i].divisions : j*levels[i].ft/levels[i].divisions/5280;
					var img = this.getScaleBarLabelScalar(txt);
					d.appendChild(img)
					bar.appendChild(d)
				}
				
			}
			img = document.createElement("img")
			img.src = this.path+"scale_divider.gif"
			img.style.width="3px";
			img.style.height="9px";
			img.style.position = "absolute";
			img.style.zIndex = "10";
			img.style.top = "15px";
			img.style.left = j*parseInt(levels[i].ft*ft/levels[i].divisions)+5+"px";
			bar.appendChild(img);
			var d = document.createElement("div");
			d.style.width="30px";
			d.style.height="10px";
			d.style.position = "absolute";

			d.style.zIndex = "10";
			d.style.top = "3px";
			d.style.left = j*parseInt(levels[i].ft*ft/levels[i].divisions)-5+"px";
			
			txt = (levels[i].units=="feet") ? j*levels[i].ft/levels[i].divisions : j*levels[i].ft/levels[i].divisions/5280;
			var img = this.getScaleBarLabelScalar(txt);
			d.appendChild(img)
			bar.appendChild(d)
			
			
			units = document.createElement("img")
			units.src = this.path+"txt/"+levels[i].units+".gif"
			break;
		}
	
	}
	
	var miles = Math.floor(100*max_width/m)
	
	this.tools.scalebar.el.innerHTML="";
	
	this.tools.scalebar.el.appendChild(bar);
	
	var d = document.createElement("div");
	d.style.position = "absolute";
	d.style.top = "24px";
	d.style.width = bar.style.width;
	d.appendChild(units)
	this.tools.scalebar.el.appendChild(d);

};
	
psharkmap.prototype.getScaleBarLabelScalar = function(n){
	var txt = ""+n;
	var span = document.createElement("span")
	
	for (var i=0; i < txt.length; i++){
		var img = document.createElement("img");
		var n = txt.charAt(i);
		if (n==".")n="point";
		img.src = this.path+"txt/"+n+".gif";
		span.appendChild(img)
	}
	return span;
};

// global functions and objects
//  scroll and zoom section

// psharkmap member functions

psharkmap.prototype.scrollNorth = function(){
	PSRKMAP.active_map = this;
	this.goal_map_offset_x = this.map_offset_x;
	this.goal_map_offset_y = this.map_offset_y-parseInt(this.map.height/2);
	
	this.current_slide_step = 1;

	this.slide_timer = setTimeout(this.centerMapPanelTimed,20);
};

psharkmap.prototype.scrollEast = function(){
	PSRKMAP.active_map = this;
	this.goal_map_offset_x = this.map_offset_x+parseInt(this.map.width/2);
	this.goal_map_offset_y = this.map_offset_y;
	
	this.current_slide_step = 1;

	this.slide_timer = setTimeout(this.centerMapPanelTimed,20);
};

psharkmap.prototype.scrollSouth = function(){
	PSRKMAP.active_map = this;
	this.goal_map_offset_x = this.map_offset_x;
	this.goal_map_offset_y = this.map_offset_y+parseInt(this.map.height/2);
	
	
	this.current_slide_step = 1;

	this.slide_timer = setTimeout(this.centerMapPanelTimed,20);
};

psharkmap.prototype.scrollWest = function(){
	PSRKMAP.active_map = this;
	this.goal_map_offset_x = this.map_offset_x-parseInt(this.map.width/2);
	this.goal_map_offset_y = this.map_offset_y;
	
	this.current_slide_step = 1;

	this.slide_timer = setTimeout(this.centerMapPanelTimed,20);
};

psharkmap.prototype.scrollDistance = function(x,y){
	PSRKMAP.active_map = this;
	this.goal_map_offset_x = this.map_offset_x-x;
	this.goal_map_offset_y = this.map_offset_y-y;
	
	this.current_slide_step = 1;

	this.slide_timer = setTimeout(this.centerMapPanelTimed,20);
};

psharkmap.prototype.mouseWheelZoomIn = function(){
	var z = Math.min(this.zoomlevel_array.length-1,this.current_zoom+1);

	var x = this.nonCenterXForZoom((this.current_x+this.map_offset_x)/(this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size),z);
	var y = this.nonCenterYForZoom((this.current_y+this.map_offset_y)/(this.zoomlevel_array[this.current_zoom].y_tiles*this.zoomlevel_array[this.current_zoom].y_tile_size),z);
	
	this.centerAndZoomMapPanel(x,y,z)
};

psharkmap.prototype.mouseWheelZoomOut = function(){
	var z = Math.max(0,this.current_zoom-1)
	var x = this.nonCenterXForZoom((this.current_x+this.map_offset_x)/(this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size),z);
	var y = this.nonCenterYForZoom((this.current_y+this.map_offset_y)/(this.zoomlevel_array[this.current_zoom].y_tiles*this.zoomlevel_array[this.current_zoom].y_tile_size),z);
	
	this.centerAndZoomMapPanel(x,y,z)
};

psharkmap.prototype.nonCenterXForZoom = function(x,z){
	var px_from_center_x = this.current_x - this.map.width/2;
	return x - px_from_center_x/(this.zoomlevel_array[z].x_tiles*this.zoomlevel_array[z].x_tile_size);
};

psharkmap.prototype.nonCenterYForZoom = function(y,z){
	var px_from_center_y = this.current_y - this.map.height/2;
	return y - px_from_center_y/(this.zoomlevel_array[z].y_tiles*this.zoomlevel_array[z].y_tile_size);
};

psharkmap.prototype.zoomMapPanel = function(){
	var z = parseInt(arguments[0]);
	
	var x = (this.map_offset_x + this.map.width/2) / (this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size);
	var y = (this.map_offset_y + this.map.height/2) / (this.zoomlevel_array[this.current_zoom].y_tiles*this.zoomlevel_array[this.current_zoom].y_tile_size);
	
	if (z != this.current_zoom){
		this.centerAndZoomMapPanel(x,y,z);
	}
};

psharkmap.prototype.zoomInMapPanel = function(){
	var new_zoom = Math.min(this.zoomlevel_array.length-1,this.current_zoom+1)
	
	if (new_zoom != this.current_zoom){
		// we're not at the top zoom layer yet
		// so clear all layers and let's zoom
		// here is where a smooter zoom might be good
		// instead of a jump
//		this.clearMap();
		this.zoomMapPanel(new_zoom);
	}
};

psharkmap.prototype.zoomOutMapPanel = function(){
	var new_zoom = Math.max(0,this.current_zoom-1)
	if (new_zoom != this.current_zoom){
		// we're not at the top zoom layer yet
		// so clear all layers and let's zoom
		// here is where a smooter zoom might be good
		// instead of a jump
//		this.clearMap();
		this.zoomMapPanel(new_zoom);
	}
};

psharkmap.prototype.centerAndZoomMapPanel = function(x, y, z, offset_x, offset_y){

	this.init_view = false;
	
	this.zoom_coord_x = x;
	this.zoom_coord_y = y;
	
	var zoom_update = false;
	if (!isNaN(z)){

		if (this.current_zoom != z){
			this.previous_zoom = this.current_zoom;
			zoom_update = true;
		}
		this.current_zoom = z;
		
		this.old_map_offset_x = this.map_offset_x;
		this.old_map_offset_y = this.map_offset_y;
		this.do_smooth_zoom = (!this.basemapMaxZoomThreshold());

		
		if (this.current_zoom != z)this.clearTileQueue();
	}




	this.map_offset_x = parseInt(x*this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size-parseInt(this.map.width/2));
	this.map_offset_y = parseInt(y*this.zoomlevel_array[this.current_zoom].y_tiles*this.zoomlevel_array[this.current_zoom].y_tile_size-parseInt(this.map.height/2));
	
	if (offset_x){
		this.map_offset_x-=offset_x;
	}
	if (offset_y){
		this.map_offset_y-=offset_y;
	}
	
	
	if (this.map.feature.layer){
		this.resizeAllCanvasLayers(zoom_update);
		if (zoom_update){
			this.map.feature.imagemap_areas = [];
			this.load_canvas_layers_obj = [];
			this.map.feature.imagemap_map.innerHTML = "";
		}
	}


	this.setZoomClass();
	this.loadMapPanel();
	this.setScaleBar();
	this.resizeFocusArea();
	this.resizeHighlightPolygons();
	this.placeMarkers();
//	this.placePOIMarkers();
	this.updateZoomTool();
	this.unlockKeyMap();

	
	if (this.polygonpanel_obj){
		if (this.mode=="polygon" || this.polygonpanel_obj.polygon_completed){
			this.polygonpanel_obj.updatePolygon();
		}
	}
	if (this.view_tracker_function){
		this.view_tracker_function(this.getView());
	}
};

psharkmap.prototype.centerMapPanel = function(x, y, offset_x, offset_y){
	
	this.goal_map_offset_x = parseInt(x*this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size-parseInt(this.map.width/2));
	this.goal_map_offset_y = parseInt(y*this.zoomlevel_array[this.current_zoom].y_tiles*this.zoomlevel_array[this.current_zoom].y_tile_size-parseInt(this.map.height/2));
	
	this.goal_map_offset_x = Math.max(0,Math.min(this.goal_map_offset_x,this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size-this.map.width));
	this.goal_map_offset_y = Math.max(0,Math.min(this.goal_map_offset_y,this.zoomlevel_array[this.current_zoom].y_tiles*this.zoomlevel_array[this.current_zoom].y_tile_size-this.map.height));
	

	if (offset_x){
		this.goal_map_offset_x-=offset_x;
	}
	if (offset_y){
		this.goal_map_offset_y-=offset_y;
	}


	var dx = abs(this.map_offset_x-this.goal_map_offset_x)
	var dy = abs(this.map_offset_y-this.goal_map_offset_y)
	
	if (dx>this.map.width || dy>this.map.height || this.zooming){
		this.centerAndZoomMapPanel(x,y,this.current_zoom,offset_x,offset_y);
	}else{
	
		PSRKMAP.active_map.slide_steps = Math.max(Math.min(parseInt(Math.sqrt(dx*dx+dy*dy))/20,10),4);
		this.current_slide_step = 1;
		this.slide_timer = setTimeout(this.centerMapPanelTimed,10);
	}
};

psharkmap.prototype.centerMapPanelTimed = function(){

	var remaining_steps = PSRKMAP.active_map.slide_steps - PSRKMAP.active_map.current_slide_step;

	if (remaining_steps > 0){
		PSRKMAP.active_map.map_offset_x = parseInt(PSRKMAP.active_map.map_offset_x + (PSRKMAP.active_map.goal_map_offset_x-PSRKMAP.active_map.map_offset_x)/remaining_steps);
		PSRKMAP.active_map.map_offset_y = parseInt(PSRKMAP.active_map.map_offset_y + (PSRKMAP.active_map.goal_map_offset_y-PSRKMAP.active_map.map_offset_y)/remaining_steps);

		PSRKMAP.active_map.loadMapPanel();
//
		PSRKMAP.active_map.current_slide_step++;
//		
	
		PSRKMAP.active_map.slide_timer = setTimeout(PSRKMAP.active_map.centerMapPanelTimed,50);
	}else{
		clearTimeout(PSRKMAP.active_map.slide_timer);
		PSRKMAP.active_map.unlockKeyMap();
	}
};

psharkmap.prototype.zoomOutRight = function(){
	if (this.map.zoom_frame) this.hideRightZoomFrame();
	
	var new_zoom = Math.max(0,this.current_zoom-1)
	
	if (new_zoom != this.current_zoom){
		// we're not at the top zoom layer yet
		// so clear all layers and let's zoom
		// here is where a smooter zoom might be good
		// instead of a jump
		var x = (this.map_offset_x + this.current_x)/(this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size);
		var y = (this.map_offset_y + this.current_y)/(this.zoomlevel_array[this.current_zoom].y_tiles*this.zoomlevel_array[this.current_zoom].y_tile_size);

//		this.clearMap();
		PSRKMAP.dblclick_ready = false
		this.centerAndZoomMapPanel(x,y,new_zoom);
	}
};

psharkmap.prototype.buildRightZoomFrame = function(){
	if (!this.map.zoom_frame){
		this.map.zoom_frame = document.createElement("div");
		this.map.zoom_frame.style.border = "2px solid #000";
		this.map.zoom_frame.style.background = (window.XMLHttpRequest) ? "url("+this.path+"png10.png) 0 0 repeat" : "none";
		this.map.zoom_frame.style.zIndex = 51;
		this.map.zoom_frame.style.position = "absolute";
		this.map.zoom_frame.style.display = "none";
		this.map.root.appendChild(this.map.zoom_frame);
	
	}
};

psharkmap.prototype.showRightZoomFrame = function(sx, sy, ex, ey){
	
	var ax = Math.min(sx,ex);
	var ay = Math.min(sy,ey);
	
	this.map.zoom_frame_width = abs(sx-ex)/(this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size);
	this.map.zoom_frame_height = abs(sy-ey)/(this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size);

	this.map.zoom_frame_center_x = (this.map_offset_x + ax + (abs(sx-ex)/2))/(this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size);
	this.map.zoom_frame_center_y = (this.map_offset_y + ay + (abs(sy-ey)/2))/(this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size); 
	
	if (!this.map.zoom_frame) this.buildRightZoomFrame();
	this.map.zoom_frame.style.left = this.map_offset_x + ax+"px";
	this.map.zoom_frame.style.top = this.map_offset_y + ay+"px";
	this.map.zoom_frame.style.width = abs(sx-ex)+"px";
	this.map.zoom_frame.style.height = abs(sy-ey)+"px";
	this.map.zoom_frame.style.display = "block";

};

psharkmap.prototype.hideRightZoomFrame = function(){
	if (this.map.zoom_frame){
		this.map.zoom_frame.style.display = "none";
		this.map.zoom_frame.style.width = "1px";
		this.map.zoom_frame.style.height = "1px";
	}
	this.map.zoom_frame_center_x = 0;
	this.map.zoom_frame_center_y = 0; 
	this.map.zoom_frame_width = 0;
	this.map.zoom_frame_height = 0;
};

psharkmap.prototype.zoomRightZoomFrame = function(){
	if (this.map.zoom_frame){
		if (this.map.zoom_frame.style.display == "block"){
			for (var i=this.zoomlevel_array.length-1; i>=this.current_zoom; i--){
				var px_width = this.map.zoom_frame_width * (this.zoomlevel_array[i].x_tiles*this.zoomlevel_array[i].x_tile_size);
				var px_height = this.map.zoom_frame_height * (this.zoomlevel_array[i].y_tiles*this.zoomlevel_array[i].y_tile_size);
				if(px_width<=this.map.width && px_height<=this.map.height){
					this.centerAndZoomMapPanel(this.map.zoom_frame_center_x,this.map.zoom_frame_center_y,i);
				}
			}
		}
	}
	this.hideRightZoomFrame();
};

psharkmap.prototype.setZoomClass = function(){
	this.map.obj.className = "";
	if (this.current_zoom==0)this.map.obj.className = "zoom_min";
	if (this.current_zoom==this.zoomlevel_array.length-1)this.map.obj.className = "zoom_max";
};

psharkmap.prototype.getZoom = function(){
	return this.current_zoom;
};

// global functions and objects

// the following functions have same names as psharkmap member functions
// we should use the psharkmap member functions exclusively
	
PSRKMAP.zoomMapPanel = function(map_id,z){
	// is this even in use any more?
	PSRKMAP.active_map = PSRKMAP.arr_mapobjects[map_id];
	PSRKMAP.active_map.zoomMapPanel(z);
}

PSRKMAP.zoomInMapPanel = function(map_id){
	PSRKMAP.active_map = PSRKMAP.arr_mapobjects[map_id];
	PSRKMAP.active_map.zoomInMapPanel();
}
PSRKMAP.zoomOutMapPanel = function(map_id){
	PSRKMAP.active_map = PSRKMAP.arr_mapobjects[map_id];
	PSRKMAP.active_map.zoomOutMapPanel();
}

PSRKMAP.centerMapPanel = function(x,y,offset_x,offset_y){
	PSRKMAP.active_map.centerMapPanel(x,y,offset_x,offset_y);
}

//  search section

// psharkmap member functions

psharkmap.prototype.search = function(){
	//var url = this.path+"search_results.html";
	//this.getRemoteContent(url,null,null,PSRKMAP.getSearchResults,this);
	alert("Error, id: 3");
};

psharkmap.prototype.getSearchResults = function(str){
	var o = eval('(' + str + ')');
	this.search_results = o.search_results;
	this.centerAndZoomMapPanel(.5,.5,0);
	this.placeMarkers();
};

psharkmap.prototype.getSearchResultsFlat = function(str){
	var map_obj = this;
	
	for (var i=0; i < this.search_form.elements.length;i++){
		if (this.search_form.elements[i].type == "submit"){
			this.search_form.elements[i].value = map_obj.search_text;
			this.search_form.elements[i].disabled = "";
		}
	}

	if (this.search_form.debug)
		if (this.search_form.debug.checked)
			Dumper(str);
		
	var pairs = str.split("&");
	
	var mark = [];
	mark.x = -1;
	mark.y = -1;
	mark.address = this.current_search_address;
	
	for(var j=0;j < pairs.length;j++) {
		var key = pairs[j].split("=")[0];
		var val = pairs[j].split("=")[1];
		switch(key) {
			case "x": mark.x = val;break;
			case "y": mark.y = val;break;
		}
	}
	
	if (mark.x<0 || mark.x>1 || mark.x<0 || mark.x>1){
		
		var begin_str = '<!-- LOOKUP BEGIN -->';
		var end_str = '<!-- LOOKUP END -->';

		str = str.substring(str.indexOf(begin_str)+begin_str.length);
		str = str.substring(0, str.indexOf(end_str));
		
		str = str.replace("<li>Click the back button</li>","");

		this.setSearchCommentSection(str);

		var links = this.control.search_comments.getElementsByTagName("a"); 
		for (var i = 0; i < links.length; i++) { 
			links[i].onclick = function(){
				if (map_obj.checkSearchResults(this.innerHTML)) return false;
			
				map_obj.current_search_address = this.innerHTML;
				var url = this.href.replace("/maps/","/mason/Lookup/");
				if (url.indexOf("submit_to")<0)url += "&submit_to=/mason/Maps/mapparams.html?loc="+map_obj.locale;

				var pajax = new psharkmapAJAXobj();
				pajax.setURL(url);
				pajax.setTargetFunction(PSRKMAP.getSearchResultsFlat);
				pajax.pushFunctionArg(map_obj);
				pajax.sendRequest();

				return false;
			}
		}
	}else{
		this.search_results.push(mark);
		
		while (this.search_results.length>5){
			var obj = this.search_results[0].marker;
			if (obj)obj.parentNode.removeChild(obj);
			this.search_results.shift();
		}
	
		var pz = this.zoomlevel_array.length-3;
		
		this.centerMapPanel(mark.x,mark.y);
		this.ShowSearchedForReport(mark.x,mark.y);
		this.control.search_results.innerHTML = "<h3>Search Results</h3>";
		this.generateResultList();

	}
};

psharkmap.prototype.generateResultList = function(){
	for (var i = this.search_results.length-1; i>=0; i--){
		var px = this.search_results[i].x;
		var py = this.search_results[i].y;

		var link = document.createElement("a");
		link.setAttribute("href","javascript:void(0)");
		link.setAttribute("title",i);
		if (i == this.search_results.length-1){
			link.className = "cur";
		}
		link.onclick = function(){
			map_obj.focusMarker(map_obj.search_results[this.title].marker);
			map_obj.centerMapPanel(map_obj.search_results[this.title].x,map_obj.search_results[this.title].y);
			map_obj.ShowSearchedForReport(map_obj.search_results[this.title].x,map_obj.search_results[this.title].y);
		}
		var txt = document.createTextNode(this.search_results[i].address);
		link.appendChild(txt);

		var del = document.createElement("a");
		del.setAttribute("href","javascript:void(0)");
		del.setAttribute("title","Delete");
		del.className = "del";
		del.onclick = function(){
			map_obj.removeMarker(this.parentNode.firstChild.title);
			map_obj.search_results.splice(this.parentNode.firstChild.title,1);
			map_obj.placeMarkers();
			map_obj.control.search_results.innerHTML = "<h3>Search Results</h3>";
			map_obj.generateResultList();
		}

		var div = document.createElement("div");
		div.appendChild(link);
		div.appendChild(del);
		
		this.control.search_results.appendChild(div);
	}
	this.control.search_results.style.display = this.search_results.length ? "block" : "none";
};

psharkmap.prototype.checkSearchResults = function(address){
	for (var i=0; i < this.search_results.length; i++){
		if (this.search_results[i].address == address){
			return true;
		}
	}
	return false;
};

psharkmap.prototype.ShowSearchedForReport = function(px,py,args){
	this.placeMarkers();
	this.hideReport();
	this.loadReport(px,py,args);
	this.hideFocusArea();
};

psharkmap.prototype.setSearchCommentSection = function(str){
	if (this.control.search_comments){
		this.control.search_comments.innerHTML = str;
		this.control.search_comments.style.display = "block";
	}
	this.setSearchPanelSize();
};

psharkmap.prototype.placeMarkers = function(){
	if (this.search_results){

		if (!this.search_results_div){
			this.search_results_div = document.createElement("div");
			this.map.root.appendChild(this.search_results_div);
		}
	
		var map_obj = this;
		var pz = this.zoomlevel_array.length-1;
	
		for (var i = 0; i < this.search_results.length; i++){
			if (!this.search_results[i].marker){
				this.search_results[i].marker = document.createElement("div");
				this.search_results[i].marker.style.position = "absolute";
				this.search_results[i].marker.style.cursor = "default";
				this.search_results[i].marker.style.zIndex = "400";
				this.search_results[i].width = 24;
				this.search_results[i].height = 24;

				this.search_results_div.appendChild(this.search_results[i].marker);
				
				var address = document.createElement("span")
				address.className = "marker_label";
				address.style.position = "absolute";

				address.style.left = this.search_results[i].width+"px";
				
				var a = document.createElement("a");
				a.setAttribute("href","javascript:void(0)");
				a.onclick = function(){
					var id = this.parentNode.parentNode.id;
					map_obj.ShowSearchedForReport(map_obj.search_results[id].x,map_obj.search_results[id].y);
				}

				var txt = document.createTextNode(this.search_results[i].address);
				a.appendChild(txt);
				
				this.search_results[i].marker.onmouseover = function(){
					map_obj.focusMarker(this);
				}
				address.appendChild(a);
				this.search_results[i].marker.appendChild(address);
			}
			
			this.search_results[i].marker.id = i;
			
			if (i == this.search_results.length-1){
				this.search_results[i].marker.className = "current_marker";
			}else{
				this.search_results[i].marker.className = "marker";
			}
			
			this.search_results[i].marker.style.left = this.search_results[i].x * (this.zoomlevel_array[this.current_zoom].x_tiles*this.zoomlevel_array[this.current_zoom].x_tile_size)-this.search_results[i].width/2+"px";
			this.search_results[i].marker.style.top =  this.search_results[i].y * (this.zoomlevel_array[this.current_zoom].y_tiles*this.zoomlevel_array[this.current_zoom].y_tile_size)-this.search_results[i].height/2+"px";
		}
	}
};

psharkmap.prototype.focusMarker = function(cur_marker){
	for (var i=0; i < this.search_results.length; i++){
		if (this.search_results[i].marker){
			this.search_results[i].marker.style.zIndex = (this.search_results[i].marker==cur_marker) ? "401" : "400";
		}
	}
};

psharkmap.prototype.removeMarker = function(id){
	var o = this.search_results[id].marker;
	o.parentNode.removeChild(o);
};

// global functions and objects

PSRKMAP.getSearchResults = function(str,map_obj){
	map_obj.getSearchResults(str);
}

PSRKMAP.getSearchResultsFlat = function(str,map_obj){
	map_obj.getSearchResultsFlat(str);
}

//  toolbar section

// psharkmap member functions

psharkmap.prototype.paintToolbar = function(){
	if (!this.canvas.set_in_layout){
		return;
	}
	if (!this.toolbar){
		this.toolbar = this.cE("div",this.canvas.obj);
		this.toolbar.className = "toolbar";
		this.toolbar.style.border = this.canvas.borderTopWidth + "px " + this.canvas.borderStyle + " " + this.canvas.borderColor;
		this.toolbar.style.borderBottom = "none";
		
		this.toolbar_container = document.createElement("table")
		
		var tbody = document.createElement("tbody")
		var trow=document.createElement("tr");

		this.toolbar_legends=this.cE("td",trow);
		
		this.toolbar_report=this.cE("td",trow);
		this.toolbar_report.className = "disabled";
		this.toolbar_report.style.borderLeft = this.canvas.borderTopWidth + "px " + this.canvas.borderStyle + " " + this.canvas.borderColor;
		this.toolbar_report.onmouseover = function () {
			if (!PSRKMAP.active_map.map.report.report_available) {			
				jsPopupLoad(document.getElementById("load_map_minireport"), 240, 95);
			}	
		}
		this.toolbar_report.onmouseout = function () {
			jsPopupUnload(document.getElementById("load_map_minireport"));
		}
					
		this.toolbar_text=this.cE("td",trow);
		this.toolbar_text.className = "toolbar_info";
		this.toolbar_text.innerHTML = this.header_text;
		this.toolbar_text.style.borderLeft = this.canvas.borderTopWidth + "px " + this.canvas.borderStyle + " " + this.canvas.borderColor;
		
		
		this.toolbar_link=this.cE("td",trow);
		this.toolbar_link.style.borderLeft = this.canvas.borderTopWidth + "px " + this.canvas.borderStyle + " " + this.canvas.borderColor;
		
		this.toolbar_copy_print=this.cE("td",trow);
		this.toolbar_copy_print.style.borderLeft = this.canvas.borderTopWidth + "px " + this.canvas.borderStyle + " " + this.canvas.borderColor;
		this.toolbar_copy_print.style.paddingRight = 2*this.canvas.borderRightWidth + "px";
		
		tbody.appendChild(trow);
		this.toolbar_container.appendChild(tbody);
		this.toolbar.appendChild(this.toolbar_container);
		
		this.toolbar_legends.appendChild(this.addLink("Show Map Legends",PSRKMAP.linkLegends));
		this.toolbar_report.appendChild(this.addLink("Show Mini-Report",PSRKMAP.linkReport));
		this.toolbar_link.appendChild(this.addLink("Link to Current View",PSRKMAP.linkGetLink));
		this.toolbar_copy_print.appendChild(this.addLink("Print/PDF Map",PSRKMAP.linkCopy));
	}
	this.setStyles(this.toolbar,{"width":this.canvas.width-this.canvas.borderLeftWidth-this.canvas.borderRightWidth+"px"});
	this.setStyles(this.toolbar_container,{"width":this.canvas.width+"px"});
};

psharkmap.prototype.setPanelContent = function(obj,header,content,sub_header){
	this.setPanelPlaceAndSize(obj);
	if (!obj.content_set){
		if (typeof(header)=="object"){
			obj.header.appendChild(header);
		}else{
			obj.header.innerHTML = header;
		}

		if (typeof(content)=="object"){
			obj.content.appendChild(content);
		}else{
			obj.content.innerHTML = content;
		}
		
		if (sub_header){
			if (typeof(sub_header)=="object"){
				obj.sub_header.appendChild(sub_header);
			}else{
				obj.sub_header.innerHTML = sub_header;
			}
			obj.sub_header.style.display = "block";
		}

		obj.content_set = true;
		obj.content.style.height="auto";
		obj.content.style.background="#fff";
	}
};

psharkmap.prototype.invalidatePanelContent = function(obj){
	if (obj){
		obj.content_set = false;
	}
};
	
psharkmap.prototype.setPanelAsCurrent = function(obj){
	obj.panel_index = this.current_panels.length;
	this.current_panels.removeValue(obj);
	this.current_panels.push(obj);	
};

psharkmap.prototype.resizePanel = function(){
	if (this.current_panels.length>0){
		for (var i=0; i < this.current_panels.length; i++){
			this.setPanelPlaceAndSize(this.current_panels[i]);
			if (this.current_panels[i].config.resize_fn){
				this.current_panels[i].config.resize_fn();
			}
			this.setPanelPlaceAndSize(this.current_panels[i]);
		}
	}
};

psharkmap.prototype.closeCurrentPanel = function(){
	if (this.current_panels.length>0){
		for (var i=0; i < this.current_panels.length; i++){
			if (!this.current_panels[i].config.stay_open){
				this.current_panels[i].container.style.display = "none";
				if (this.current_panels[i].config.close_fn){
					this.current_panels[i].config.close_fn();
					this.current_panels[i].config.close_fn = null;
				}
			}
		}
	}
};

psharkmap.prototype.closeNamedPanel = function(name){
	if (this.current_panels.length>0){
		for (var i=0; i < this.current_panels.length; i++){
			if (this.current_panels[i].id == name){
				this.closePanel(this.current_panels[i]);

			}
		}
	}
};

psharkmap.prototype.closePanel = function(obj){
	obj.container.style.display = "none";
	if (obj.config.close_fn){
		obj.config.close_fn();
	}
	this.current_panels.removeValue(obj);
};

psharkmap.prototype.showPanel = function(obj){

	if (this.current_panels.length>0 && this.current_panels[this.current_panels.length-1].container!=obj.container){
		this.closeCurrentPanel();
	}
	
	this.setPanelAsCurrent(obj);
	var padding = (obj.config.padding) ? parseInt(obj.config.padding,10) : 0;

	
	if (obj.container.style.display != "block"){
		obj.container.style.display = "block";
		if (obj.config.border){
			obj.content.style.height = Math.max(obj.height - obj.header.offsetHeight - obj.sub_header.offsetHeight - 2*this.canvas.borderWidth - 2*padding,0) + "px";
		}else{
			obj.content.style.height = obj.container.offsetHeight - obj.header.offsetHeight - 2*padding + "px";
		}
	}
};

psharkmap.prototype.paintPanel = function(obj,config,name){
	var map_obj = this;
	if (!obj){
		obj = [];
		obj.config = config;
	
		obj.id = name;
		obj.container = document.createElement("div");
		obj.container.style.zIndex = "999";
		obj.container.style.position="absolute";
		
		var padding = (obj.config.padding) ? parseInt(obj.config.padding,10) : 0;

		obj.container.style.background = (obj.config.background) ? obj.config.background : "#fff";
		obj.container.style.display = "none";
		this.canvas.obj.appendChild(obj.container);
		

		obj.header=document.createElement("div");
		if (!obj.config.no_close_button){
			var a = document.createElement("a");
			a.className = "report_closer";
			a.onclick = function(){
				map_obj.closePanel(obj);
			}
			obj.container.appendChild(a);
		}

		obj.container.appendChild(obj.header);
		obj.sub_header = document.createElement("div");
		obj.sub_header.style.display="none";
		obj.container.appendChild(obj.sub_header);
		
		obj.content = document.createElement("div");
		obj.content.style.overflow = "auto";
		
		obj.container.appendChild(obj.content);
		
		if (padding){
			obj.header.style.padding = padding + "px " + padding + "px 0px " + padding + "px";
			obj.sub_header.style.padding = padding+"px";
			obj.content.style.padding = padding+"px";
		}
	}
	return obj;
};

psharkmap.prototype.setPanelPlaceAndSize = function(obj){
	var borderWidth = (obj.config.border) ? this.canvas.borderWidth : 0;
	var padding = (obj.config.padding) ? parseInt(obj.config.padding,10) : 0;
	var width = 0;
	if (obj.config.width){
		if (obj.config.width.indexOf("px")>0){
			width = parseInt(obj.config.width,10);
		}else if (obj.config.width.indexOf("%")>0){
			width = parseInt(obj.config.width,10)*(this.map.width)/100;
		}
	}else{
		width = this.map.width;
	}
	if (obj.config.height){
		if (obj.config.height.indexOf("px")>0){
			height = parseInt(obj.config.height);
		}else if (obj.config.height.indexOf("%")>0){
			if (obj.config.parent == this.control.obj){
				height = parseInt(obj.config.height,10)*(this.control.height)/100;
			}else{
				height = parseInt(obj.config.height,10)*(this.map.height)/100;
			}
		}
	}else{
		height = this.map.height;
	}

	obj.container.style.width = width+"px";
	obj.container.style.height = height+"px";

	obj.container.style.borderWidth = borderWidth+"px";
	obj.container.style.borderStyle = this.canvas.borderStyle;
	obj.container.style.borderColor = this.canvas.borderColor;
	if (obj.config.valign=="top"){
		obj.container.style.borderWidth = this.canvas.borderTopWidth+"px "+borderWidth+"px "+borderWidth+"px "+borderWidth+"px";
	}

	if (obj.config.align=="right" || obj.config.align=="center"){
		width += 2*borderWidth;
	}else{
		width += 2*borderWidth;
		obj.container.style.borderLeft = "none";
	}
	
	switch (obj.config.align){
		case "right":
			if (obj.config.parent == this.control.obj){
				obj.container.style.left = (this.canvas.set_in_layout) ? this.map.width+this.control.width+this.canvas.left_offset-width+this.canvas.borderLeftWidth+borderWidth+"px" : this.map.width-width+borderWidth+this.canvas.borderWidth+"px";
			}else{
				obj.container.style.left = (this.canvas.set_in_layout) ? this.map.width+this.canvas.left_offset-width+this.canvas.borderLeftWidth+borderWidth+"px" : this.map.width-width+borderWidth+this.canvas.borderWidth+"px";
			}
			break;
		case "center":
			obj.container.style.left = (this.canvas.set_in_layout) ? (this.map.width-width)/2+"px" : (this.map.width-width)/2+this.canvas.borderWidth+"px";
			break;
		default:
			obj.container.style.left = (this.canvas.set_in_layout) ? this.canvas.borderLeftWidth+this.canvas.left_offset+"px" : this.canvas.borderWidth+"px";
			break;
	}
	
	switch (obj.config.valign){
		case "bottom":
			obj.container.style.top = this.getPos(this.map.obj)[1] + this.map.height-height+this.canvas.borderWidth+"px";
			break;
		case "middle":
			obj.container.style.top = this.getPos(this.map.obj)[1] + (this.map.height-height)/2+this.canvas.borderWidth+"px";
			break;
		default:
			obj.container.style.top = (obj.config.border) ? this.getPos(this.map.obj)[1]+"px" : this.getPos(this.map.obj)[1]+this.canvas.borderWidth+"px";
			break;
	}

	obj.height = height + 2*borderWidth;
	if (obj.config.border){
		obj.content.style.height = Math.max(0,obj.height - obj.header.offsetHeight - obj.sub_header.offsetHeight - 2*this.canvas.borderWidth - 2*padding) + "px";
	}else{
		obj.content.style.height = Math.max(0,obj.container.offsetHeight - obj.header.offsetHeight - 2*padding) + "px";
	}
};

psharkmap.prototype.linksForReports = function(){
	var zl_a = this.zoomlevel_array
		var c_z = this.current_zoom
	var posx = 500;
	var posy = 330;
	if (this.old_x){
		posx = this.old_x;
	}
	if (this.old_y){
		posy = this.old_y;
	}
	if (this.map){
		var offset_x = parseInt((this.map.focusarea.x*zl_a[zl_a.length-1].x_tiles*zl_a[zl_a.length-1].x_tile_size)-(this.map.width/2));
		var offset_y = parseInt((this.map.focusarea.y*zl_a[zl_a.length-1].y_tiles*zl_a[zl_a.length-1].y_tile_size)-(this.map.height/2));
		this.click_coord_x = (posx+offset_x-this.canvas.borderWidth)/(zl_a[zl_a.length-1].x_tiles*zl_a[zl_a.length-1].x_tile_size);
			this.click_coord_y = (posy+offset_y-this.canvas.borderWidth)/(zl_a[zl_a.length-1].y_tiles*zl_a[zl_a.length-1].y_tile_size);
	}
	var xx = this.map.focusarea.x*zl_a[zl_a.length-1].x_tile_size*zl_a[zl_a.length-1].x_tiles;
	var yy = this.map.focusarea.y*zl_a[zl_a.length-1].y_tile_size*zl_a[zl_a.length-1].y_tiles;
	var x_tile = parseInt(xx / zl_a[zl_a.length-1].x_tile_size);
	var y_tile = parseInt(yy / zl_a[zl_a.length-1].y_tile_size);
	var x_pixel = xx - x_tile * zl_a[zl_a.length-1].x_tile_size;
	var y_pixel = yy - y_tile * zl_a[zl_a.length-1].y_tile_size;  		
	return "&xtile="+x_tile+"&ytile="+y_tile+"&xpixel="+x_pixel+"&ypixel="+y_pixel;
};

psharkmap.prototype.setLinksMenu = function(){
	this.canvas.has_linksmenu = 1;
};


// global functions and objects

PSRKMAP.setLL = function(res) {
	if (!PSRKMAP.active_map)return false;
	var str = PSRKMAP.active_map.getView();
	var href = window.location.href.split("#")[0]
	href = href.split("?")[0]
	href += "?"+str;
	
	href += '&'+res;
	
	PSRKMAP.active_map.closeCurrentPanel();
	
	var id = PSRKMAP.active_map.psharkmap_id+"_getlink";
	
	PSRKMAP.active_map.invalidatePanelContent(PSRKMAP.active_map.linkPanel);
	
	PSRKMAP.active_map.linkPanel = PSRKMAP.active_map.paintPanel(PSRKMAP.active_map.linkPanel,{"width":"340px", "height":"110px", "align":"right", "valign":"top", "border":"yes", "padding":"5px", "stay_open":true,"close_fn":PSRKMAP.closeLinkPanel, "parent":PSRKMAP.active_map.control.obj},"linksPanel");
	PSRKMAP.active_map.setPanelContent(PSRKMAP.active_map.linkPanel,"<h3>Link to current map view</h3>","<br /><input type='text' id='"+id+"' value='"+href+"' style='width:316px;' /><br /><br /><a href='"+href+"'>Load current map view</a>","");

	PSRKMAP.active_map.showPanel(PSRKMAP.active_map.linkPanel);
	PSRKMAP$(id).focus();
   	PSRKMAP$(id).select();
}

PSRKMAP.GetLL = function() {
	//get the current x, y and send them to projection component to get lat long
	var map_obj = PSRKMAP.active_map;
	map_obj.ll = '';

	var zl_a = map_obj.zoomlevel_array
	var c_z = map_obj.current_zoom
	
	var location_x = ((map_obj.map_offset_x+map_obj.map.width/2))/(zl_a[c_z].x_tiles*zl_a[c_z].x_tile_size);		
	var location_y = ((map_obj.map_offset_y+map_obj.map.height/2))/(zl_a[c_z].y_tiles*zl_a[c_z].y_tile_size);		
	var url = "/mason/Maps/components/projection.html?map="+map_obj.locale+"&x="+location_x+"&y="+location_y;
	var pajax = new psharkmapAJAXobj();
	pajax.setURL(url);
	pajax.setTargetFunction(PSRKMAP.setLL);
	pajax.sendRequest();
}

PSRKMAP.linkGetLink = function(){
	var map_obj = PSRKMAP.active_map;
	if (!map_obj){
		return;
	}
	map_obj.toolbar_link.className = "active";
	PSRKMAP.GetLL();
}

PSRKMAP.closeLinkPanel = function(){
	var map_obj = PSRKMAP.active_map;
	if (!map_obj){
		return;
	}
	map_obj.toolbar_link.className = "";
}

PSRKMAP.linkMapOptions = function(){
	var map_obj = PSRKMAP.active_map;
	if (map_obj.control.width == map_obj.control.narrow_width){
		map_obj.control.width = map_obj.control.wide_width;
	} else {
		map_obj.control.width = map_obj.control.narrow_width;
	}
	
	if (map_obj.control.searchpanel){
		map_obj.control.searchpanel.stored_visibility = map_obj.control.searchpanel.style.visibility;
		map_obj.control.searchpanel.style.visibility = "hidden";
	}

	map_obj.closeCurrentPanel();
	map_obj.setPanelAsCurrent(map_obj.control.themesPanel)
	map_obj.showPanel(map_obj.control.themesPanel);
	map_obj.resizePanel();
	map_obj.repaint();
}

PSRKMAP.CtrlPanel_toggle = function(){
	var map_obj = PSRKMAP.active_map;
	if (map_obj.control.width == map_obj.control.toggle_width + map_obj.canvas.borderWidth){
		map_obj.control.width = map_obj.control.narrow_width;
		map_obj.control.ctrlpanel_toggle.style.backgroundPosition = "0px 50%";
		map_obj.control.ctrlpanel_toggle.style.borderRight = "0px none";
		map_obj.control.ctrlpanel_toggle.title = "Hide Control Panel";
	} else {
		map_obj.control.width = map_obj.control.toggle_width + map_obj.canvas.borderWidth;
		map_obj.control.ctrlpanel_toggle.style.backgroundPosition = "-" + map_obj.control.toggle_width + "px 50%";
		map_obj.control.ctrlpanel_toggle.style.borderRight = map_obj.canvas.borderWidth + "px " + map_obj.canvas.borderStyle + " " + map_obj.canvas.borderColor;
		map_obj.control.ctrlpanel_toggle.title = "Show Control Panel";
	}
	
	map_obj.resizePanel();
	map_obj.repaint();
}


PSRKMAP.linkMapOptionsAdjust = function(){
	PSRKMAP.active_map.map_options_intro.style.width = Math.max(0,parseInt(PSRKMAP.active_map.map_options_table.offsetWidth)-PSRKMAP.active_map.getScrollerWidth())+"px";
	PSRKMAP.active_map.map_options_intro.style.margin = "0px auto 0px "+parseInt(PSRKMAP.active_map.map_options_table.offsetLeft)+"px";
	PSRKMAP.active_map.map_options_header.style.width = Math.max(0,parseInt(PSRKMAP.active_map.map_options_table.offsetWidth)-PSRKMAP.active_map.getScrollerWidth())+"px";
	PSRKMAP.active_map.map_options_header.style.margin = "0px auto 0px "+parseInt(PSRKMAP.active_map.map_options_table.offsetLeft)+"px";
}

PSRKMAP.linkCopy = function(){
	if (!PSRKMAP.active_map)return false;
	PSRKMAP.active_map.setView();
	var str = PSRKMAP.active_map.getView();
	window.location.href = "/mason/Maps/imagepage.html?"+str+PSRKMAP.active_map.linksForReports();
	return false;
}


PSRKMAP.linkPrint = function(){
	if (!PSRKMAP.active_map)return false;
	PSRKMAP.active_map.setView();
	var str = PSRKMAP.active_map.getForCopy();
	window.location.href = "/mason/Maps/imagepage_old.html?"+str;
	return false;
}

PSRKMAP.linkReport = function(){
	var map_obj = PSRKMAP.active_map;
	if (!map_obj)return false;
	if (map_obj.map.report.report_available){
		map_obj.displayReport();
	}
}


PSRKMAP.linkFullReport = function(){
	var map_obj = PSRKMAP.active_map;
	if (!map_obj)return false;
	map_obj.setView();
	if (map_obj.map.report.report_available){
		window.location.href ="/mason/Maps/fullreport.html"+map_obj.linksForReports();
	}
	return false;
}


/* *************************************************************************************************
   * removed by Jens, 12/26/08
   * believed to not be in use any more
   *************************************************************************************************
psharkmap.prototype.paintLinksMenu = function(){

	if (!this.canvas.has_linksmenu) return;
	
	if (!this.tools.linksmenu.obj){
		this.tools.linksmenu.obj = document.createElement("div");
		this.tools.linksmenu.obj.style.position = "absolute";
		//this.tools.linksmenu.obj.style.height = this.tools.linksmenu.height+"px";
		this.tools.linksmenu.obj.style.width = this.tools.linksmenu.width+"px";
		this.tools.linksmenu.obj.style.borderWidth = this.canvas.borderWidth + "px";
		this.tools.linksmenu.obj.style.borderStyle = "solid";
		this.tools.linksmenu.obj.style.borderColor = this.canvas.borderColor;
		this.tools.linksmenu.obj.style.background = "url('psharkmap/png20.png')";
		this.tools.linksmenu.obj.style.visibility = "hidden";
		this.canvas.obj.appendChild(this.tools.linksmenu.obj);

		this.tools.linksmenu.obj.ondblclick = function(){ return false; }
		
		this.tools.linksmenu.obj.onmouseover = function(){
			if (PSRKMAP.dragging){
				this.style.cursor = (document.all) ? "move" : "-moz-grabbing";
			}
			this.style.background = "#fff";
		}			
		this.tools.linksmenu.obj.onmouseout = function(){
			this.style.background = "url('psharkmap/png20.png')";
		}
		
		var arr_links = new Array();
		if (this.position_from_url){
			arr_links[0] = new Array();
			arr_links[0].text = "Link";
			arr_links[0].fn = this.linkGetLink;
		}
		
		var map_obj = this;
		
		for (var i=0; i < arr_links.length; i++){
			var a = document.createElement("a");
			a.setAttribute("href","javascript:void(0);");
			var txt = document.createTextNode(arr_links[i].text);
			a.appendChild(txt);
			var fn = arr_links[0].fn;
			a.onclick = function(){
				PSRKMAP.active_map = map_obj;
				fn();
			}
			this.tools.linksmenu.obj.appendChild(a);
		}
		

	}

	this.positionLinksMenu();
	this.tools.linksmenu.obj.style.visibility = "visible";
}

psharkmap.prototype.positionLinksMenu = function(){
	if (this.tools.linksmenu.obj){
		this.tools.linksmenu.obj.style.top = this.getPos(this.canvas.obj)[1] + this.tools.margin+"px";
		if (this.canvas.hasControlPanel){
			this.tools.linksmenu.obj.style.left = this.getPos(this.canvas.obj)[0] + this.canvas.borderWidth + this.map.width - this.tools.zoom_tool.width - this.tools.margin - 2*this.canvas.borderWidth - this.tools.margin - this.tools.linksmenu.width + "px";
		}else{
			this.tools.linksmenu.obj.style.left = this.getPos(this.canvas.obj)[0] + this.canvas.width - this.tools.zoom_tool.width - this.tools.margin + "px";
		}
	}

}

PSRKMAP.linkFindComps = function(){
	var map_obj = PSRKMAP.active_map;
	if (!map_obj)return false;
	map_obj.setView();
	if (map_obj.map.report.report_available){
		window.location.href ="/mason/Maps/findcomps.html"+map_obj.linksForReports();
	}
	return false;
}

PSRKMAP.linkOld = function(){
	if (!PSRKMAP.active_map)return false;
	PSRKMAP.active_map.setView();
	var str = PSRKMAP.active_map.getView();
	window.location.href = "/maps/index.html?"+str+"&force=1";
	return false;
}

PSRKMAP.linkAPI = function(){
	if (!PSRKMAP.active_map)return false;
	PSRKMAP.active_map.setView();
	alert("linkAPI");
}

PSRKMAP.linkHome = function(){
	if (!PSRKMAP.active_map)return false;
	PSRKMAP.active_map.setView();
	window.location.href="/";
	return false;
}
  ************************************************************************************************
  * end removed stuff
  ************************************************************************************************
*/

//  zoom map section

// psharkmap member functions

psharkmap.prototype.paintZoomMap = function(){
	if (!this.map.zoom_map_layer){
		this.map.zoom_map_layer = document.createElement("div");
		this.map.zoom_map_layer.style.position="absolute";
		this.map.zoom_map_layer.style.top = 0;
		this.map.zoom_map_layer.style.left = 0;
		this.map.zoom_map_layer.style.zIndex = 9;
		this.map.root.appendChild(this.map.zoom_map_layer);
	}
};

psharkmap.prototype.clearZoomMapLayer = function(){
	if (this.map.zoom_map_layer){
		this.map.zoom_map_layer.innerHTML = "";
	}
}


psharkmap.prototype.setZoomMapLayer = function(prev_z,cur_z, old_map_offset_x,old_map_offset_y){
	var map_obj = this;
	if (!this.map.zoom_map_layer) this.paintZoomMap();
	this.clearZoomMapLayer();
	this.zooming=true;

	if (old_map_offset_x>=0 && old_map_offset_y>=0 && prev_z>=0){
		//alert(1)
		
		if (prev_z<cur_z){
		
			this.map.base_map_layer.style.display="none";
			this.map.zoom_map_layer.style.display = "block"
				
			var left_tile_n = Math.floor(old_map_offset_x/this.zoomlevel_array[prev_z].x_tile_size);
			var right_tile_n = Math.ceil((old_map_offset_x+this.map.width)/this.zoomlevel_array[prev_z].x_tile_size);
			var top_tile_n = Math.floor(old_map_offset_y/this.zoomlevel_array[prev_z].y_tile_size);
			var bottom_tile_n = Math.ceil((old_map_offset_y+this.map.height)/this.zoomlevel_array[prev_z].y_tile_size);
	
			for (var x = Math.max(left_tile_n,0); x <= Math.min(right_tile_n,this.zoomlevel_array[prev_z].x_tiles-1); x++){
				for (var y = Math.max(top_tile_n,0); y <= Math.min(bottom_tile_n,this.zoomlevel_array[prev_z].y_tiles-1); y++){
					var d = -1;
					var img_id = this.map_id+"-"+this.current_basemap.replace("_","").replace("/","")+"-i_"+prev_z+"_"+d+"_"+x+"_"+y;
					var img = PSRKMAP$(this.map_id+"-"+this.current_basemap.replace("_","").replace("/","")+"-i_"+prev_z+"_"+d+"_"+x+"_"+y);
					if (img){
						this.map.zoom_map_layer.appendChild(img);
						img.className = "zoom"
					}else{
						//alert("not found: "+ img_id)
					}
				}
			}

			this.map.base_map_layer.innerHTML="";
			var zoom_factor = this.zoomlevel_array[cur_z].x_tiles / this.zoomlevel_array[prev_z].x_tiles

			var delta_x = this.zoom_coord_x*this.zoomlevel_array[prev_z].x_tile_size*this.zoomlevel_array[prev_z].x_tiles - (old_map_offset_x+this.map.width/2)
			var delta_y = this.zoom_coord_y*this.zoomlevel_array[prev_z].y_tile_size*this.zoomlevel_array[prev_z].y_tiles - (old_map_offset_y+this.map.height/2)

		
			var tile_center_x = ((old_map_offset_x+this.map.width/2)/this.zoomlevel_array[prev_z].x_tile_size)-left_tile_n;
			var tile_center_y = ((old_map_offset_y+this.map.height/2)/this.zoomlevel_array[prev_z].y_tile_size)-top_tile_n;

			var center_x=(this.zoom_coord_x*this.zoomlevel_array[this.current_zoom].x_tile_size*this.zoomlevel_array[this.current_zoom].x_tiles)
			var center_y=(this.zoom_coord_y*this.zoomlevel_array[this.current_zoom].y_tile_size*this.zoomlevel_array[this.current_zoom].y_tiles)

			var steps = 4
			var step = (prev_z<cur_z)?0:steps;
			
			map_obj.zoomLayerZoom(zoom_factor,step,steps,left_tile_n,right_tile_n,top_tile_n,bottom_tile_n,this.previous_zoom,delta_x,delta_y,tile_center_x,tile_center_y,center_x,center_y);
			
		}
	}
};

psharkmap.prototype.zoomLayerZoom = function(total_zoom_factor,step,steps,left_tile_n,right_tile_n,top_tile_n,bottom_tile_n,z,delta_x,delta_y,tile_center_x,tile_center_y,center_x,center_y){

	var zoom_factor = 1 + (total_zoom_factor-1)*step/steps;
	var map_obj = this;
			
	var left_offset_max=0;
	var top_offset_max=0;		
	var left_offset_min=0;
	var top_offset_min=0;
	var init=1;

	for (var x = Math.max(left_tile_n,0); x <= Math.min(right_tile_n,this.zoomlevel_array[z].x_tiles-1); x++){
		var x_tiles = right_tile_n - left_tile_n+1;
		var center_offset_x =  x - tile_center_x-Math.max(left_tile_n,0);
		var tile_width = this.zoomlevel_array[z].x_tile_size*zoom_factor

		for (var y = Math.max(top_tile_n,0); y <= Math.min(bottom_tile_n,this.zoomlevel_array[z].y_tiles-1); y++){
			var d = -1;
			var img_id = this.map_id+"-"+this.current_basemap.replace("_","").replace("/","")+"-i_"+z+"_"+d+"_"+x+"_"+y;
				
			var img = PSRKMAP$(this.map_id+"-"+this.current_basemap.replace("_","").replace("/","")+"-i_"+z+"_"+d+"_"+x+"_"+y);


			if (img){

				img.style.width = this.zoomlevel_array[z].x_tile_size*zoom_factor + "px";
				img.style.height = this.zoomlevel_array[z].y_tile_size*zoom_factor + "px";
				


				var y_tiles = bottom_tile_n - top_tile_n+1;
				var center_offset_y =  y - tile_center_y - Math.max(top_tile_n,0);
				var tile_height = this.zoomlevel_array[z].y_tile_size*zoom_factor

				img.style.left = center_x+center_offset_x*tile_width+"px";					
				img.style.top = center_y+center_offset_y*tile_height+"px";

				if(init){
					left_offset_min=center_x+center_offset_x*tile_width;
					top_offset_min=center_y+center_offset_y*tile_height;
					init=0;
				}
				
			}else{
				//alert("not found: "+img_id)
			}
		}
	}

	this.map.zoom_map_layer.style.left = -1*Math.min(delta_x*total_zoom_factor*step/steps,left_offset_min)+"px"
	this.map.zoom_map_layer.style.top = -1*Math.min(delta_y*total_zoom_factor*step/steps,top_offset_min)+"px"


	if (step==steps){
		this.zooming=false;
		this.map.base_map_layer.style.display="block";
		return;
	}
	
	
	if (step<steps){
	//if (step<steps && (confirm("continue?"))){
	this.map.base_map_layer.style.display="none"
		step++;
		PSRKMAP.smooth_zoom_timer = setTimeout(function(){map_obj.zoomLayerZoom(total_zoom_factor,step,steps,left_tile_n,right_tile_n,top_tile_n,bottom_tile_n,z,delta_x,delta_y,tile_center_x,tile_center_y,center_x,center_y)},10);
	}
};

// global functions and objects

//  zoom tool section

// psharkmap member functions

psharkmap.prototype.paintZoomTool = function(){
	if (this.no_zoom){
		return;
	}	
	if (!this.tools.zoom_tool.obj){
		this.tools.zoom_tool.obj = document.createElement("div");
		this.tools.zoom_tool.slider_maxheight = this.tools.zoom_tool.slider_height;
		this.tools.zoom_tool.slider_minheight = 8;

		this.tools.zoom_tool.height = this.zoomlevel_array.length*this.tools.zoom_tool.slider_maxheight+2*33+11+42;
		
		var tool = document.createElement("div")
		this.setStyles(tool,{"width":this.tools.zoom_tool.width+"px","padding":"11px 0"});
		this.tools.zoom_tool.obj.appendChild(tool)
		
		var zoom_out_obj = document.createElement("div");
		this.setStyles(zoom_out_obj,{"padding":"0 11px","margin":"0"});
		

		var zoom_label = document.createElement("div")
		zoom_label.innerHTML = "zoom";
		
		this.setStyles(zoom_label,{"margin":"-10px -10px 4px -10px", "color":"#000", "textAlign":"center", "font":"bold 11px arial", "padding":"1px 1px 1px 1px"});
		
		var a = document.createElement("a");
		a.setAttribute("href","javascript:void(0)");
		a.setAttribute("title","Zoom Out");
		this.setStyles(a,{"border":"none", "width":"20px", "height":"20px", "display":"block"});
		
		if (document.all){
			a.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.path+"zoom_minus.png', sizingMethod=\'scale\')"
		}else{
			a.style.background = "url('"+this.path+"zoom_minus.png') 50% 50% no-repeat";
		}
		
		var map_obj = this;
		a.onclick = function(){
			map_obj.zoomOutMapPanel();
		}
		
		a.onmouseover = function(){
			if (PSRKMAP.dragging) this.style.cursor = (document.all) ? "move" : "-moz-grabbing";
		}
		
		zoom_out_obj.appendChild(a);
		tool.appendChild(zoom_out_obj);
	
		this.tools.zoom_tool.zoom_ticks = document.createElement("div");
		if (this.tools.zoom_tool.micro){	
			this.setStyles(this.tools.zoom_tool.zoom_ticks,{"height":"1px", "background":"url('"+this.path+"zoom_level.png') 50% 50% no-repeat"});
		}else{
			this.setStyles(this.tools.zoom_tool.zoom_ticks,{"padding":"0", "margin":"0", "width":"42px"});
			for (var i=0; i < this.zoomlevel_array.length; i++){
				var a = document.createElement("a");
				a.setAttribute("href","javascript:void(0)");
				a.setAttribute("title","Zoom Level "+i);
				this.setStyles(a,{"border":"none", "padding":"0", "width":"42px", "height":this.tools.zoom_tool.slider_maxheight+"px", "display":"block", "background":"url('"+this.path+"zoom_level.png') 50% 50% no-repeat"});
				
				var img = document.createElement("img");
				img.src = ""+this.path+"clear.gif";
				img.style.border = "none";
				a.appendChild(img);

				var map_obj = this;
				a.onmousedown = function(){
					map_obj.zoomMapPanel(this.title.replace("Zoom Level ",""));
					return false;
				}
				a.onmouseover = function(){
					if (PSRKMAP.dragging){
						this.style.cursor = (document.all) ? "move" : "-moz-grabbing";
					}
				}
				this.tools.zoom_tool.zoom_ticks.appendChild(a);
			}
		}			
		this.tools.zoom_tool.zoom_ticks.style.position = "relative";

		tool.appendChild(this.tools.zoom_tool.zoom_ticks);
		
		var zoom_in_obj = document.createElement("div");

		zoom_in_obj.style.padding = "0 11px";
		zoom_in_obj.style.margin = "0";
		var a = document.createElement("a");
		a.setAttribute("href","javascript:void(0)");
		a.setAttribute("title","Zoom In");
		this.setStyles(a,{"border":"none", "width":"20px", "height":"20px", "display":"block"});


		if (document.all){
			a.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.path+"zoom_plus.png', sizingMethod=\'scale\')"
		}else{
			a.style.background = "url('"+this.path+"zoom_plus.png')";
		}

		var map_obj = this;
		a.onclick = function(){
			map_obj.zoomInMapPanel();
		}
		
		a.onmouseover = function(){
			if (PSRKMAP.dragging){
				this.style.cursor = (document.all) ? "move" : "-moz-grabbing";
			}
		}

		zoom_in_obj.appendChild(a);
		tool.appendChild(zoom_in_obj);
		
		this.tools.zoom_tool.widget = this.cE("div");
		this.setStyles(this.tools.zoom_tool.widget,{"width":"42px", "height":"42px", "marginTop":"4px", "position":"relative", "display":"none"});
		this.tools.zoom_tool.widget.style.background = (window.XMLHttpRequest) ? "url('"+this.path+"center.png')" : "url('"+this.path+"center.gif')";
		tool.appendChild(this.tools.zoom_tool.widget);
		
		var ctls = [];
		ctls[0] = {w:18,h:11,t:0,l:12,title:"Scroll Up",oc:function(){ map_obj.scrollNorth();return false; }};
		ctls[1] = {w:11,h:18,t:12,l:31,title:"Scroll Right",oc:function(){ map_obj.scrollEast();return false; }};
		ctls[2] = {w:18,h:11,t:31,l:12,title:"Scroll Down",oc:function(){ map_obj.scrollSouth();return false; }};
		ctls[3] = {w:11,h:18,t:12,l:0,title:"Scroll Left",oc:function(){ map_obj.scrollWest();return false; }};
		ctls[4] = {w:18,h:18,t:12,l:12,title:"Re-Center",oc:function(){ map_obj.centerMapPanel(map_obj.init_center_x,map_obj.init_center_y);return false; }};

		for (var c=0;c<ctls.length;c++){
			var ctl = document.createElement("a");
			this.setStyles(ctl,{"display":"block", "position":"absolute", "width":ctls[c].w+"px", "height":ctls[c].h+"px", "top":ctls[c].t+"px", "left":ctls[c].l+"px"});
			
			ctl.setAttribute("href","javascript:void(0)");
			ctl.setAttribute("title",ctls[c].title);
			ctl.onclick = ctls[c].oc;
			this.tools.zoom_tool.widget.appendChild(ctl);
		}

		
		this.tools.zoom_tool.obj.style.position = "absolute";
		this.tools.zoom_tool.obj.style.width = this.tools.zoom_tool.width-22+"px";

		this.tools.zoom_tool.obj.style.zIndex = "900";
		this.tools.zoom_tool.obj.style.visibility = "hidden";
		
		tool.style.background = "url('"+this.path+"png20.png')";
		
		this.tools.zoom_tool.obj.onmouseover = function(){
			if (PSRKMAP.dragging){
				this.style.cursor = (document.all) ? "move" : "-moz-grabbing";
				map_obj.displayMaxMin(this);
			}
		}
	
		this.paintZoomSlider();
		this.tools.zoom_tool.obj.appendChild(tool);
		this.canvas.obj.appendChild(this.tools.zoom_tool.obj);
	
	}

	this.positionZoomTool();
	this.tools.zoom_tool.obj.oncontextmenu = function(){return false};
	this.tools.zoom_tool.obj.onselectstart = function(){return false};
	this.tools.zoom_tool.obj.style.visibility = "visible";
};

psharkmap.prototype.paintZoomSlider = function(){

	if (this.tools.zoom_tool.micro || this.no_zoom){
		return false;
	}
	this.tools.zoom_tool.slider = document.createElement("div");
	this.tools.zoom_tool.slider.style.margin = "0";
	this.tools.zoom_tool.slider.style.padding = "0";
	this.tools.zoom_tool.slider.style.width = "42px";
	this.tools.zoom_tool.slider.style.height = this.tools.zoom_tool.slider_height + "px";
	this.tools.zoom_tool.slider.style.zIndex = "102";
	
	this.tools.zoom_tool.slider.onmouseover = function(){
		if (PSRKMAP.dragging){
			this.style.cursor = (document.all) ? "move" : "-moz-grabbing";
		}
	}

	this.tools.zoom_tool.slider.style.background = "url('"+this.path+"zoom_level_on.png') 50% 50% no-repeat";
	
	this.tools.zoom_tool.slider.style.position = "absolute";
	
	this.tools.zoom_tool_slider_x = 0;
	this.tools.zoom_tool_slider_y = this.current_zoom * this.tools.zoom_tool.slider_height;		
	
	this.tools.zoom_tool.slider.style.top = this.tools.zoom_tool_slider_y+"px";
	this.tools.zoom_tool.slider.style.left = this.tools.zoom_tool_slider_x+"px";
	
	var img = document.createElement("img");
	img.src = this.path+"clear.gif";
	img.style.border = "none";
	this.tools.zoom_tool.slider.appendChild(img);
	
	this.tools.zoom_tool.zoom_ticks.appendChild(this.tools.zoom_tool.slider);

	if (this.tools.zoom_tool.slider){
		this.tools.zoom_tool.slider.style.cursor = (document.all) ? "move" : "-moz-grab";
		var map_obj = this;
		this.tools.zoom_tool.slider.onmousedown = function(){
			PSRKMAP.map_drag = true;
			map_obj.slideZoom(arguments[0]);
			map_obj.tools.zoom_tool.slider.style.cursor = (document.all) ? "move" : "-moz-grabbing";
		}
		this.tools.zoom_tool.slider.onmouseup = function(){
			map_obj.tools.zoom_tool.slider.style.cursor = (document.all) ? "move" : "-moz-grab";
			PSRKMAP.map_drag = false;
		}
		this.tools.zoom_tool.slider.onclick = function(){
			return false;
		}
	}
	

};

psharkmap.prototype.setSlider = function(){
	if (this.tools.zoom_tool.micro || this.no_zoom){
		return false;
	}
	var new_zoom = 0;
	if (this.tools.zoom_tool_slider_cur_y>this.tools.zoom_tool_slider_click_y){
		new_zoom = parseInt(this.current_zoom) + parseInt((this.tools.zoom_tool_slider_cur_y-this.tools.zoom_tool_slider_click_y+(this.tools.zoom_tool.slider_height/2))/this.tools.zoom_tool.slider_height);
	}else{
		new_zoom = parseInt(this.current_zoom) + parseInt((this.tools.zoom_tool_slider_cur_y-this.tools.zoom_tool_slider_click_y-(this.tools.zoom_tool.slider_height/2))/this.tools.zoom_tool.slider_height);
	}
	
	new_zoom = Math.max(0,Math.min(this.zoomlevel_array.length-1,new_zoom));
	this.tools.zoom_tool_slider_y = new_zoom*this.tools.zoom_tool.slider_height;
	this.zoomMapPanel(new_zoom);
	this.tools.zoom_tool.slider.style.top = this.tools.zoom_tool_slider_y + "px";
};

psharkmap.prototype.slideZoom = function(){
	if (this.tools.zoom_tool.micro || this.no_zoom){
		return false;
	}

	var e = arguments[0];
	if(!e) e = window.event;
	
	PSRKMAP.active_map = this;
	
	var event_pos_obj = this.getEventPosObj(e);
	var posy = event_pos_obj.y-this.canvas_offset_y;
	
	this.tools.zoom_tool_slider_click_y = posy;
	this.tools.zoom_tool_slider_old_y = posy;
	PSRKMAP.sliding = true;
};
	
psharkmap.prototype.positionZoomTool = function(){
	if (this.tools.zoom_tool.obj){
		if (this.canvas.set_in_layout){
			this.tools.zoom_tool.obj.style.left = this.map.width+this.canvas.left_offset+this.canvas.borderLeftWidth - this.tools.zoom_tool.width - this.tools.margin + "px";
			this.tools.zoom_tool.obj.style.top = this.getPos(this.map.obj)[1]+this.canvas.borderTopWidth + this.tools.margin + "px";
		}else if (!this.map.relative){
			this.tools.zoom_tool.obj.style.top = this.tools.margin + "px";
			if (this.canvas.hasControlPanel){
				this.tools.zoom_tool.obj.style.left = this.map.width - this.tools.zoom_tool.width - this.tools.margin + "px";
			}else{
				this.tools.zoom_tool.obj.style.left = this.map.width - this.tools.zoom_tool.width - this.tools.margin + "px";
			}
		}else{
			this.setZoomToolOffset()
			this.tools.zoom_tool.obj.style.padding = (this.tools.zoomtool_offset_y)+"px 0px 0px "+(this.tools.zoomtool_offset_x)+"px";
			this.tools.zoom_tool.obj.style.clip = "rect("+(this.tools.zoomtool_offset_y)+"px "+(this.tools.zoomtool_offset_x+this.tools.zoom_tool.width)+"px "+(this.tools.zoomtool_offset_y+this.tools.zoom_tool.height)+"px "+(this.tools.zoomtool_offset_x)+"px)";
		}
		if (this.tools.keymap.el) {
			var overlap = (this.tools.zoom_tool.obj.offsetHeight+this.tools.keymap.height+3+2*this.tools.margin)-this.map.height;
			var widget_room = 42;
			if (this.tools.zoom_tool.widget.style.display=="none"){
				overlap+= 42;
			}
			
			var tick_room = (this.tools.zoom_tool.slider_height-this.tools.zoom_tool.slider_minheight)*this.tools.zoom_tool.zoom_ticks.childNodes.length;
			if (tick_room<overlap){
				this.tools.zoom_tool.widget.style.display = "none";
				overlap -= 42;
			}else{
				this.tools.zoom_tool.widget.style.display = "block";
			}
			if(overlap>(this.tools.zoom_tool.slider_height-this.tools.zoom_tool.slider_maxheight)*this.tools.zoom_tool.zoom_ticks.childNodes.length || this.tools.zoom_tool.slider_height < this.tools.zoom_tool.slider_maxheight){
				var tick_height = this.tools.zoom_tool.slider_height-Math.ceil(overlap/Math.max(1,this.tools.zoom_tool.zoom_ticks.childNodes.length));
				if (tick_height<this.tools.zoom_tool.slider_minheight){
					this.tools.zoom_tool.slider_height = this.tools.zoom_tool.slider_minheight;				
					var d = (tick_height - this.tools.zoom_tool.slider_height)*this.tools.zoom_tool.zoom_ticks.childNodes.length;			
					this.resizeKeyMapSize(this.tools.keymap.width+d,this.tools.keymap.height+d);				
				}else{
					this.tools.zoom_tool.slider_height = Math.min(tick_height,this.tools.zoom_tool.slider_maxheight);
					this.resizeKeyMapSize(this.tools.keymap.width,this.tools.keymap.height);
				}
				if (this.tools.zoom_tool.zoom_ticks){
					for (var i=0; i < this.tools.zoom_tool.zoom_ticks.childNodes.length; i++){
						this.tools.zoom_tool.zoom_ticks.childNodes[i].style.height=this.tools.zoom_tool.slider_height+"px";
					}
				}
			this.updateZoomTool();
			}
		}
	}
};
	
psharkmap.prototype.updateZoomTool = function(){
		if (this.tools.zoom_tool.micro || this.no_zoom){
			return false;
		}

		this.tools.zoom_tool_slider_y = this.current_zoom*this.tools.zoom_tool.slider_height;
		this.tools.zoom_tool.slider.style.top = this.tools.zoom_tool_slider_y + "px";
};

psharkmap.prototype.setZoomToolOffset = function(){
	if (this.canvas.border_width_user_set){
		this.tools.zoomtool_offset_x = this.map.width-this.tools.zoom_tool.width-this.tools.margin;
		this.tools.zoomtool_offset_y = this.tools.margin;
	}else{
		if (this.canvas.set_in_layout){
			this.tools.zoomtool_offset_x = this.map.width+this.canvas.borderLeftWidth-this.tools.zoom_tool.width-this.tools.margin;
		}else{
			this.tools.zoomtool_offset_x = this.canvas.borderWidth + this.map.width-this.tools.zoom_tool.width-this.tools.margin;
		}
		this.tools.zoomtool_offset_y = this.canvas.borderTopWidth + this.tools.margin;
	}
};

// global functions and objects

