	var map = 0;
    var iconCache = new Array();
    var siteList = new Array();

    function hideLeftFrame()
    {
        var lc = document.getElementById('left_column');
        if (lc)
        {
            lc.style.display = 'none';
        } 
        handleResize();
        return void(0);
    } 

    function calculateElementHeights(elist)
    {
        var total = 0;
        for (var i=0; i<elist.length; i++)
        {
            var thingy = document.getElementById(elist[i]);
            if (thingy)
                total += thingy.clientHeight;
        } 
        return total;
    } 

    function handleResize()
    {
        if (0 <= navigator.appName.indexOf('Microsoft'))
            return void(0);

        try {
            var body = document.getElementsByTagName('body')[0];
            var leftCol = document.getElementById('left_column');
            var lcWidth = 220;  
            if (leftCol && leftCol.style.display=="none")
            {
                lcWidth=0;
            } 

            var totalHeight = body.clientHeight;
            var totalWidth = body.clientWidth;
            
            if (window.innerHeight)
            {
                totalHeight = window.innerHeight - 10;
                totalWidth = window.innerWidth - 10;
            } 
            setElementSize('format_table', 0, totalHeight - 6);
            setElementSize('map', totalWidth - lcWidth - 8, totalHeight - 10);

            var leftCruftHeight = calculateElementHeights(  
                new Array ("before_selector", "after_selector")
            );
            if (leftCruftHeight)
            {
                setElementSize('contains_selector', 0, totalHeight - leftCruftHeight - 4);
                var sel = document.getElementById("grave_selector");
                if (sel)
                { 
	                var olist = sel.options;

                    var spaceAvailable =  totalHeight - leftCruftHeight - 24; 
                    var lineht = olist[0].clientHeight;
                    if (lineht > 0)
                    {
                        var lines = Math.floor (spaceAvailable / lineht);
                        if (lines >4 )
                            sel.size = lines;
                    }
                }  

            } 
        }
        catch (ex) {
            alert("exception " + ex);
        }
        return void(0);
    }

    function setElementSize(id, width, height)
    {
        var box = document.getElementById(id);
        if (! box)
            return void(0);

        if (height)
            box.style.height = height + "px";
            /* box.style.clientHeight = height; */

        if (width)
            box.style.width = width + "px";

        return void(0);
    }

    function _getSelectedOption(selector)
    {
	    var olist = selector.options;

		var selectedIndex = -1;
	    for (var i=0; i< olist.length; i++)
		{
			if (olist[i].selected && olist[i].value)
			{
				return olist[i];
			}
		}
        return 0;
    } 

    var prevSite = 0;

	function selectLocation(selector, siteList)
	{
		// var selector = document.forms.infoform.elements["listing"];
        var option = _getSelectedOption(selector); 
		if (! option)
		{
			alert("Select a location from the list");
			return;
		}

        var site = siteList["" + option.value ];
        if (!site)
        {
            alert("javascript error, cannot locate point " + option.value);
            return 0;
        } 

        if (prevSite)
        {
            var goodIcon = prevSite.getIcon().image;
            if (goodIcon)
                prevSite._marker.setImage(goodIcon);
        } 

      	map.panTo(site._point);
      	map.setCenter(site._point);  // setCenter is just too abrupt; panTo is slower.
//        alert(map.getZoom());
        if (map.getZoom()<13)   // big numbers are closer in.
   		    map.setZoom(13);

        site._marker.setImage('http://www.graveyards.com/images/mapicon_high.png');

        prevSite = site;

        return void(0);
	} 

	function setGraveyardSelector(point)
	{
		var pointlat = point.lat();
		var pointlon = point.lng();

		var foundit=0;	
		var selector = document.forms.infoform.elements["listing"];

	    var olist = selector.options;
	    for (var i=0; i< olist.length; i++)
   	 	{
			olist[i].selected=false;
			var value = olist[i].value;
			var comma = value.indexOf(",");
			if (comma)
			{
				var thislat = value.substr(0,comma);
				var thislon = value.substr(comma + 1);
				if ( (pointlat == thislat) && (pointlon==thislon))
				{
					olist[i].selected=1;
					foundit=1;
				}
			} 
		}

		if (! foundit)
		{
			/* alert("could not find " + pointlat + ", " + pointlon); */
		}
	} 

    function createMarker(point, icon, title, html) {

        var shortname = title.replace(" Cemetery", "");

        var opts = {
            "icon": icon,
            "clickable" : true,
            "labelText": shortname,
            "labelOffset": new GSize(0,-2)
        };

        var marker = new LabeledMarker(point, opts);

        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });

        GEvent.addListener(marker,"mouseover", function() { 
			setGraveyardSelector(point);
		});        

/*        GEvent.addListener(marker,"mouseout", function() { 
 			document.forms.infoform.elements["thisloc"].value = 
				"(" + title + ")"
		});        
*/

        return marker;
      }

    
        function loadIcon (colour)
	    { 
            var icon = new GIcon();
		    icon.image = "http://www.graveyards.com/images/mapicon_" + colour + ".gif";
		    icon.iconSize = new GSize(18, 20);
		    icon.iconAnchor = new GPoint(9, 20);

		    icon.shadow = "http://www.graveyards.com/images/mapicon_shadow.gif";
		    icon.shadowSize = new GSize(22, 20);
		    icon.infoWindowAnchor = new GPoint(5, 1);
            iconCache[colour] = icon;
    		return icon;
	    }
