/*-----------------------------------------------------------------------
map JavaScript File

version: 	4.1
author:		sebastian kupke
email:		sebastian.kupke@baral-geohaus.de
website:	http://www.baral.de
-----------------------------------------------------------------------*/

/* =namespace map
-----------------------------------------------------------------------*/

ws.map = {
		
	
	// the current center of the map
	center: {
		x: 0,
		y: 0
	},
	
	// the current scale factor (meter / pixel)
	scale: 0,
	scaleNumber: 0,
	
	
	// min and max scales
	minScale: 0,
	maxScale: 0,
	
	// scalebar
	scalebar: false,
	
	// context
	context: false,
	
	// extent
	startExtent: new ws.cl.Extent(0, 0, 0, 0),
	boundaryExtent: new ws.cl.Extent(0, 0, 0, 0),
	
	// bordermaps
	bordermaps: {
		use: false,
		pixel: 400,
		minScale: 5000,
		maxScale: 500
	},
	
	loaded: null,
	
	/* =views
	-----------------------------------------------------------------------*/
	currentView: -1,
	maxView: -1,
	registerView: true,
	
	views: [],
	
	// language
	l: {
		load: '',
		loadError: '',
		loadAbort: '',
		noMapInScale: ''
	},
	
	/* =Service
	-----------------------------------------------------------------------*/
	// services
	services: [],
	
	// id of current service
	curService: '',
	
	/* =Returns a service object. Returns the current service if no id is given. Otherwise returns the service object with given id.
	-----------------------------------------------------------------------*/
	getService: function(id) {
		if (id) {
			// return service with given id
			for (i = 0; i < ws.map.services.length; i++) {
				if (ws.map.services[i].id == id) {
					return ws.map.services[i];
				}
			}
		} else {
			// get current service
			for (i = 0; i < ws.map.services.length; i++) {
				if (ws.map.services[i].id == ws.map.curService) {
					return ws.map.services[i];
				}
			}
		}
		
		return false;
	},
	
	/* =Service
	-----------------------------------------------------------------------*/
	Service: function (id, use, type, url, levels, curLevel) {
		this.id = id;
		this.use = use;
		this.type = type;
		this.url = url;
		this.levels = levels;
		this.curLevel = curLevel;
		
		/* =Returns a level object. Returns the current level if no id is given. Otherwise returns the level object with given id.
		-----------------------------------------------------------------------*/
		this.getLevel = function(id) {
			if (id) {
				// return level with given id
				for (i = 0; i < levels.length; i++) {
					if (levels[i].id == id) {
						return levels[i];
					}
				}
			} else {
				var scaleNumber = ws.map.getScaleNumber();
				for (i = 0; i < levels.length; i++) {
					if (levels[i].minScale >= scaleNumber && levels[i].maxScale <= scaleNumber) {
						return levels[i];
					}
				}
			}
			
			return false;
		};
		
		/* =Set the current level and returns this level object.
		-----------------------------------------------------------------------*/
		this.setCurLevel = function(id) {
			curLevel = id;
			
			// return level with given id
			for (i = 0; i < levels.length; i++) {
				if (levels[i].id == id) {
					return levels[i];
				}
			}
			
			return false;
		};
	},
	
	/* =Level
	-----------------------------------------------------------------------*/
	Level: function(id, minScale, maxScale, layers, curLayer) {
		this.id = id;
		this.minScale = minScale;
		this.maxScale = maxScale;
		this.layers = layers;
		this.curLayer = curLayer;
		
		// get layer by layer id
		this.getLayer = function(id) {
			if (id) {
				// return layer with given id
				for (i = 0; i < layers.length; i++) {
					if (layers[i].id == id) {
						return layers[i];
					}
				}
			} else {
				// get current layer
				for (i = 0; i < layers.length; i++) {
					if (layers[i].id == curLayer) {
						return layers[i];
					}
				}
			}
			
			return false;
		};
		
		/* =Set the current layer and returns this layer object.
		-----------------------------------------------------------------------*/
		this.setCurLayer = function(id) {
			curLayer = id;
			
			// return level with given id
			for (i = 0; i < layers.length; i++) {
				if (layers[i].id == id) {
					return layers[i];
				}
			}
			
			return false;
		};
	},
	
	/* =Layer
	-----------------------------------------------------------------------*/
	Layer: function(id, layer, copyrightText, copyrightMethod) {
		this.id = id;
		this.layer = layer;
		this.copyrightText = copyrightText;
		this.copyrightMethod = copyrightMethod;
	},
	
	/* =Returns the position of the mouse cursor in pixel
	-----------------------------------------------------------------------*/
	getCurPx: function(e) {
		
		var offset = $('#maps').offset();
		
		var x = e.pageX - offset.left;
		var y = e.pageY - offset.top;
		
		return new ws.cl.Point(x,y);
	},
	
	/* =Returns the position of the element in pixel
	-----------------------------------------------------------------------*/
	getElemPx: function() {

		try{
		var x = parseInt(document.getElementById('pin_select').style.left);
		var y = parseInt(document.getElementById('pin_select').style.top);
		
		return new ws.cl.Point(x,y);
	}
	catch(e){
		return new ws.cl.Point(0,0);
	}
	
	},
	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//stadtfix anfang 
	
	/* =Returns the mittelpunkt of the element in pixel
	-----------------------------------------------------------------------*/
	getStadtfixPx: function() {

		try{
			var x = parseInt(document.getElementById('pin_select').style.left);
			var y = parseInt(document.getElementById('pin_select').style.top);
			
			var x_mittel=x+(document.getElementById('pin_select').width)/2;
			var y_mittel=y+(document.getElementById('pin_select').height)/2;
		
			return new ws.cl.Point(x_mittel,y_mittel);
	}
	catch(e){
		return new ws.cl.Point(0,0);
		}
	},
	
	/* =Returns the position of the element in pixel
	-----------------------------------------------------------------------*/
	getImgPos: function(_obj) {

		var x=parseInt(_obj.style.left);
		var y=parseInt(_obj.style.top);
		
		return new ws.cl.Point(x,y);
	},
	

	/* =get object pixelkoordinaten
	-----------------------------------------------------------------------*/
	getPos: function(_obj) {
		//var getPos=function(_obj) {
		var x = 0, y = 0;
		do{
		    x += _obj.offsetLeft;
		    y += _obj.offsetTop;
		}while(_obj==_obj.offsetParent);
		return {'x':x,'y':y};
		//};
	},
	
//stadtfix end
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
		
	/* =Returns the position of the mouse cursor in coords
	-----------------------------------------------------------------------*/
	getCurCoords: function(e) {
		
		var p = ws.map.getCurPx(e);
		
		return ws.map.px2Coords(p);
	},
	
	/* =Calculates the coordinates from given pixel
	 * 
	 * @private
	-----------------------------------------------------------------------*/
	px2Coords: function(p) {
		
		var centerPixX = ($('#map_div').width() / 2) - p.x;
		var centerPixY = ($('#map_div').height() / 2) - p.y;
		
		var diffMeterX = centerPixX * ws.map.scale;
		var diffMeterY = centerPixY * ws.map.scale;
		
		var x = Math.abs(diffMeterX - ws.map.center.x);
		var y = Math.abs(diffMeterY + ws.map.center.y);
		
		return new ws.cl.Point(x, y);
	},
	
	/* =Returns an Point object
	 * 
	 * @param point Point object
	 * @param mapDivWidth int optional
	 * @param mapDivHeight int optional
	-----------------------------------------------------------------------*/
	coords2Px: function(p, mapDivWidth, mapDivHeight) {
		
		var width = mapDivWidth;
		var height = mapDivHeight;
		
		if (!width || !height) {
			width = $('#map_div').width();
			height = $('#map_div').height();
		}
		
	        var widthHalf = width / 2;
		var heightHalf = height / 2;
		
		var lux = ws.map.center.x - widthHalf * ws.map.scale;
		var luy = ws.map.center.y + heightHalf * ws.map.scale;
		
	        // Pixel diff from left upper
	        var x = (p.x - lux) / ws.map.scale;
		var y = (luy - p.y) / ws.map.scale;
		
		return new ws.cl.Point(Math.round(x), Math.round(y));
		//return new ws.cl.Point(x, y);
	},
	
	/* =zooms to a point in the map
	 * 
	-----------------------------------------------------------------------*/
	zoomto: function(x, y, scaleNumber) {

		ws.map.center.x = x;
		ws.map.center.y = y;

		if (scaleNumber) {
			ws.map.setScaleFactor(scaleNumber);
		}

		ws.map.load();
	},
	
	/* =Scale factor and scale number functions
	-----------------------------------------------------------------------*/
	getScaleNumber: function() {

		var widthPixel = $('#map_div').width();

		var mapWidthCm = widthPixel / ws.c.ppcm;

		var widthMeter = ws.map.scale * widthPixel;
		var scaleNumber = widthMeter * 100 / mapWidthCm;

		return Math.round(scaleNumber);
	},

	setScaleFactor: function(scaleNumber) {

		var widthPixel = $('#map_div').width();
		
		var mapWidthCm = widthPixel / ws.c.ppcm;
		
		var widthMeter = mapWidthCm * scaleNumber / 100;
		ws.map.scale = widthMeter / widthPixel;
		
		return ws.map.scale;
	},
	
	/* =Returns an JavaScript Extent object of the bounding box coordinates
	-----------------------------------------------------------------------*/
	getExtentCoords: function() {
		
		var widthHalf = $('#map_div').width() / 2;
		var heightHalf = $('#map_div').height() / 2;
		
		var minx = ws.map.center.x - widthHalf * ws.map.scale;
		var miny = ws.map.center.y - heightHalf * ws.map.scale;
		var maxx = ws.map.center.x + widthHalf * ws.map.scale;
		var maxy = ws.map.center.y + heightHalf * ws.map.scale;
		
		return new ws.cl.Extent(minx, miny, maxx, maxy);
	},
	
	/* =Loading
	-----------------------------------------------------------------------*/
	showLoadingDiv: function(text) {

		$('#loading_text').html(text);
		$('#loading_div').show();
	},

	hideLoadingDiv: function() {
		
		$('#loading_div').hide();
	},
	
	/* =Destroy all map events (make it clear again)
	-----------------------------------------------------------------------*/
	destroyEvents: function() {
	    
		$('#maps').css('cursor', 'auto');
		
	    $('#t_select_rect').css('z-index','1500');
	    $('#t_select_polygon').css('z-index','1600');
	    $('#t_select_circle').css('z-index','1700');
	    
		$('#map_div').unbind();
	    $('#maps').unbind();
	    
	    $('#maps').mousewheel(function(e, delta) {
			ws.c.mousewheel.handle(e, delta);
		});
	},
	
	/* =Pin functions
	-----------------------------------------------------------------------*/
	pin: {
		
		point: new ws.cl.Point(0, 0),
		img: 'rect.png',
		imgWidth: null,
		imgHeight: null,
		tooltipHeader: '',
		tooltipContent: '',
		
		/* =set
		-----------------------------------------------------------------------*/
		show: function() {
		
			// Set the image
		    $('#map_pin_image').attr('src', 'style/' + ws.c.style + '/img/map/pin/' + ws.map.pin.img);
		    
		    // Set the image width
		    if (ws.map.pin.imgWidth) {
		        $('#map_pin_image').css('width', ws.map.pin.imgWidth + 'px');
		    }
		    
		    // Set the image height
		    if (ws.map.pin.imgHeight) {
		        $('#map_pin_image').css('height', ws.map.pin.imgHeight + 'px');
		    }
	
		    // Set the position
		    var pos = ws.map.coords2Px(ws.map.pin.point);
	
		    pos.y = pos.y - ($('#map_pin').height() / 2);
		    pos.x = pos.x - ($('#map_pin').width() / 2);
	
		    $('#map_pin').css({
		    	top: pos.y + 'px',
		    	left: pos.x + 'px'
		    });
		    
			// ws.tt
			ws.tt.show($('#map_pin'), {
				header: ws.map.pin.tooltipHeader,
				content: ws.map.pin.tooltipContent
			});
		}
	},
				
	/* =Loads a map
	 * 
	 * @public
	-----------------------------------------------------------------------*/
	load: function() {
		
		var scaleNumber = ws.map.getScaleNumber();
		
		// check for min/max scale
		if (scaleNumber > ws.map.minScale) {
			ws.map.setScaleFactor(ws.map.minScale);
		} else if (scaleNumber < ws.map.maxScale) {
			ws.map.setScaleFactor(ws.map.maxScale);
		}
		
		// check for boundary
		if (ws.map.center.x < ws.map.boundaryExtent.minx) {
			ws.map.center.x = ws.map.boundaryExtent.minx;
		}
		
		if (ws.map.center.x > ws.map.boundaryExtent.maxx) {
			ws.map.center.x = ws.map.boundaryExtent.maxx;
		}
		
		if (ws.map.center.y < ws.map.boundaryExtent.miny) {
			ws.map.center.y = ws.map.boundaryExtent.miny;
		}
		
		if (ws.map.center.y > ws.map.boundaryExtent.maxy) {
			ws.map.center.y = ws.map.boundaryExtent.maxy;
		}

		// Get width and height of map div
		var width = $('#map_div').width();
		var height = $('#map_div').height();

		var ext = new ws.cl.Extent(ws.map.center.x - (width / 2 * ws.map.scale), ws.map.center.y - (height / 2 * ws.map.scale), ws.map.center.x + (width / 2 * ws.map.scale), ws.map.center.y + (height / 2 * ws.map.scale));

		// Get layers
		var mapLayers = '';
		var service = ws.map.getService();
		var level = service.getLevel();
		if (level) {
			var layer = level.getLayer();
	
			// Loading div
			ws.map.showLoadingDiv(ws.map.l.load);
			
			$.ajax({
		        url: 'scripts/get_map.gsp' + ws.c.ur,
		        data: {
					service: service.id,
					layers: layer.layer,
					width: width,
					height: height,
					bbox: ext.minx + ',' + ext.miny + ',' + ext.maxx + ',' + ext.maxy
				},
		        dataType: 'json',
		        type: 'post',
		        cache: false,									// BrowserBug IE
		        success: function(data){
					mapImage = new Image();
					mapImage.src = 'temp/' + data.img;
	
					mapImage.onload = ws.map.loadSuccess;
					mapImage.onerror = ws.map.loadError;
					mapImage.onabort = ws.map.loadAbort;					
		        }
		    });
		} else {
			// no level definition for this scale
			alert(ws.map.l.noMapInScale);
		}
	},
	
	/* =Calls if a map request was successfull
	 * 
	 * @private
	-----------------------------------------------------------------------*/
	loadSuccess: function() {
	
		// insert image
		var mapDiv = $('#map_div').css({
			top: '0px',
			left: '0px'
		});
		
		$('#map_image').css({
			position: 'absolute',
			top: '0px',
			left: '0px',
			width: mapDiv.width() + 'px',
			height: mapDiv.height() + 'px'
		}).html('<img src="' + mapImage.src + '" style="width: ' + mapDiv.width() + 'px; height: ' + mapDiv.height() + 'px;" />');
		
		ws.map.hideLoadingDiv();

		// get new scale number
		var scaleNumber = ws.map.getScaleNumber();
		
		/* =map pin
		-----------------------------------------------------------------------*/
		ws.map.pin.show();
		
		/* =map copyright
		-----------------------------------------------------------------------*/
		var service = ws.map.getService();
		var level = service.getLevel();
		var layer = level.getLayer();
		if (layer.copyrightText) {
			var style = layer.copyrightMethod ? ' style="cursor: pointer;" ' : '';
			$('#map_copyright_div').html('<span onclick="' + layer.copyrightMethod + '" ' + style + '>' + layer.copyrightText + '</span>');
		}
		
		/* =map context
		-----------------------------------------------------------------------*/
		$('#map_context span').text(layer.copyrightText);
		
		/* =map scalebar
		-----------------------------------------------------------------------*/
		if (ws.map.scalebar && (!$.browser.msie || $.browser.version > 6)) {
			// scale = meter / pixel
			var widthMeter = ws.map.scale * 200;
			
			if (widthMeter < 10) {
				widthMeter = Math.round(widthMeter);
			} else if (widthMeter < 100) {
				widthMeter = Math.round(widthMeter / 10) * 10;
			} else if (widthMeter < 1000) {
				widthMeter = Math.round(widthMeter / 100) * 100;
			} else if (widthMeter < 10000) {
				widthMeter = Math.round(widthMeter / 1000) * 1000;
			} else if (widthMeter < 100000) {
				widthMeter = Math.round(widthMeter / 10000) * 10000;
			} else if (widthMeter < 1000000) {
				widthMeter = Math.round(widthMeter / 100000) * 100000;
			}
			
			var width = widthMeter / ws.map.scale;
			
			$('#map_scalebar_div').show().width(width + 'px');
			$('#map_scalebar_scale_2').text(widthMeter + ' m');
		}
		
		/* =map view
		-----------------------------------------------------------------------*/
		if (ws.map.registerView) {
			ws.map.currentView += 1;
			ws.map.maxView += 1;

			ws.map.views.push(new ws.cl.View(ws.map.center, ws.map.scale));
		} else {
			ws.map.registerView = true;
		}
		
		/* =toolbar tools
		-----------------------------------------------------------------------*/
		try {
			if (ws.map.currentView > 0) {
				$('#button_undo').attr('src','style/' + ws.c.style + '/img/toolbar/undo.gif');
				$('#button_home').attr('src','style/' + ws.c.style + '/img/toolbar/home.gif');
			} else {
				$('#button_undo').attr('src','style/' + ws.c.style + '/img/toolbar/undoGrey.gif');
				$('#button_home').attr('src','style/' + ws.c.style + '/img/toolbar/homeGrey.gif');
			}

			if (ws.map.maxView > ws.map.currentView) {
				$('#button_redo').attr('src','style/' + ws.c.style + '/img/toolbar/redo.gif');
			} else {
				$('#button_redo').attr('src','style/' + ws.c.style + '/img/toolbar/redoGrey.gif');
			}
		} catch(e) {}

		try {
			if (scaleNumber >= ws.map.minScale) {
				$('#button_minus').attr('src','style/' + ws.c.style + '/img/toolbar/minusGrey.gif');
				$('#button_zoomout').attr('src','style/' + ws.c.style + '/img/toolbar/zoomoutGrey.gif');
			} else {
				$('#button_minus').attr('src','style/' + ws.c.style + '/img/toolbar/minus.gif');
				$('#button_zoomout').attr('src','style/' + ws.c.style + '/img/toolbar/zoomout.gif');
			}

			if (scaleNumber <= ws.map.maxScale) {
				$('#button_plus').attr('src','style/' + ws.c.style + '/img/toolbar/plusGrey.gif');
				$('#button_zoomin').attr('src','style/' + ws.c.style + '/img/toolbar/zoominGrey.gif');
			} else {
				$('#button_plus').attr('src','style/' + ws.c.style + '/img/toolbar/plus.gif');
				$('#button_zoomin').attr('src','style/' + ws.c.style + '/img/toolbar/zoomin.gif');
			}
		} catch(e) {}
	    
	    if (!ws.c.firstLoading) {
	    	/* =m_overview
			-----------------------------------------------------------------------*/
			try {
				ws.m.overview.setRect();
			} catch(e) {}
	    }
		
		/* =m_coordinates
		-----------------------------------------------------------------------*/
		try {
			if ($('#m_m_coordinates').size()) {
				$('#m_coordinates_scale_number').val(scaleNumber);
				$('#maps').mousemove(function (e) {
					ws.m.coordinates.show(e);
				});
			}
		} catch(e) {}
		
		/* =m_layer
		-----------------------------------------------------------------------*/
		try {
			var service = ws.map.getService();
			var level = service.getLevel();
			var layer = level.getLayer();
			$('#m_layer_tree li').css('font-weight', 'normal');
			$('#m_layer_' + service.id + '_' + level.id).css('font-weight', 'bold');
			$('#m_layer_' + service.id + '_' + level.id + '_' + layer.id).css('font-weight', 'bold');
		} catch(e) {}

		/* =m_meetingPoint
		-----------------------------------------------------------------------*/
		try {
			ws.m.meetingPoint.setPin();
		} catch (e) {}
		
		/* =m_address
		-----------------------------------------------------------------------*/
		try {
			ws.m.address.setPin();
		} catch (e) {}
		
		/* =m_parcel
		-----------------------------------------------------------------------*/
		try {
			ws.m.parcel.setPin();
		} catch (e) {}
		
		/* =m_objects
		-----------------------------------------------------------------------*/
		try {
			ws.m.objects.show();
		} catch (e) {}

		/* =map bordermaps
		-----------------------------------------------------------------------*/
		var bm = ws.map.bordermaps;
		if (bm.use && bm.pixel > 0 && (bm.minScale >= scaleNumber || bm.minScale == 0) && (bm.maxScale <= scaleNumber || bm.maxScale == 0)) {
			ws.map.loadBorderMaps();
		} else if (bm.use && bm.pixel > 0) {
			$('.map_bm').attr('src','style/' + ws.c.style + '/img/map/empty.gif');
		}
		
		/* =first loading
		-----------------------------------------------------------------------*/
		if (ws.c.firstLoading) {
			ws.c.firstLoading = false;

			// context menu
			if (ws.map.context) {
				$('#maps').showMenu({
					opacity:0.8,
					query: '#map_context'
				});
			}
			
			// modules
			if (ws.c.modules) {
				$.ajax({
			        url: 'scripts/get_modules.gsp' + ws.c.ur,
			        dataType: 'html',
			        success: function(data){
			        	$('#m_window').html(data);
			        }
			    });
			}
		}
		
		/* =callback loaded
		-----------------------------------------------------------------------*/
		if (ws.map.loaded) {
			ws.map.loaded.call(this);
			ws.map.loaded = null;
		}
	},
	
	/* =Calls if a map request was not successfull
	 * 
	 * @private
	-----------------------------------------------------------------------*/
	loadError: function() {
		
		ws.map.hideLoadingDiv();

		alert(ws.map.l.loadError);
	},
	
	/* =Calls if a map request was aborted
	 * 
	 * @private
	-----------------------------------------------------------------------*/
	loadAbort: function() {
		
		ws.map.hideLoadingDiv();

		alert(ws.map.l.loadAbort);
	},
	
	/* =Loads the bordermaps
	 * 
	 * @private
	-----------------------------------------------------------------------*/
	loadBorderMaps: function() {
		
		var scaleNumber = ws.map.getScaleNumber();

		// Get width and height of map div
		var widthPixel = $('#map_div').width();
		var heightPixel = $('#map_div').height();

		var ext = new ws.cl.Extent(ws.map.center.x - (widthPixel / 2 * ws.map.scale), ws.map.center.y - (heightPixel / 2 * ws.map.scale), ws.map.center.x + (widthPixel / 2 * ws.map.scale), ws.map.center.y + (heightPixel / 2 * ws.map.scale));

		var superMinX = ext.minx - (ws.map.bordermaps.pixel * ws.map.scale);
		var superMaxX = ext.maxx + (ws.map.bordermaps.pixel * ws.map.scale);
		var superMinY = ext.miny - (ws.map.bordermaps.pixel * ws.map.scale);
		var superMaxY = ext.maxy + (ws.map.bordermaps.pixel * ws.map.scale);

		// Get layers
		var service = ws.map.getService();
		var level = service.getLevel();
		var layer = level.getLayer();
		
		getOneBorderMap('l');
		getOneBorderMap('r');
		getOneBorderMap('t');
		getOneBorderMap('b');
		getOneBorderMap('lt');
		getOneBorderMap('lb');
		getOneBorderMap('rt');
		getOneBorderMap('rb');
		
		function getOneBorderMap(bm) {
			
			var bbox = '';
			var width = ws.map.bordermaps.pixel;
			var height = ws.map.bordermaps.pixel;
			
			if (bm == 'l') {
				bbox = superMinX + ',' + ext.miny + ',' + ext.minx + ',' + ext.maxy;
				height = heightPixel;
			} else if (bm == 'r') {
				bbox = ext.maxx + ',' + ext.miny + ',' + superMaxX + ',' + ext.maxy;
				height = heightPixel;
			} else if (bm == 't') {
				bbox = ext.minx + ',' + ext.maxy + ',' + ext.maxx + ',' + superMaxY;
				width = widthPixel;
			} else if (bm == 'b') {
				bbox = ext.minx + ',' + superMinY + ',' + ext.maxx + ',' + ext.miny;
				width = widthPixel;
			} else if (bm == 'lt') {
				bbox = superMinX + ',' + ext.maxy + ',' + ext.minx + ',' + superMaxY;
			} else if (bm == 'lb') {
				bbox = superMinX + ',' + superMinY + ',' + ext.minx + ',' + ext.miny;
			} else if (bm == 'rt') {
				bbox = ext.maxx + ',' + ext.maxy + ',' + superMaxX + ',' + superMaxY;
			} else if (bm == 'rb') {
				bbox = ext.maxx + ',' + superMinY + ',' + superMaxX + ',' + ext.miny;
			}
			
	        $.ajax({
	            url: 'scripts/get_map.gsp' + ws.c.ur,
	            data: {
					service: service.id,
					layers: layer.layer,
					width: width,
					height: height,
					bbox: bbox
				},
	            dataType: 'json',
	            type: 'post',
	            cache: false,
	            success: function(data){
					$('#map_image_' + bm).attr('src','temp/' + data.img);
	            }
	        });
		}
	}	
};

















