

OpenLayers.Control.Navigation.prototype.zoomWheelEnabled = false;


OpenLayers.Util.onImageLoadError = function() {

	this._attempts = (typeof(this._attempts) === "number") ? (this._attempts + 1) : 0;
	if(this._attempts < OpenLayers.IMAGE_RELOAD_ATTEMPTS) {
		this.src = this.src;
	} else if(this._attempts === OpenLayers.IMAGE_RELOAD_ATTEMPTS){
		this.src = "http://tile.know-where.com/tiles/nodata.gif";
	} else {
		this.style.backgroundColor = OpenLayers.Util.onImageLoadErrorColor;
	}
	this.style.display = "";
};

OpenLayers.Layer.TileCache.prototype.buffer = 0;

function init_renderTile(obj) {
	if (obj.imgDiv == null) {
		obj.initImgDiv();
	}

	obj.imgDiv.viewRequestID = obj.layer.map.viewRequestID;

	// needed for changing to a different serve for onload error
	if (obj.layer.url instanceof Array) {
		obj.imgDiv.urls = obj.layer.url.slice();
	}
	obj.url = obj.layer.getURL(obj.bounds);
	// position the frame
	OpenLayers.Util.modifyDOMElement(obj.frame, null, obj.position, obj.size);
}
function finish_renderTile(obj) {
	var imageSize = obj.layer.getImageSize();
        if (obj.layerAlphaHack) {
            OpenLayers.Util.modifyAlphaImageDiv(obj.imgDiv,
                    null, null, imageSize, obj.url);
        } else {
            OpenLayers.Util.modifyDOMElement(obj.imgDiv,
                    null, null, imageSize) ;
            obj.imgDiv.src = obj.url;
        }
}
KWImage_renderTile = function() {

	var queue_id = new Date().getTime();
	var args = arguments;
	var call_back_binder = function(obj, args, id){
		return function(){
			if ( obj.layer != null ) {
			
			var current_time = new Date().getTime();
			if ( queue_id === obj.kw_queue_id ) {
				
				
				if ( id != null ) {
				/*OpenLayers.Tile.Image.prototype.renderTile.apply(obj,args);*/
				finish_renderTile(obj);
				}

	                	obj.layer.map.kw_tile_throttle.eventCounter( new Object() );
				obj.delay_drawn = true;

				
			} 
			if ( id == null && obj.delay_drawn) {
			     obj.kw_queue_id = null;
			}
			}
		}
	}

	init_renderTile(this);

	if ( this.kw_queue_id == null ) {
		
		this.kw_queue_id = queue_id;
		this.delay_drawn = false;
		setTimeout(call_back_binder(this, arguments, queue_id), 350);
		setTimeout(call_back_binder(this,arguments,null),1000);
	} else {
		

		this.kw_queue_id = queue_id;
		this.delay_drawn = false;
		
		setTimeout(call_back_binder(this, arguments, queue_id), 600);
		
		setTimeout(call_back_binder(this,arguments,null),1000);
	}
	return(true);
}
OpenLayers.Layer.TileCache.prototype.addTile = function(bounds, position) {

        var url = this.getURL(bounds);
        var atile = new OpenLayers.Tile.Image(this, position, bounds,
                                             url, this.tileSize);
	atile.renderTile = KWImage_renderTile;
	return(atile);
}
function KWMap_moveTo(lonlat, zoom, options) {

	var move = true;
	var current_time = new Date().getTime();
	var throttled = this.kw_tile_throttle.eventCounter( null );
	if ( throttled ) {
/*console.error("throttle on: skipping");*/
			move = false;
			this.kw_move_skipped = true;
			if ( lonlat != null ) {
			this.kw_save_lonlat = lonlat.clone();
			} else {
				this.kw_save_lonlat = null;
			}
			this.kw_save_zoom = zoom;
			this.kw_save_options = options;
	} else {
		if ( this.kw_move_skipped ) {
/*console.error("rendering skipped");*/
			lonlat = this.kw_save_lonlat;
			zoom = this.kw_save_zoom;
			options = this.kw_save_options;
			this.kw_save_lonlat = null;
			this.kw_save_zoom = null;
			this.kw_save_options = null;
		} 
	}
	if ( lonlat === null && zoom === null && options === null ) {
		move = false;
	}
	if ( move ) {
		
        	OpenLayers.Map.prototype.moveTo.apply(this,arguments);
		this.kw_move_skipped = false;
	} 
}
KWMap_moveThrottle.prototype.counter = 0;
KWMap_moveThrottle.prototype.on = false;
KWMap_moveThrottle.prototype.start = null;
KWMap_moveThrottle.prototype.end = null;
KWMap_moveThrottle.prototype.eventCounter = function (event) {

	var current_time = new Date().getTime();

	
	var throttle_interval = 3000;
	
	throttle_interval = throttle_interval - 500;
	
	var throttle_max = 90;
	

	
	while( this.end != null  && (current_time - this.start.time) > throttle_interval ) {
		this.start = this.start.next;
		this.counter--;
		if ( this.start === null ) {
			this.end = null;
			this.counter = 0;
		}
	}
	
	if ( event != null ) {
		event.time = current_time;
		event.next = null;
		if ( this.end == null ) {
			this.end = event;
			this.start = event;
		} else {
			this.end.next = event;
			this.end = event;
		}
		this.counter++;
	}

	
	if ( this.counter >= throttle_max  ) {
		this.on = true;
	} else if ( this.on ) {
		this.on = false;
	}
/*
if ( event != null ) {
console.error(current_time+":event#: "+this.counter+" throttle interval:"+throttle_interval+ " throttle_max:"+throttle_max+" return:",this.on);
}
*/
	return(this.on);
}
function KWMap_moveThrottle(map) {

	this.map = map;
	this.map.moveTo = KWMap_moveTo;
	return(this);
}




OpenLayers.Control.PanZoomBar.prototype.zoomStopWidth = 16;
OpenLayers.Control.PanZoomBar.prototype.buttonDown = function (evt) {
	if (!OpenLayers.Event.isLeftClick(evt)) {
            return;
        }

        switch (this.action) {
            case "panup":
                this.map.pan(0, -this.slideFactor);
                break;
            case "pandown":
                this.map.pan(0, this.slideFactor);
                break;
            case "panleft":
                this.map.pan(-this.slideFactor, 0);
                break;
            case "panright":
                this.map.pan(this.slideFactor, 0);
                break;
	    case "panSE":
                this.map.pan(this.slideFactor, this.slideFactor);
		break;
	    case "panSW":
                this.map.pan(-this.slideFactor, this.slideFactor);
		break;
	    case "panNE":
                this.map.pan(this.slideFactor, -this.slideFactor);
		break;
	    case "panNW":
                this.map.pan(-this.slideFactor, -this.slideFactor);
		break;
            case "zoomin":
                this.map.zoomIn();
                break;
            case "zoomout":
                this.map.zoomOut();
                break;
            case "zoomworld":
                this.map.zoomToMaxExtent();
                break;
        }

        OpenLayers.Event.stop(evt);
}
OpenLayers.Control.PanZoomBar.prototype._addButton = function(id,img,xy,sz) {
	var button_div = OpenLayers.Control.PanZoom.prototype._addButton.apply(this,arguments);
	button_div.style.cursor = 'pointer';
	return button_div;
}
OpenLayers.Control.PanZoomBar.prototype.draw = function(px) {

        OpenLayers.Control.prototype.draw.apply(this, arguments);
        px = this.position.clone();


        this.buttons = [];

        var top_bottom_button_sz = new OpenLayers.Size(33,25);
	var corner_button_sz = new OpenLayers.Size(28,30);
        var right_left_button_sz = new OpenLayers.Size(23,34);
        var zoombar_plus_minus_sz = new OpenLayers.Size(20,24);
        var zoom_plus_minus_sz = new OpenLayers.Size(20,20);
	var button_pad = 8;
        var origin_x = px.x-button_pad;
        var origin_y = px.y-button_pad;
	var map_width = KWMap_width();
	var map_height = KWMap_height();
	var map_ctr = new OpenLayers.Pixel (map_width/2, map_height/2);


        this.slideFactor = map_ctr.y-10;
	px.x = origin_x+map_ctr.x-(top_bottom_button_sz.w/2)
	px.y = origin_y;
        var button = this._addButton("panup", "north-mini.png", px, top_bottom_button_sz);
	button.style.cursor = 'pointer';
	px.y = map_height - top_bottom_button_sz.h;
        this._addButton("pandown", "south-mini.png", px, top_bottom_button_sz);

	

        px.x = origin_x;
	

        px.y = origin_y + map_ctr.y - (right_left_button_sz.h/2);
        this.slideFactor = map_ctr.x-10;
        this._addButton("panleft", "west-mini.png", px, right_left_button_sz);

        px.x = map_width - right_left_button_sz.w;
        this._addButton("panright", "east-mini.png", px, right_left_button_sz);

	
		
			px.x = origin_x + right_left_button_sz.w;
		
		
			
				px.y = origin_y + button_pad;
			
		
        	this._addButton("zoomin", "zoombar-plus-mini.png", px, zoombar_plus_minus_sz);
        	px = this._addZoomBar(px.add(1, zoombar_plus_minus_sz.h-1));
		this.slider.style.cursor = 'pointer';
        	this._addButton("zoomout", "zoombar-minus-mini.png", px.add(-1,0), zoombar_plus_minus_sz);
	
        return this.div;
}

function KWMap_configure_copyright( kwmap_obj ) {
	kwmap_obj.copyright_icon = new OpenLayers.Icon(
					kw_hostdir + "/Icon/copyright.png", 
					new OpenLayers.Size(125,12), 
					new OpenLayers.Pixel(0,0) );
	kwmap_obj.copyright_icon.imageDiv.style.zIndex = 999;
	kwmap_obj.viewPortDiv.appendChild(kwmap_obj.copyright_icon.imageDiv);
	kwmap_obj.draw_copyright = function() {
		var margin = 4;
		this.copyright_icon.draw(new OpenLayers.Pixel(

						margin,

						KWMap_height() - (this.copyright_icon.size.h+margin)));
	}
}
function KWMap_on_zoomend() {
	var iz;
	for ( iz=0; iz < this.numZoomLevels; iz++ ) {
		this.kw_map_scale_icon_list[iz].display(false);
	}
	this.draw_scale();
}
function KWMap_configure_map_scale(kwmap_obj) {
	kwmap_obj.events.register("zoomend",that,KWMap_on_zoomend );
	kwmap_obj.draw_scale = function() {
		var z = this.getZoom();
		var margin = 4;
		this.kw_map_scale_icon_list[z].display(true);
		this.kw_map_scale_icon_list[z].draw(new OpenLayers.Pixel(
					margin,
					KWMap_height() - (this.kw_map_scale_icon_list[z].size.h+margin)));
	}
	var zoom_num = kwmap_obj.numZoomLevels;
	kwmap_obj.kw_map_scale_icon_list = new Array(zoom_num);
	var z;
	for ( z=0; z < zoom_num; z++ ) {
		kwmap_obj.kw_map_scale_icon_list[z] =  new OpenLayers.Icon(
				"http://lowes.know-where.com/lowes/Icon/map_scale/zoom"+z+".png",
				new OpenLayers.Size(104,16), 
				new OpenLayers.Pixel(0,0) );
		kwmap_obj.kw_map_scale_icon_list[z].imageDiv.style.zIndex = 998;
		kwmap_obj.viewPortDiv.appendChild(kwmap_obj.kw_map_scale_icon_list[z].imageDiv);
	}
}
function getElementHeight(Elem) {
		var elem = document.getElementById(Elem);
		var xPos = elem.offsetHeight;
		return xPos;
}

function getElementWidth(Elem) {
		var elem = document.getElementById(Elem);
		var xPos = elem.offsetWidth;
		return xPos;
}

function KWMap_width () {
	var wt;
	if(KW_MAP_API.enabled == 1){
		if(KW_MAP_API.width > 0){
			wt = KW_MAP_API.width;
		} else {
			wt = windowWidth() - KW_MAP_API.padding_width;
		}

		wt = Math.min(KW_MAP_API.max_width, wt);
		wt = Math.max(KW_MAP_API.min_width, wt);
		return wt;
	}

	if(KW_PAGE_CONFIG.map_custom_width !== undefined){
		return KW_PAGE_CONFIG.map_custom_width;
	}


    if ((document.getElementById('search_results') !== null) && (document.getElementById('search_results').className == 'kwresult_show')) {
		wt = windowWidth() - KW_PAGE_CONFIG.table_width - KW_PAGE_CONFIG.horizontal_margins;
		wt = Math.min(KW_PAGE_CONFIG.max_sr_map_width, wt);
		wt = Math.max(KW_PAGE_CONFIG.min_sr_map_width, wt);
    } else {
		wt = windowWidth() - KW_PAGE_CONFIG.detail_width - KW_PAGE_CONFIG.horizontal_margins;
		wt = Math.min(KW_PAGE_CONFIG.max_det_map_width, wt);
		wt = Math.max(KW_PAGE_CONFIG.min_det_map_width, wt);
 	 }
	return wt;
}

function KWMap_height () {
	var ht;	

	if(KW_MAP_API.enabled == 1){
		if(KW_MAP_API.height > 0){
			ht = KW_MAP_API.height;
		} else {
			ht = windowHeight() - KW_MAP_API.padding_height;
		}

		ht = Math.min(KW_MAP_API.max_height, ht);
		ht = Math.max(KW_MAP_API.min_height, ht);
		return ht;
	}

	if(KW_VARS.current_page === 'results'){
		ht = Math.max(getElementHeight("kw_results_map_container"), KW_PAGE_CONFIG.map_custom_height);
		return Math.min(ht, 1000);
	} else if(KW_VARS.current_page === 'detail'){
		ht = Math.max(getElementHeight("kw_detail_map_container"), KW_PAGE_CONFIG.map_custom_height);
		return Math.min(ht, 1000);
	} else if(KW_VARS.current_page === 'dd'){
		ht = getElementHeight("kw_detail_map_container");
		if(ht < KW_PAGE_CONFIG.map_custom_height){
			ht = KW_PAGE_CONFIG.map_custom_height;
		}
		ht = Math.min(ht, 400);
		return ht;
	}

}

function KWMap_style(){
	var map_div = document.getElementById('LOCAL_MAP');
	map_div.style.height = KWMap_height () + 'px';
	map_div.style.width = KWMap_width () + 'px';
}


function KWMap_zoom(lat, lon, zoom) {
	var location = new OpenLayers.LonLat;
	location.lat = lat;
	location.lon = lon;
	localmap.setCenter(location,zoom,1,1)
	if ( localmap.hl_marker ) {
		localmap.hl_marker.icon.display(false);
	}
	if ( localmap.hl_shadow ) {
		localmap.hl_shadow.icon.display(false);
	}
}	

function KWMap_panTo(lat, lon) {
	var location = new OpenLayers.LonLat;
	location.lat = lat;
	location.lon = lon;
	localmap.panTo(location);
}	

function KWMap_Bounds() {
	var that = new OpenLayers.Bounds();
	that.extend_by_loc = function(loc) {
		var foobar = kw_decode_txt(loc);
		var foobar_arr = foobar.split(';');
		this.extend(new OpenLayers.LonLat(foobar_arr[1],foobar_arr[0]));
	}
	return that;

}
var kw_decode = new Array();
kw_decode['X'] = '6';
kw_decode['b'] = '3';
kw_decode['f'] = '7';
kw_decode['8'] = '9';
kw_decode['g'] = '2';
kw_decode['Y'] = '+';
kw_decode['l'] = '-';
kw_decode['n'] = '8';
kw_decode['5'] = '1';
kw_decode['I'] = '4';
kw_decode['q'] = '0';
kw_decode['P'] = '.';
kw_decode['Z'] = ';';
kw_decode['x'] = '5';

function kw_decode_txt(src) {
	var val = '';
	var c;
	for ( c=0; c < src.length; c++ ) {
		var newc = kw_decode[src.charAt(c)];
		val = val + newc;
	}
	return val;
}
function KWMap_Icon(img,img_wd,img_ht,x_offset,y_offset,img_hl) {
	var icon_size = new OpenLayers.Size(img_wd,img_ht);
	var icon_offset = new OpenLayers.Pixel(-x_offset,-y_offset);
	var icon = new OpenLayers.Icon(img, icon_size, icon_offset);
	return icon;
}
function KWMap(mapid,lat,lon,zoom) {
/* Constructor for an OpenLayers.Map object, with a few
 * special conveniences for KWMap usage
 * lat, lon becomes the center lat/lon
 * zoom can be either an OpenLayers.Bounds or a zoom number
 */
/* Private functions to KWMap */
	function init_kwmap_layer(){
		var tile_size = 512;
		var n_zoom = 12;
		var zoom_levels = new Array(n_zoom-2);
		/* degrees lat/pixel @ most zoomed in level (1000 pix/mile & 69 miles/deg of lat)*/
		var zoom_max_pixel = 0.000014;  /* kwmap only support 6 decimals of precision */
		for ( z=2; z < n_zoom; z++ ) { /* limit to 10 zooms for now until we get world working properly */
        		/* OpenLayers expects zoom resolution defined in units per pixel*/
			zoom_levels[z-2] = (zoom_max_pixel * Math.pow(2.6,n_zoom-(z+1))).toFixed(6);
		}
		
		var server_list;
		if(kw_ssl === true){
			server_list = ;
		} else {
			server_list = [ "http://tilea.know-where.com/tiles/", "http://tileb.know-where.com/tiles", "http://tilec.know-where.com/tiles", "http://tiled.know-where.com/tiles" ];
		}

		var kwmap = new OpenLayers.Layer.TileCache( "Streets",
				server_list,
				"basic512_subset_10z",
				{format: 'image/gif',
				tileSize: new OpenLayers.Size(tile_size,tile_size),
				maxExtent : new OpenLayers.Bounds(-180,-60,180,90),
				resolutions: zoom_levels, transitionEffect: 'resize' });

		return kwmap;
	}

/* Make the KWMap object */

	var base_layer = init_kwmap_layer();
	var zoom_num = 0;
	/* the "resolutions" array from the base_layer controls how many 
	 * zoom levels there will be on the map.
	 */
	var mapOptions = { controls: [], resolutions: base_layer.resolutions };
	that = new OpenLayers.Map( mapid,mapOptions );
	that.addLayers([base_layer]);
	that.kw_tile_throttle = new KWMap_moveThrottle(that);

	KWMap_configure_copyright(that);

	/* 
	 * Set map center & zoom level together, so that map
	 * only loads tiles once on creation
	 * Every change of center or zoom causes a "moveTo"
	 * on the map, which must load new tiles.
	 */
	if ( typeof(zoom) == "number" ) {
		zoom_num = zoom;
	} else {
		zoom_num = base_layer.getZoomForExtent(zoom);
	}
	that.setCenter(new OpenLayers.LonLat(lon,lat),zoom_num);
	that.draw_copyright();
	/* Add controls*/
	that.addControl( new OpenLayers.Control.PanZoomBar() );
	that.addControl( new OpenLayers.Control.Navigation() );
	that.addControl( new OpenLayers.Control.DragPan() );
	that.kw_center_lat = lat;
	that.kw_center_lon = lon;
	that.kw_shadow_list = new Array();
	that.kw_hl_shadow = null;
	that.kw_marker_list = new Array();
	that.kw_hl_marker = null;
	that.kw_marker_lat = new Array();
	that.kw_marker_lon = new Array();
	that.marker_layer = new OpenLayers.Layer.Markers( "Markers" ,
				{minResolution:0.000010,maxResolution:0.513848});
	that.addLayer(that.marker_layer);

/* Add some priviledged methods for KWMap */
	that.set_marker_loc = function(i,loc) {
		var foobar = kw_decode_txt(loc);
		var foobar_arr = foobar.split(';');
		this.kw_marker_lat[i] = foobar_arr[0];
		this.kw_marker_lon[i] = foobar_arr[1];
		/* Add markers layer*/
	}
	that.set_marker_shadow = function(i,icon) {
		this.kw_shadow_list[i]= new OpenLayers.Marker(new OpenLayers.LonLat(this.kw_marker_lon[i],this.kw_marker_lat[i]),icon);
		this.kw_shadow_list[i].kw_zero_based_i = i;
		this.marker_layer.addMarker(this.kw_shadow_list[i]);
	}
	that.set_hl_marker_shadow = function(icon) {
		if ( this.kw_hl_shadow ) {
			this.marker_layer.removeMarker(this.kw_hl_shadow);
			this.kw_hl_shadow.destroy();
			this.kw_hl_shadow = null;
		}
		this.kw_hl_shadow= new OpenLayers.Marker(this.getCenter(),icon);
		this.kw_hl_shadow.kw_zero_based_i = null;
		this.marker_layer.addMarker(this.kw_hl_shadow);
		this.kw_hl_shadow.icon.display(false);
	}
	that.set_marker = function(i,icon,href,text,key,hostdir) {
		var new_marker = new OpenLayers.Marker(new OpenLayers.LonLat(this.kw_marker_lon[i],this.kw_marker_lat[i]),icon);
		new_marker.kw_zero_based_i = i;
		new_marker.kw_text = text;
		new_marker.kw_key = key;
		/*new_marker.kw_hostdir = hostdir;*/
		/*new_marker.layer = this.marker_layer;*/
		new_marker.kw_href = href;

		if(KW_MAP_API.enabled !== 1){
			new_marker .events.register("click", new_marker , function(e) {
				click_action(new_marker );
			});
		}

		new_marker .events.register("mouseover", new_marker , function(e) {
			mouseover_action(new_marker );
		});

		new_marker .events.register("mouseout", new_marker , function(e) {
			mouseout_action(new_marker )
		});
		new_marker.map = this;
		this.marker_layer.addMarker(new_marker);
		this.kw_marker_list[i] = new_marker;
		/* using an undocumented OpenLayers internal here */
		new_marker.icon.imageDiv.style.cursor = 'pointer';
	}
	that.set_hl_marker = function(icon) {
		var new_marker = new OpenLayers.Marker(this.getCenter(),icon);
		new_marker.kw_zero_based_i = null;
		if(KW_MAP_API.enabled !== 1){
			new_marker.events.register("click", new_marker, function(e) {
				click_action(new_marker);
			});
		}

		new_marker.events.register("mouseover", new_marker, function(e) {
			mouseover_action(new_marker);
		});

		new_marker.events.register("mouseout", new_marker, function(e) {
			mouseout_action(new_marker);
		});
		new_marker.map = this;
		
		this.marker_layer.addMarker(new_marker);
		new_marker.icon.display(false);
		new_marker.icon.imageDiv.style.cursor = 'pointer';
		this.kw_hl_marker = new_marker;
		/* using an undocumented OpenLayers internal here */
	
		if(this.kw_hl_markers == null || this.kw_hl_markers == undefined){
			this.kw_hl_markers = new Array();
		}
		this.kw_hl_markers.push(new_marker);
	}
	that.DD_markers = function DD_markers(lat_start, lon_start, lat_end, lon_end) {
		if (this.start_marker == null) {
			this.start_marker_shadow = new OpenLayers.Marker(new OpenLayers.LonLat(lon_start, lat_start), DDshadow);
			this.start_marker = new OpenLayers.Marker(new OpenLayers.LonLat(lon_start, lat_start), DDstart);
			this.end_marker = new OpenLayers.Marker(new OpenLayers.LonLat(lon_end, lat_end), DDend);
		} else {
			this.start_marker_shadow.lonlat = new OpenLayers.LonLat(lon_start, lat_start);
			this.start_marker.lonlat = new OpenLayers.LonLat(lon_start, lat_start);
			this.end_marker.lonlat = new OpenLayers.LonLat(lon_end, lat_end);
		}
		this.marker_layer.addMarker( this.start_marker_shadow );
		this.marker_layer.addMarker( this.start_marker );
		this.marker_layer.addMarker( this.end_marker );

		var bound = new OpenLayers.Bounds();
		bound.extend (this.start_marker.lonlat);
		bound.extend (this.end_marker.lonlat);
                this.zoomToExtent(bound);
		var startpixel = this.getPixelFromLonLat(this.start_marker.lonlat);
		var endpixel = this.getPixelFromLonLat(this.end_marker.lonlat);

		// for some reason offsets are negative
		if (startpixel.y < - this.start_marker.icon.offset.y || endpixel.y < - this.end_marker.icon.offset.y || 
				startpixel.x < - this.start_marker.icon.offset.x || endpixel.x < - this.end_marker.icon.offset.x ||
				this.getSize().w - startpixel.x < this.start_marker.icon.size.w + this.start_marker.icon.offset.x ||
				this.getSize().w - endpixel.x < this.end_marker.icon.size.w + this.end_marker.icon.offset.x) {
			this.zoomOut();
		}


 
	}
	that.DD_remove_markers = function DD_remove_markers() {
		/* I checked the OpenLayers code, it is ok to call this 
		 * even if the marker has not been added to the layer
		*/
		if ( this.start_marker ) {
			this.marker_layer.removeMarker( this.start_marker );
		}
		if ( this.start_marker_shadow ) {
			this.marker_layer.removeMarker( this.start_marker_shadow );
		}
		if ( this.end_marker ) {
			this.marker_layer.removeMarker( this.end_marker );
		}
	}

	that.add_copyright = function(copyright_img,copyright_wd,copyright_ht,x,y) {
	/* This is a do nothing function...it should be removed from page/location */
	/* alert("Remove add_copyright from page/location"); */
	}

	that.draw_line = function(points) {
		if ( this.line_layer == null ) {
			this.line_layer = new OpenLayers.Layer.Vector( "Lines",
				{minResolution:0.000010,maxResolution:0.513848} );
			this.addLayer(this.line_layer);
		}
		var line_style = {
			strokeColor: "#00FF00",
			strokeWidth: 15,
			strokeRadius: 30,
			strokeOpacity: 0.6,
			pointerEvents: "visiblePainted"
		};
		var line_feature = new OpenLayers.Feature.Vector(
			new OpenLayers.Geometry.LineString(points),
			null,
			line_style
			);
		this.line_layer.addFeatures([line_feature]);

//		var pt;
//		var bound = new OpenLayers.Bounds();
//		for (pt in points) {
//			bound.extend(new OpenLayers.LonLat(points[pt].x, points[pt].y));
//		}
//		this.zoomToExtent(bound);
	}

	that.remove_line = function () {
		if ( this.line_layer != null ) {
			this.removeLayer(this.line_layer);
			this.line_layer = null;
		}
	}

/* Return the new map */
	return (that);
}

function mouseover_action(new_marker) {
	var i = new_marker.kw_zero_based_i;
	var i1 = i + 1;
	if ( new_marker.map.kw_hl_marker && new_marker.map.kw_hl_shadow ) {
		var k = i;
		if(new_marker.map.kw_hl_markers.length <= i){
			k = 0;
		}
		new_marker.map.kw_hl_marker = new_marker.map.kw_hl_markers[k];
		new_marker.map.kw_hl_marker.icon.moveTo(new_marker.map.kw_marker_list[i].icon.px.clone());
		/* keep track of which marker for mouse out */

		new_marker.map.kw_hl_marker.icon.imageDiv.title = marker_popup_text[i];

		new_marker.map.kw_hl_marker.kw_zero_based_i = i; 
		new_marker.map.kw_hl_marker.icon.display(true);


		new_marker.map.kw_hl_shadow.icon.moveTo(new_marker.map.kw_shadow_list[i].icon.px.clone());
		new_marker.map.kw_hl_shadow.icon.display(true);
	}

	if(KW_MAP_API.enabled !== 1){
		/* Show marker on result table */
		
			if(typeof(KWResults) !== 'undefined'){
				var pi = Math.floor(i / KWResults.results_per_page);
				if(pi !== KWResults.page_current){
					KWResults.show_page(pi);
				}
				KWResults.kwresult_highlight(i);
			}

		
	}
}

function mouseout_action(new_marker) {

	var i = new_marker.kw_zero_based_i;
	var i1 = i+1;
	if ( new_marker.map.kw_hl_shadow != null ) {
		new_marker.map.kw_hl_shadow.icon.display(false);
	}
	if ( new_marker.map.kw_hl_marker != null ) {
		new_marker.map.kw_hl_marker.icon.display(false);
	}
	
	if(KW_MAP_API.enabled !== 1){
		/* remove marker from results table */
		/* Force redraw of page */	
		
			if(typeof(KWResults) !== 'undefined'){
				KWResults.kwresult_highlight_off(i);
			}
		
	}
	/* remove popup */
	/*
	new_marker.map.removePopup(new_marker.popup);
	new_marker.popup.destroy();
	new_marker.popup = null;
	*/

}

function click_action(new_marker) {

	var i = new_marker.kw_zero_based_i;

	kwshow_detail(new_marker.map.kw_marker_list[i].kw_key);
	/* resize map to allow for detail page */
	//kwresize();

	var p = Math.floor(i / KWResults.results_per_page);
	if(p !== KWResults.page_current){
		KWResults.show_page(p);
	}

	KWMap_zoom(new_marker.map.kw_marker_lat[i],
		   new_marker.map.kw_marker_lon[i], 
		   KW_PAGE_CONFIG.detail_zoom_level);
}

function kw_on_resize(){
	if(navigator.appName == "Microsoft Internet Explorer"){
		return;
	} else {
		kwresize();
	}
}
		

function kwresize () {
	// resize map when page resized
	//alert("kwresize");
	if(navigator.appName == "Microsoft Internet Explorer"){
		return;
	}
	document.getElementById('LOCAL_MAP').style.width = KWMap_width() + 'px';
	document.getElementById('LOCAL_MAP').style.height = KWMap_height() + 'px';
	localmap.updateSize();
	localmap.controls[0].redraw();
	localmap.draw_copyright();
	
	on_kwpage_resize("kwresize");

}

