//<![CDATA[
/*
Copyright (c) 2002 The University of Kansas Natural History Museum and 
Biodiversity Research Center (NHM & BRC)

All rights reserved.

Developed by: 		Dave Vieglais
                    NHM & BRC 
                    http://speciesanalyst.net

Permission is hereby granted, free of charge, to any person obtaining a 
copy of this software and associated documentation files (the "Software"), 
to deal with the Software without restriction, including without limitation 
the rights to use, copy, modify, merge, publish, distribute, sublicense, 
and/or sell copies of the Software, and to permit persons to whom the Software 
is furnished to do so, subject to the following conditions: 

	* Redistributions of source code must retain the above copyright notice, 
	  this list of conditions and the following disclaimers. 
	* Redistributions in binary form must reproduce the above copyright notice, 
      this list of conditions and the following disclaimers in the documentation 
	  and/or other materials provided with the distribution. 
	* Neither the names of Dave Vieglais, NHM & BRC, nor the names of its 
	  contributors may be used to endorse or promote products derived from this 
	  Software without specific prior written permission. 
	  
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS 
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. 
	
'$Author: vieglais $'
'$Date:  $'
'$Revision:  $'

Contact Info
------------

If you have questions, concerns, criticisms, etc somewhat related to this software, 
it's operation, and/or installation please contact the author, 
Dave Vieglais at "vieglais at ku dot edu".

Modified by A P R Cooper
						British Antarctic Survey
						April 2005
						November 2006 (add rubberband zoom)

*/
var ie55up = true;

//finds the image with "name" within the document "doc".
//In netscape, this method recurses through all layers until the
//image is found or not found.
//in:
//  name: the name of the image
//  doc: the document to search in - usually start with window.document.
//out: image object or null if not found.

	 
//{{{ findImage(name, doc)
function findImage(name, doc)
{
    var i, img;
    for (i = 0; i < doc.images.length; i++)
    {
        if (doc.images[i].name == name)
            return doc.images[i];
    }
    for (i = 0; i < doc.layers.length; i++)
    {
        if ((img = findImage(name, doc.layers[i].document)) != null)
        {
            img.container = doc.layers[i];
            return img;
        }
    }
    return null;
}//}}}

//============= ogcMap object ==============
//internal method to generate the url for the layer
//in: index of the layer
//out: string, url of image
//{{{ ogcmap_layer_url(aLayer)
function ogcmap_layer_url(aLayer)
{
    var sURL = aLayer[0];
    sURL += "&REQUEST=GetMap";
    sURL += "&WIDTH="+this.mapWidthPX;
    sURL += "&HEIGHT="+this.mapHeightPX;
    if (aLayer[2])
        sURL += "&TRANSPARENT=TRUE";
    else
        sURL += "&TRANSPARENT=FALSE";
    sURL += "&LAYERS=" + aLayer[1];
    sURL += "&BBOX=" + this.cBounds[0] + "," + this.cBounds[1] + "," + this.cBounds[2] + "," + this.cBounds[3];
    if (!aLayer[2])
	    sURL += "&BGCOLOR=" + this.bgColor;
	sURL += "&EXCEPTIONS=application/vnd.ogc.se_inimage";
	sURL += "&FORMAT=" + aLayer[4];
	//alert(sURL);
    return sURL;
}//}}}

//{{{ ogcmap_capabilities_url(aLayer)
function ogcmap_capabilities_url(aLayer)
{
	var sURL = aLayer[0];
	sURL += "&REQUEST=GetCapabilities";
	return sURL;
}//}}}

//{{{ ogcmap_queryLayerURL(aLayer,x,y)
function ogcmap_queryLayerURL(aLayer,x,y)
{
//	var sURL = aLayer[0];
//	sURL += "&REQUEST=GETFEATUREINFO";
//	sURL += "&WIDTH="+this.mapWidthPX;
//	sURL += "&HEIGHT="+this.mapHeightPX;
//	sURL += "&LAYERS=" + aLayer[1];
//	sURL += "&BBOX=" + this.cBounds[0] + "," + this.cBounds[1] + "," + this.cBounds[2] + "," + this.cBounds[3];
//	sURL += "&EXCEPTIONS=application/vnd.ogc.se_inimage";
//	sURL += "&QUERY_LAYERS="+aLayer[1];
//	sURL += "&FEATURE_COUNT=10";
//	sURL += "&X=" + x;
//	sURL += "&Y=" + y;
//	sURL += "&RADIUS=3";
//	sURL += "&FORMAT=text/plain";
//	sURL += "&INFO_FORMAT=text/plain";
//		alert(sURL);
  var dd = this.pixelToDD(x,y);
  var dx = this.cBounds[2] - this.cBounds[0];
	var projRadius = 4*dx/this.mapWidthPX;
	sURL = "http://www.add.scar.org:8080/geoserver/description.jsp?requestType=projRadius&";
	sURL += "cenX="+dd[0]+"&cenY="+dd[1]+"&radius="+projRadius;
	return sURL;
}//}}}

//converts pixel to decimal degree coordinates
//in: xp = x coordinate, yp= y coordinate
//out: array[0..1], 0 = longitude, 1 = latitude
//{{{ ogcmap_pixelToDD(xp,yp)
function ogcmap_pixelToDD(xp,yp)
{
    var aDD = new Array(0,0);
    var dx = this.cBounds[2] - this.cBounds[0];
    var dy = this.cBounds[3] - this.cBounds[1];
    aDD[0] = this.cBounds[0] + (dx*xp)/this.mapWidthPX;
    aDD[1] = this.cBounds[3] - (dy*yp)/this.mapHeightPX;
    return aDD;
}//}}}

//adds a layer to the map
//in: url = base url of layer
//    name = ogc wms name of the layer
//    transparent = boolean indicating if the layer should provide a transparent background
//    visible = boolean in idcating if the layer is to be retrieved and drawn
//		minscale = minimum scale at which the layer shall be displayed
//		maxscale = maximum scale at which the layer shall be displayed
// Note: Scale is calculated assuming a pixel = 0.28mm, as specified in the OGC Styled
// Layer Descriptor language (OGC 02-070).
//
// Modified to provide scale dependence by A P R Cooper, British Antarctic Survey,
// April 2005
//
//out: no return value
//{{{ ogcmap_addLayer(url,name,transparent,visible,format,minscale,maxscale,displayname)
function ogcmap_addLayer(url,name,transparent,visible,format,minscale,maxscale,displayname)
{
	var fmt = format;
	var minsc = minscale;
	var maxsc = maxscale;
	var dname = displayname;
	if ((!fmt) || (fmt == "undefined"))	fmt = "image/png";
	if ((!minsc) || (minsc == "undefined")) minsc = 0;
	if ((!maxsc) || (maxsc == "undefined")) maxsc = Infinity;
	if ((!dname) || (dname == "undefined")) dname = name;
	
    var a = new Array(url,name,transparent,visible,fmt,minsc,maxsc,dname);
    this.layers[this.layers.length] = a;
}//}}}


//{{{ ogcmap_queryUI(x,y)
function ogcmap_queryUI(x,y)
{
	if (!this.query)
		return;
	if (this.queryLayer < 0)
		return;
	if (this.queryLayer >= this.layers.length)
		return;
	var sURL = this.queryLayerURL(this.layers[this.queryLayer],x,y);
	var w = window.open(sURL,this.prefix + "_QlayerUI","height=300,width=300,resizable=yes,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes",false);
}//}}}

//generates a user interface for turning on/off layers
//{{{ ogcmap_layerUI()
function ogcmap_layerUI()
{
	var i = 0;
	var s = "<html><head>\n";
	var id = "window.opener.g_ogcMaps[" + this.gid + "]";
	s += "<link rel=\"StyleSheet\" type=\"text/css\" href=\"ADD.css\">\n";
	s+= "</head><body>\n";
	s +="<form name='lyrctrl'>\n"
	s += "<input type='button' value='Done' onclick='" + id + ".redraw();window.close();'> ";
	s += "<input type='checkbox'";
	if (this.autoRefresh)
		s += " checked='1'";
	s += " onclick='"+id+".toggleRefresh()'>Auto<br/>";
	s += "<table class=\"namelist\">";
	var worldWidth = this.cBounds[2] - this.cBounds[0];
	var cScale = worldWidth/(this.mapWidthPX * 0.00028);
	s += "<thead><td>Layer</td><td>Visible</td><td>Inquire</td></thead>";
	for (i=0; i < this.layers.length; i++)
	{
		if (((cScale > this.layers[i][5]) && (cScale <= this.layers[i][6]))) {
			s+= "<tr><td>";
			s += "<a href='" + this.capabilitiesURL(this.layers[i]) + "' target='_new'>" + this.layers[i][7] + "</a></td><td>";
			s += "<input type='checkbox'";
			if (this.layers[i][3]) s += " checked='1'";
			s += " onclick='javascript:" + id + ".toggleLayer(" + i + ")'></input></td><td>";
			s += "<input type=\"radio\"";
			if (this.queryLayer == i) s += " checked";
			s += " onclick='"+id+".queryLayer = "+i+"' name=\"setQueryLayer\"></input></td></tr>\n";
		}
	}
	s += "</table>\n";
	s += "<input type='button' value='Done' onclick='" + id + ".redraw();window.close();'><br />";
	s += "</form>\n";
	s += "</body></html>";
		
	var w = window.open("about:blank",this.prefix + "_layerUI","height=300,width=200,resizable=yes,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes",false);
	var d = w.document;
	d.open();
	d.write(s);
	d.close();
}//}}}

//{{{ ogcmap_toggleLayer(idx)
function ogcmap_toggleLayer(idx)
{
	if (idx < 0)
		return;
	if (idx >= this.layers.length)
		return;
	this.layers[idx][3] = ! this.layers[idx][3];
	if (this.autoRefresh)
		this.redraw();
}//}}}

//{{{ ogcmap_toggleRefresh()
function ogcmap_toggleRefresh()
{
	this.autoRefresh = !this.autoRefresh;
}//}}}

//redraws all the map layers
//
// Modified by A P R Cooper, British Antarctic Survey, April 2005 to provide
// scale dependent display of layers
//
//{{{ ogcmap_redraw()
function ogcmap_redraw()
{
    var sURL = "";
    var worldWidth = this.cBounds[2] - this.cBounds[0];
    this.cScale = worldWidth/(this.mapWidthPX * 0.00028);
    if (document.all) {
	    this.scaleBar = document.images[this.prefix+"sbar"];
    } else {
	    this.scaleBar = findImage(this.prefix+"sbar",document);
    }
    var scaleWidth = Math.floor(Math.log(worldWidth)/Math.log(10));
    scaleWidth = Math.pow(10,scaleWidth);
    var barWidth = scaleWidth / 10;
    var barUnits = 'm';
    var sbimage = "images/scale10.gif";
    if (scaleWidth < (worldWidth / 5.0)) {
	    scaleWidth = scaleWidth * 2.5;
	    barWidth = scaleWidth / 5;
	    var sbimage = "images/scale05.gif";
    }
    var scalePX = scaleWidth / (this.cScale * 0.00028);
    if (barWidth / 1000 >= 1) {
	    barWidth /= 1000;
	    barUnits = 'km';
    }
    this.scaleBar.width = scalePX;
    this.scaleBar.src = sbimage;
    this.scaleBar.alt = barWidth+" "+barUnits;
    sbarCaption = document.getElementById(this.prefix+"sbarText");
    sbarCaption.innerHTML="Bar width = "+barWidth+" "+barUnits;
    for (var i=0; i < this.layers.length; i++)
    {
	    sURL = this.layer_url(this.layers[i]);
	    var img = 0;
	    if (document.all)
	    {
		    img = document.images[this.prefix+i];
	    }
	    else
	    {
		    img = findImage(this.prefix+i,document);
	    }
	    if ((this.layers[i][3]) && ((this.cScale > this.layers[i][5]) && (this.cScale <= this.layers[i][6])))
	    {
		    img.src = sURL;
	    }
	    else
	    {
		    img.src = "blank.gif";
	    }
    }
}//}}}

//sets the current map extents to the full extents and redraws the layers
//{{{ ogcmap_fullExtent()
function ogcmap_fullExtent()
{
    this.cBounds[0] = this.mapBounds[0];
    this.cBounds[1] = this.mapBounds[1];
    this.cBounds[2] = this.mapBounds[2];
    this.cBounds[3] = this.mapBounds[3];
    this.redraw();
}//}}}

//sets the current extent to the previous extent and redraws the layers
//{{{ ogcmap_previousExtent()
function ogcmap_previousExtent()
{
    this.cBounds[0] = this.prevBounds[0];
    this.cBounds[1] = this.prevBounds[1];
    this.cBounds[2] = this.prevBounds[2];
    this.cBounds[3] = this.prevBounds[3];
    this.redraw();
}//}}}

//zooms in on the specified pixel coordinate
//{{{ ogcmap_zoom(xp,yp)
function ogcmap_zoom(xp,yp)
{
    this.prevBounds[0] = this.cBounds[0];
    this.prevBounds[1] = this.cBounds[1];
    this.prevBounds[2] = this.cBounds[2];
    this.prevBounds[3] = this.cBounds[3];

    var dx = this.cBounds[2] - this.cBounds[0];
    dx = dx / this.zoomFactor;
    var dy = this.cBounds[3] - this.cBounds[1];
    dy = dy / this.zoomFactor;

    var dd = this.pixelToDD(xp,yp);

    this.cBounds[0] = dd[0]-(dx/2.0);
    this.cBounds[2] = dd[0]+(dx/2.0);
    this.cBounds[1] = dd[1]-(dy/2.0);
    this.cBounds[3] = dd[1]+(dy/2.0);

    this.redraw();
}//}}}

//Does the opposite of zoom()
//{{{ ogcmap_zoomOut(xp,yp)
function ogcmap_zoomOut(xp,yp)
{
    this.prevBounds[0] = this.cBounds[0];
    this.prevBounds[1] = this.cBounds[1];
    this.prevBounds[2] = this.cBounds[2];
    this.prevBounds[3] = this.cBounds[3];

    var dx = this.cBounds[2] - this.cBounds[0];
    dx = dx * this.zoomFactor;
    var dy = this.cBounds[3] - this.cBounds[1];
    dy = dy * this.zoomFactor;

    var dd = this.pixelToDD(xp,yp);

    this.cBounds[0] = dd[0]-(dx/2.0);
    this.cBounds[2] = dd[0]+(dx/2.0);
    this.cBounds[1] = dd[1]-(dy/2.0);
    this.cBounds[3] = dd[1]+(dy/2.0);

    this.redraw();
}//}}}

//Zooms to the best extent for a specified box 
//{{{ ogcmap_zoomExtent(x0,y0,x1,y1)
function ogcmap_zoomExtent(x0,y0,x1,y1)
{
    this.prevBounds[0] = this.cBounds[0];
    this.prevBounds[1] = this.cBounds[1];
    this.prevBounds[2] = this.cBounds[2];
    this.prevBounds[3] = this.cBounds[3];

    var xpc = (x0+x1)/2.0;
		var ypc = (y0+y1)/2.0;
		var cen = this.pixelToDD(xpc,ypc);
		var bl = this.pixelToDD(Math.min(x0,x1),Math.min(y0,y1));
		var tr = this.pixelToDD(Math.max(x0,x1),Math.max(y0,y1));
		
		zf1 = (tr[0]-bl[0])/(this.cBounds[2] - this.cBounds[0]);
		zf2 = (bl[1]-tr[1])/(this.cBounds[3] - this.cBounds[1]);
		
		zf = Math.max(zf1,zf2);

    var dx = this.cBounds[2] - this.cBounds[0];
    dx = dx * zf;
    var dy = this.cBounds[3] - this.cBounds[1];
    dy = dy * zf;
//		alert(cen+" "+dx+" "+dy+" "+zf);

    this.cBounds[0] = cen[0]-(dx/2.0);
    this.cBounds[2] = cen[0]+(dx/2.0);
    this.cBounds[1] = cen[1]-(dy/2.0);
    this.cBounds[3] = cen[1]+(dy/2.0);

    this.redraw();
}//}}}

//zooms in on the specified map coordinate
//in: x = longitude, y = latitude
//{{{ ogcmap_zoomDD(x,y)
function ogcmap_zoomDD(x,y)
{
    this.prevBounds[0] = this.cBounds[0];
    this.prevBounds[1] = this.cBounds[1];
    this.prevBounds[2] = this.cBounds[2];
    this.prevBounds[3] = this.cBounds[3];

    var dx = this.cBounds[2] - this.cBounds[0];
    dx = dx / this.zoomFactor;
    var dy = this.cBounds[3] - this.cBounds[1];
    dy = dy / this.zoomFactor;

    this.cBounds[0] = x-(dx/2.0);
    this.cBounds[2] = x+(dx/2.0);
    this.cBounds[1] = y-(dy/2.0);
    this.cBounds[3] = y+(dy/2.0);

    this.redraw();
}//}}}

//{{{ ogcmap_pan(xp,yp)
function ogcmap_pan(xp,yp)
{
    this.prevBounds[0] = this.cBounds[0];
    this.prevBounds[1] = this.cBounds[1];
    this.prevBounds[2] = this.cBounds[2];
    this.prevBounds[3] = this.cBounds[3];

    var dx = this.cBounds[2] - this.cBounds[0];
    var dy = this.cBounds[3] - this.cBounds[1];
    var dd = this.pixelToDD(xp,yp);

    this.cBounds[0] = dd[0]-(dx/2.0);
    this.cBounds[2] = dd[0]+(dx/2.0);
    this.cBounds[1] = dd[1]-(dy/2.0);
    this.cBounds[3] = dd[1]+(dy/2.0);

    this.redraw();
}//}}}

//{{{ ogcmap_click(e)
function ogcmap_click(e,obj)
{
	if(!e) e=window.event;
	if (e.button==2) {
		return;
	}
	var mX=null;
	var mY=null;

	var opcode = 0; //0=zoom in, 1=zoom to extent (ctrl), 2=pan (shift)
/*
		Modified by A Paul R Cooper, British Antarctic Survey, April 2005 to
		provide better cross-browser support
*/
	if (typeof(e.offsetX)!="undefined")
	{
		mX = e.offsetX;
		mY = e.offsetY;
	}
	else
		if (typeof(e.layerX)!="undefined")
	{
		mX = e.layerX;
		mY = e.layerY;
	}

	opcode = this.cursorOption;
	if (opcode == 1)
	{
        this.zoom(mX,mY);
    }
    else if (opcode == 2)
    {
        this.zoomOut(mX,mY);
    }
    else if (opcode == 3)
    {
        this.pan(mX,mY);
    }
    else if (opcode == 4)
    {
    	this.queryUI(mX,mY);
    } 
		else if (opcode == 0 ) {
			if (this.clickNumber==0) {
				this.anchorX=mX;
				this.anchorY=mY;
				this.clickNumber=1;
				this.focusObject=e.target;
				if (e.srcElement) this.focusObject=e.srcElement;
				this.focusObject.style.cursor="crosshair";
			} else {
				this.clickNumber=0;
				this.zoomExtent(this.anchorX,this.anchorY,mX,mY);
				document.getElementById(this.prefix+"root").style.cursor="auto";
				this.focusObject.style.cursor="auto";
			}
		}
}//}}}


//{{{ ogcmap_setCursorOption(co)
function ogcmap_setCursorOption(co)
{
	this.cursorOption = co;
	var thisButton;
	if (co == 0) this.clickNumber=0;
  for (var i=0; i < 5; i++)
	{
		if (document.all) {
			thisButton = document.images[this.prefix+"button"+i];
		} else {
			thisButton = findImage(this.prefix+"button"+i,document);
		}
		if (i == co) {
			thisButton.border = 2;
		} else {
			thisButton.border = 0;
		}
	}
	
//	alert(this.cursorOption);
}//}}}

    
//{{{ ogcmap_writeInline()
function ogcmap_writeInline()
{
	var gid = this.gid;
	var s = "";
	var sdiv = "<div style=\"width:" + this.mapWidthPX + "px; height:" + this.mapHeightPX;
	sdiv += "px; margin:0; padding:0; position:absolute; border-style:solid; border-width:2px; border-color:#0000ff; ";
	sdiv+= "\" id=\""+this.prefix+"root\">";	
  var swh = "width=\"" + this.mapWidthPX + "px\" height=\"" +this.mapHeightPX + "px\"";
	s += "<div style=\"width:" + this.mapWidthPX + "px; height:" + this.mapHeightPX;
	s += "px; ";
	s += "\" name=\"" + this.prefix+"\">";	

  var nlayers = this.layers.length;
  for (var i=0; i < nlayers-1; i++)
	{
		s += sdiv + "<img name=\"" + this.prefix+i+ "\" src=\"blank.gif\" " + swh + " ></img></div>\n";
	}
	s += sdiv + "<img name=\""+this.prefix+i+"\" onmousedown=\"g_ogcMaps["+gid;
	s += "].click(event,this);\" ";
	s += swh + " src=\"blank.gif\"></img></div>\n";
	s += "<img src=\"blank.gif\" width=\"1px\" height=\"" + this.mapHeightPX + "px\"></img>";
	// Control button bar
	
	s += '<div class="mapButtons" style="left: ' + (this.mapWidthPX + 5) + 'px">';
	s += '<table name="'+this.prefix+'bbar">';
	s += '<tr><td><img class="mapButton" border="2" name="'+this.prefix+'button0" alt="Zoom by clicking twice" title="Zoom by clicking twice" src="images/zoom_2click.gif" onClick="g_ogcMaps['+gid+'].setCursorOption(0)" /></td></tr>';
	s += '<tr><td><img class="mapButton" border="0" name="'+this.prefix+'button1" alt="Fixed Zoom In" title="Fixed Zoom In" src="images/zoomin.gif" onClick="g_ogcMaps['+gid+'].setCursorOption(1)" /></td></tr>';
	s += '<tr><td><img class="mapButton" border="0" name="'+this.prefix+'button2" alt="Zoom Out" title="Zoom Out" src="images/zoomout.gif" onClick="g_ogcMaps['+gid+'].setCursorOption(2)" /></td></tr>';
	s += '<tr><td><img class="mapButton" border="0" name="'+this.prefix+'button3" alt="Pan to cursor" title="Pan to Cursor" src="images/pan.gif" onClick="g_ogcMaps['+gid+'].setCursorOption(3)" /></td></tr>';
	s += '<tr><td><img class="mapButton" border="0" name="'+this.prefix+'button4" alt="Get Info" title="get Info" src="images/info.gif" onClick="g_ogcMaps['+gid+'].setCursorOption(4)" /></td></tr>';
	s += '<tr><td><img class="mapButton" border="0" src="images/previous.gif" alt="Previous Extent" title="PreviousExtent" onClick="g_ogcMaps['+gid+'].previousExtent()" /></td></tr>';
	s += '<tr><td><img class="mapButton" border="0" src="images/refresh.gif" alt="Refresh" title="Refresh" onClick="g_ogcMaps['+gid+'].redraw()" /></td></tr>';
	s += '<tr><td><img class="mapButton" border="0" src="images/fullview.gif" alt="Original Extent" title="Original Extent" onClick="g_ogcMaps['+gid+'].fullExtent()" /></td></tr>';
//	s += '<tr><td><img class="mapButton" border="0" src="images/layers.gif" alt="Open Layer menu" title="Open Layer Menu" onClick="g_ogcMaps['+gid+'].layerUI()" /></td></tr>';
	s += '</table></div>';
	s += '</div>\n';
	

	s += '<table border="0" width="' + this.mapWidthPX + 'px"><tr><td align="center">\n';
	s += '<img class="scalebar" alt="scalebar" border="1" name="'+this.prefix+'sbar" height="10px" width="'+this.mapWidthPX+'px" src="images/scale10.gif"></img>';
	s += '<p id="'+this.prefix+'sbarText">Bar width undefined</p></td></tr></table>\n';
	s +="<div style=\"visibility:hidden; width:0px; height:0px; margin:0; padding:0; position:absolute; border: 1px dashed red;\" id=\"rubberBand\"></div>";

	document.write(s);
}//}}}

//{{{ ogcMap(gid,prefix,width,height,xmin,ymin,xmax,ymax)
function ogcMap(gid,prefix,width,height,xmin,ymin,xmax,ymax)
{
//properties
    this.gid = gid;
    this.prefix = prefix;
    this.mapWidthPX = width;
    this.mapHeightPX = height;
    this.mapBounds = new Array(xmin,ymin,xmax,ymax);
    this.layers = new Array();
    this.bgColor = "0x000000";
    this.pageSize = 0.75;  //75% of width | height
    this.cBounds = new Array(0,0,0,0);
    this.prevBounds = new Array(0,0,0,0);
    this.zoomFactor = 2;
    this.autoRefresh = false;
    this.query = false;
    this.queryLayer = 0;
    this.scaleBar = "";
    this.scaleBarCaption = "";
		this.cursorOption = 0;
		this.anchorX = 0;
		this.anchorY = 0;
		this.clickNumber=0;
		this.trX = 0;
		this.trY = 0;
		this.blX = 0;
		this.blY = 0;
		this.rubberBand = null;
		this.focusObject = null;
		this.cScale=0;

    
//methods
    this.layer_url = ogcmap_layer_url;
    this.pixelToDD = ogcmap_pixelToDD;
    this.writeInline = ogcmap_writeInline;
    this.addLayer = ogcmap_addLayer;
    this.redraw = ogcmap_redraw;
    this.fullExtent = ogcmap_fullExtent;
    this.previousExtent = ogcmap_previousExtent;
    this.zoom = ogcmap_zoom;
		this.zoomExtent = ogcmap_zoomExtent;
    this.zoomOut = ogcmap_zoomOut;
    this.pan = ogcmap_pan;
    this.click = ogcmap_click;
    this.zoomDD = ogcmap_zoomDD;
    this.layerUI = ogcmap_layerUI;
    this.toggleLayer = ogcmap_toggleLayer;
    this.toggleRefresh = ogcmap_toggleRefresh;
    this.queryLayerURL = ogcmap_queryLayerURL;
    this.queryUI = ogcmap_queryUI;
		this.capabilitiesURL = ogcmap_capabilities_url;
		this.setCursorOption = ogcmap_setCursorOption;

    this.cBounds[0] = this.mapBounds[0];
    this.cBounds[1] = this.mapBounds[1];
    this.cBounds[2] = this.mapBounds[2];
    this.cBounds[3] = this.mapBounds[3];
}//}}}

// the global set of dynamically generated maps within the document
var g_ogcMaps = new Array();

//creates a new ogcmap, inserts it into the global map array, and returns the map object created
//{{{ addOGCMap(prefix,width,height,xmin,ymin,xmax,ymax)
function addOGCMap(prefix,width,height,xmin,ymin,xmax,ymax)
{
	var n = g_ogcMaps.length;
	prefix = prefix + "_g"+n+"_";
	var map = new ogcMap(n,prefix,width,height,xmin,ymin,xmax,ymax);
	g_ogcMaps[n] = map;
	return map;
}//}}}


//]]>