function MultimapInlineMap(client) {
	/*	-----------------
		Attributes
	-----------------	*/
	this.client = client;
    if (document.location.host == "staging.multimap.com" || document.location.host == "dev2.multimap.com") {
    	this.mapcgiurl = "/clients/map";
	    this.aerialcgiurl = "/clients/aerial";
    } else {
        this.mapcgiurl = "http://www.multimap.com/clients/map";
        this.aerialcgiurl = "http://www.multimap.com/clients/aerial";
    }

	this.opacity = 75;
	this.panx = 0;
	this.pany = 0;
	this.ds = 0;
	this.width = 500; // Default width
	this.height = 300; // Default height
//	this.noautoredraw = 0;
	this.debug = 0; // Disable debug output

	/*	-----------------
		Methods
	-----------------	*/
	// Opacity control
    this.changeOpacity = function changeOpacity(opacity) {
        this.opacity = opacity;
        this.redrawMap();
    }
	// Opacity control
    this.changeType = function changeType(type) {
        this.type = type;
	 	this.redrawMap();
    }
	// Panning controls.
	this.pan = function pan(xinc, yinc) {
		this.panx = this.panx + xinc;
		this.pany = this.pany + yinc;
		this.redrawMap();
	}
	// Pan on the X axis
	this.panX = function panX(inc) { this.pan(inc, 0); }
	// Pan on the Y axis
	this.panY = function panY(inc) { this.pan(0, inc); }

	// Zooming/scale functions.
	this._getScaleIndex = function getScaleIndex() {
		if (this.scale && !this.scales) {
			this.flog("Scale value specified, but no scale range is defined - using defaults","D");
			this.scales = new Array(10000, 25000, 50000, 100000, 200000, 500000);
		}
		for (n=0; n<this.scales.length; n++) {
			if (this.scales[n] == this.scale) {
				return n;
			}
		}
	}
	this.zoom = function zoom(inc) {
		if (this.scale) {
			// We have a fixed range of scales, move up and down the scales array
			this._scaleindex = this._getScaleIndex() + inc;
			if (this._scaleindex < 0 || this._scaleindex >= this.scales.length) {
				this.flog("Cannot zoom beyond current range of scales","D");
				return;
			}
			this.scale = this.scales[this._scaleindex];
		} else {
			// Use delta scaling
			this.ds = this.ds + inc;
		}
		this.redrawMap();
	}
	this.zoomIn = function zoomIn() { this.zoom(-1); }
	this.zoomOut = function zoomOut() { this.zoom(1); }
	this.gotoScale= function gotoScale(scale) {
		this.scale = scale;
		this._scaleindex = this._getScaleIndex();
		this.redrawMap();
	}

	// Generate a full url for this map request.
	this.buildUrlParams = function buildUrlParams() {
        // If Host is overwritten
        if (this.host) {
            this.mapcgiurl = "http://"+this.host+"/clients/map";
            this.aerialcgiurl = "http://"+this.host+"/clients/aerial";
        }
		// Location of map
		if (this.query_string && this.debug) {
			var valid_params = new Array();
			valid_params["client"]=1;
			valid_params["lat"]=1;
			valid_params["lon"]=1;
			valid_params["f_client_id"]=1;
			valid_params["filter_params"]=1;
			valid_params["x"]=1;
			valid_params["y"]=1;
			valid_params["pc"]=1;
            valid_params["pclist"]=1;
            valid_params["xylist"]=1;
            valid_params["lllist"]=1;
            valid_params["grid"]=1;
            valid_params["icon"]=1;
            valid_params["gif_array"]=1;
            valid_params["dx"]=1;
            valid_params["dy"]=1;
			valid_params["coordsys"]=1;
			valid_params["scale"]=1;
			valid_params["scales"]=1;
			valid_params["width"]=1;
			valid_params["height"]=1;
			valid_params["xhtml"]=1;
			valid_params["debug"]=1;
			valid_params["query_string"]=1;
			var param = new Array();
			var query = this.query_string;
			var param_arr = query.split('&');
			var filter_params_arr = new Array();
			for (var i=0; i<param_arr.length; i++) {
				var pos = param_arr[i].indexOf('=');
				if (pos > 0) {
					var key = param_arr[i].substring(0,pos);
					var val = param_arr[i].substring(pos+1);
					if (key.match(/^f_/)) {
						filter_params_arr.push(key+'='+val);
					} else {
						if (valid_params[key] != 1) {
							this.flog(key + " is not a valid parameter","D");
						}
						param[key] = val;
					}
				}
			}
			if (param["client"]) { // If client is passed in through the query_string
				this.client = param["client"];
			}
			this.lat = param["lat"];
			this.lon = param["lon"];
            this.pclist = param["pclist"];
            this.xylist = param["xylist"];
            this.lllist = param["lllist"];
            this.grid = param["grid"];
            this.icon = param["icon"];
            this.addr2 = param["addr2"];
            this.addr3 = param["addr3"];
            this.gif_array = param["gif_array"];
            this.dx = param["dx"];
            this.dy = param["dy"];
			this.x = param["x"];
			this.y = param["y"];
			this.coordsys = param["coordsys"];
            this.country = param["country"];
            this.state = param["state"];
			this.pc = param["pc"];
			this.xhtml = param["xhtml"];
			this.width = param["width"];
			this.height = param["height"];
			this.scale = param["scale"];
			this.scales = param["scales"];
			this.filter_params = filter_params_arr;
		} else if (this.query_string) {
			var newUrlParams;
			if (this.client) {
				// Client is specified in the constructor
				newUrlParams = "client="+this.client+"&"+this.query_string;
			} else {
				// Client is in the query_string
				newUrlParams = this.query_string;
			}
			// Panning values
			panning = "&panx="+this.panx+"&pany="+this.pany;
			// Scale values
			scale = (this.scale) ? "&scale="+this.scale : "";
			zooming = (this.ds) ? "&ds="+this.ds : "";

			newUrlParams = newUrlParams+scale+panning+zooming;
			return newUrlParams;
		}

		if (this.lat && this.lon) {
			maplocation = "&lat="+this.lat+"&lon="+this.lon;
		} else if (this.x && this.y) {
			// Check if we have a coordsys, if not assume OSNG coords.
			if (this.coordsys == "") {
				this.coordsys = "gb";
			}
			maplocation = "&X="+this.x+"&Y="+this.y+"&coordsys="+this.coordsys;
		} else if (this.pc || this.addr2 || this.addr2 || this.country || this.state) {
			// GB Postcode
            maplocation = "";
            if (this.pc)
    			maplocation += "&pc="+this.pc;
            if (this.addr2)
                maplocation += "&addr2="+this.addr2;
            if (this.addr3)
                maplocation += "&addr3="+this.addr3;
            if (this.country)
                maplocation += "&country="+this.country;
            if (this.state)
                maplocation += "&state="+this.state;
        } else if (this.pclist) {
            // Postcode List
            maplocation = "&pclist="+this.pclist;
        } else if (this.xylist) {
            // XY List
            maplocation = "&xylist="+this.xylist;
        } else if (this.lllist) {
            // Lat Lon List
            maplocation = "&lllist="+this.lllist;
        } else if (this.grid) {
            // Grid
            maplocation = "&grid="+this.grid;
		} else if (this.filter_params.length > 0) {
			// Multiple Filters
			maplocation = "&" + this.filter_params.join("&");
		} else {
			// No coordinates
			this.flog("Request has no coordinates","D");
		}

        if (this.dx || this.dy) {
            maplocation += "&dx="+this.dx+"&dy="+this.dy;
        }

        if (this.icon) {
            maplocation += "&icon="+this.icon;
        }
 
        if (this.gif_array) {
            maplocation += "&gif_array="+this.gif_array;
        }

		// Map size (pixel dimensions)
		size = "&width="+this.width+"&height="+this.height;
		// Panning values
		panning = "&panx="+this.panx+"&pany="+this.pany;
		// Scale values
		scale = (this.scale) ? "&scale="+this.scale : "";
		zooming = (this.ds) ? "&ds="+this.ds : "";

		var newUrlParams = "client="+this.client+maplocation+scale+size+panning+zooming;
		return newUrlParams;
	}
	// Draw Map
	this.drawMap = function drawMap() {
		this.urlParams = this.buildUrlParams();
		var endtag = (this.xhtml == 'true') ? " />" : ">";
		var aerialImgSrc = this.aerialcgiurl+"?"+this.urlParams;
		var mapImgSrc;
        if ((this.type == "hybrid") || (this.type == "overlay") || (this.type == "aerial")) {
            mapImgSrc = this.mapcgiurl+"?overlay=true&"+this.urlParams;
        } else {
            mapImgSrc = this.mapcgiurl+"?"+this.urlParams;
        }

		var staticImgTag = "<img src='"+aerialImgSrc+"' id='staticImg' name='staticImg' alt='map'"+endtag;
		var mapDivVisibility;
        if (!(this.type))
            this.type = 'map';

		if (this.type == "hybrid") {
		    mapDivVisibility = "visible";
		    mapOverlayVisibility = "visible";
		} else if (this.type == "overlay") {
		    mapDivVisibility = "visible";
		    mapOverlayVisibility = "hidden";
		} else if (this.type == "aerial") {
		    mapDivVisibility = "hidden";
		    mapOverlayVisibility = "hidden";
		} else {
		    staticImgTag = "<img src='"+mapImgSrc+"' id='staticImg' name='staticImg' alt='map'"+endtag;
		    mapDivVisibility = "hidden";
		    mapOverlayVisibility = "hidden";
		}

		document.write('<script src="http://www.multimap.com/scripts/overlay10.js" type="text/javascript"></script>');
		document.write('<input type="hidden" name="type" id="type" value="'+this.type+'">');
		document.write('<div style="position:absolute;visibility:'+mapDivVisibility+'" id="mapDiv" onmousemove="if (document.getElementById(\'type\').value == \'overlay\') displayMap(event.pageX, event.pageY, event.clientX, event.clientY, staticImg.width, staticImg.height)" onmouseout="if (document.getElementById(\'type\').value == \'overlay\') document.getElementById(\'mapOverlay\').style.visibility=\'hidden\'">');
		document.write('	<img id="mapDivImg" src="'+aerialImgSrc+'"'+endtag);
		document.write('	<div style="position:absolute;top:0;left:0;visibility:'+mapOverlayVisibility+';opacity:'+this.opacity/100+';filter:alpha(opacity='+this.opacity+')" id="mapOverlay">');
		document.write('		<img id="mapOverlayImg" src="'+mapImgSrc+'"'+endtag);
		document.write('	</div>');
		document.write('</div>');
		document.write(staticImgTag);
	}
	// Refresh map view
	this.redrawMap = function RedrawMap() {
		this.urlParams = this.buildUrlParams();
		// Update image with new map url.
		document.getElementById('type').value = this.type;
		if (this.type == "hybrid") {
			document.getElementById('mapDiv').style.visibility = "visible";
			document.getElementById('mapOverlay').style.visibility = "visible";
			if ((navigator.userAgent.indexOf("MSIE")) >= 0)
				document.getElementById('mapOverlay').style.clip = "rect(auto)";
			else
				document.getElementById('mapOverlay').style.clip = "";
			document.getElementById('mapOverlay').style.filter = "alpha(opacity="+this.opacity+")";
			document.getElementById('mapOverlay').style.opacity = this.opacity/100;
			document.getElementById('mapDivImg').src = this.aerialcgiurl+"?"+this.urlParams;
			document.getElementById('mapOverlayImg').src = this.mapcgiurl+"?overlay=true&"+this.urlParams;
            document.getElementById('staticImg').src = this.mapcgiurl+"?overlay=true&"+this.urlParams;
		} else if (this.type == "overlay") {
			document.getElementById('mapDiv').style.visibility = "visible";
			document.getElementById('mapOverlay').style.visibility = "hidden";
			document.getElementById('mapOverlay').style.filter = "alpha(opacity="+this.opacity+")";
			document.getElementById('mapOverlay').style.opacity = this.opacity/100;
			document.getElementById('mapDivImg').src = this.aerialcgiurl+"?"+this.urlParams;
			document.getElementById('mapOverlayImg').src = this.mapcgiurl+"?overlay=true&"+this.urlParams;
            document.getElementById('staticImg').src = this.mapcgiurl+"?overlay=true&"+this.urlParams;
		} else if (this.type == "aerial") {
			document.getElementById('mapDiv').style.visibility = "hidden";
			document.getElementById('mapOverlay').style.visibility = "hidden";
			document.getElementById('staticImg').src = this.aerialcgiurl+"?"+this.urlParams;
		} else {
			document.getElementById('mapDiv').style.visibility = "hidden";
			document.getElementById('mapOverlay').style.visibility = "hidden";
			document.getElementById('staticImg').src = this.mapcgiurl+"?"+this.urlParams;
		}			
	}
	
	// Debug alerts, only display if this.debug returns true.
	this.flog = function flog(msg, type) {
		if (type == "D" && !(this.debug)) {
			return;
		} else {
			alert(msg);
		}
	}
}
