
    var xFn = function()
    {
    };
    
    var Map = xFn;

    var GMapObject = function()
    {
    };
    
    GMapObject.prototype = 
    { 
		// -- PROPERTIES --
		base: xFn,
		gc: xFn,
		gcg: xFn,
		markermgr: xFn,
		marker: xFn,
		icon: xFn,
		mapDiv: "",
		address: "",

		// -- METHODS --
		initialize: function() 
		{
			if( GBrowserIsCompatible() ) 
			{
				this.base = new GMap2(document.getElementById(this.mapDiv));
				this.base.addControl(new GSmallZoomControl());
				this.base.setCenter(new GLatLng(38, -90), 1);
				this.base.setMapType(G_SATELLITE_MAP);
				this.icon = new GIcon(G_DEFAULT_ICON, 'images/marker_red.png');
				this.icon.shadow = 'images/marker_shadow.png';
				this.icon.iconSize = new GSize(64, 64);
				this.icon.shadowSize = new GSize(70, 70);
				this.icon.iconAnchor = new GPoint(32, 32);
			}
		},

		resetDiv: function()
		{
			this.base = xFn;
			this.mapDiv.innerHTML = "No Address Found";
		},

		searchByAddress: function( address ) 
		{
			if (this.gc == xFn) 
			{
				this.gc = new GFactualGeocodeCache();
				this.gcg = new GClientGeocoder(this.gc);
			}

			this.maplocation = this.gc.toCanonical(address);
			this.gcg.getLocations(this.maplocation, this.setMapCenter_C(this));         
		},

		setMapCenter_C: function( x ) 
		{
			// Curried function to maintain parent 'Map' object
			return function( gpm ) 
			{
				var lat = gpm.Placemark[0].Point.coordinates[1];
				var lng = gpm.Placemark[0].Point.coordinates[0];

				x.base.setCenter(new GLatLng(lat,lng), 18);
				x.base.addOverlay(new GMarker(new GLatLng(lat,lng), x.icon));
				x.base.panDirection(-.7,-.5);
			};
		}
    }
    
    var mapIt = function( address ) 
    {
        if( Map == xFn ) 
        {
            Map = new GMapObject();
            Map.mapDiv = 'map'; 
            Map.initialize();
        }
        
        Map.address = address;
        Map.searchByAddress( Map.address );
    }

	var showMap = function() 
	{
		Map.searchByAddress(Map.address);
		var loader = document.getElementById('loadingcontainer');
		loader.style.display = "none";
		loader.innerHTML = '';
	}

//    // DO NOT USE
//    var searchByAddress_C = function(address, region) {
//        // Curried again
//        return function() {
//            var so = new SWFObject('/flash/loading'+region+'.swf', 'loading', '606', '337', '8', '#000000');
//            so.write('loadingcontainer');
//            if (Map == xFn) {
//                Map = new GMapObject();
//                Map.mapDiv = 'map'; 
//                Map.initialize();
//                Map.address = address;
//            }
//        }
//    }

//    var loadGMaps = function() {
//        Map.searchByAddress(Map.address);
//        document.getElementById("loadingcontainer").style.display = "none"; 
//    }
//    var loadGMap = function(address) {
//        Map = new GMapObject();
//        Map.mapDiv = "map"; 
//        Map.initialize();
//        setTimeout('Map.searchByAddress(\''+address+'\');', 3000);
//        
//        // hide the div on the page
//        document.getElementById('lookupcontainer').style.display = 'none';
//    }