var map = null;
var gMap;
window.onload = function()
{
    if (typeof GUnload == 'undefined')
    {
        return;
    }

    window.onunload = GUnload;
    map = new mapScript( mapConfig );
    if (!map.ok)
    {
        return;
    }
    map.initGMap();
}

function mapScript( config )
{
    this.ok = false;
    this.config = config;

    if (!this.config)
    {
        return;
    }

    this.box = document.getElementById( this.config.boxId );
    if (
    (!this.box)
    ||
    (!GBrowserIsCompatible())
    )
    {
        return;
    }

    this.map = null;
    this.ok = true;
}

mapScript.prototype.initGMap = function()
{
    this.map = new GMap2( this.box );
	gMap = this.map;
    var center = new GLatLng( parseFloat ( this.config.center.lat ) , parseFloat ( this.config.center.lng ));

    with (this.map)
    {
        addControl(new GLargeMapControl());

        enableScrollWheelZoom();
        enableDoubleClickZoom();
        enableContinuousZoom();
        setCenter( center , 7 );


        var points = [];
        for (var i=0; i < this.config.points.length; i++)
        {
            var point = new GLatLng( parseFloat ( this.config.points[i].lat ) , parseFloat ( this.config.points[i].lng) );
            points[points.length] = point;
        }

        // GPolygon(points,  strokeColor?,  strokeWeight?,  strokeOpacity?,  fillColor?,  fillOpacity?)
        var polygon = new GPolygon(points, '#30689d', 0, 0.6, '#30689d', 0.6);
        addOverlay(polygon);
    }
    var self = this;
}


