Type.registerNamespace( "MooreWilson.Web.UI.WebControls" );

MooreWilson.Web.UI.WebControls.GoogleMapWebControl = function( element )
{   
    MooreWilson.Web.UI.WebControls.GoogleMapWebControl.initializeBase( this, [ element ] );
}

// Map control enumerator
MooreWilson.Web.UI.WebControls.GoogleMapWebControl.MapControls = 
{
    LargeMapControl : 1,
    SmallMapControl : 2,
    ScaleControl : 3,
    ToogleControl : 4,
    Hierarchical : 5,
    OverviewMapControl : 6,
    SmallZoomControl : 7,
    NavLabelControl : 8
}

MooreWilson.Web.UI.WebControls.GoogleMapWebControl.prototype =
{
    initalize: function()
    {
        MooreWilson.Web.UI.WebControls.GoogleMapWebControl.callBaseMethod( this, 'initalize' );
    },
    
    initaliseMap: function()
    {
        if( $get( this._divId ) != null && GBrowserIsCompatible() )
        {
            this.m_Map = new google.maps.Map2( $get( this._divId ) );
            this.m_MarkerCount = 0;
            window.onunload = google.maps.Unload;
            return true;
        }
        else
            return false;
    },
    
    setMapType : function( mapType )
    {
        this.m_Map.setMapType( mapType );
    },

    addListener: function( eventName, eventHandler )
    {
        GEvent.addListener( this.m_Map, eventName, eventHandler );
    },
    
    setCenter: function( latitude, longitude, zoomLevel )
    {
        this.m_Map.setCenter( new google.maps.LatLng( latitude, longitude ), zoomLevel );
    },

    addMapControlWithPosition: function( controlType, anchor, xOffset, yOffset )
    {
        var position = new GControlPosition( anchor, new GSize( xOffset, yOffset ) );
        switch( controlType )
        {
            case MooreWilson.Web.UI.WebControls.GoogleMapWebControl.MapControls.LargeMapControl:
                this.m_Map.addControl( new GLargeMapControl(), position );
                break;
            case MooreWilson.Web.UI.WebControls.GoogleMapWebControl.MapControls.SmallMapControl :
                this.m_Map.addControl( new GSmallMapControl(), position );
                break;
            case MooreWilson.Web.UI.WebControls.GoogleMapWebControl.MapControls.ScaleControl:
                this.m_Map.addControl( new GScaleControl(), position );
                break;
            case MooreWilson.Web.UI.WebControls.GoogleMapWebControl.MapControls.ToogleControl:
                this.m_Map.addControl( new GMapTypeControl(), position );
                break;
            case MooreWilson.Web.UI.WebControls.GoogleMapWebControl.MapControls.Hierarchical:
                this.m_Map.addControl( new GHierarchicalMapTypeControl(), position );
                break;
            case MooreWilson.Web.UI.WebControls.GoogleMapWebControl.MapControls.OverviewMapControl :
                this.m_Map.addControl( new GOverviewMapControl(), position );
                break;
            case MooreWilson.Web.UI.WebControls.GoogleMapWebControl.MapControls.SmallZoomControl:
                this.m_Map.addControl( new GSmallZoomControl(), position );
                break;
            case MooreWilson.Web.UI.WebControls.GoogleMapWebControl.MapControls.NavLabelControl:
                this.m_Map.addControl( new GNavLabelControl(), position );
                break;
        }
    },

    addMapControl: function( controlType )
    {
        switch( controlType )
        {
            case MooreWilson.Web.UI.WebControls.GoogleMapWebControl.MapControls.LargeMapControl:
                this.m_Map.addControl( new GLargeMapControl() );
                break;
            case MooreWilson.Web.UI.WebControls.GoogleMapWebControl.MapControls.SmallMapControl :
                this.m_Map.addControl( new GSmallMapControl() );
                break;
            case MooreWilson.Web.UI.WebControls.GoogleMapWebControl.MapControls.ScaleControl:
                this.m_Map.addControl( new GScaleControl() );
                break;
            case MooreWilson.Web.UI.WebControls.GoogleMapWebControl.MapControls.ToogleControl:
                this.m_Map.addControl( new GMapTypeControl() );
                break;
            case MooreWilson.Web.UI.WebControls.GoogleMapWebControl.MapControls.Hierarchical:
                this.m_Map.addControl( new GHierarchicalMapTypeControl() );
                break;
            case MooreWilson.Web.UI.WebControls.GoogleMapWebControl.MapControls.OverviewMapControl :
                this.m_Map.addControl( new GOverviewMapControl() );
                break;
            case MooreWilson.Web.UI.WebControls.GoogleMapWebControl.MapControls.SmallZoomControl:
                this.m_Map.addControl( new GSmallZoomControl() );
                break;
            case MooreWilson.Web.UI.WebControls.GoogleMapWebControl.MapControls.NavLabelControl:
                this.m_Map.addControl( new GNavLabelControl() );
                break;
        }
    },


    addIconMarker: function( point, image, imageSize, shadowImage, shadowImageSize, markerOptions, iconAnchor, infoWindowAnchor )
    {
        var icon = new GIcon();
        icon.image = image;
        icon.iconSize = imageSize;
        if( shadowImage.length > 0 )
        {
            icon.shadow = shadowImage;
            icon.shadowSize = shadowImageSize;
        }
        icon.iconAnchor = iconAnchor;
	    icon.infoWindowAnchor = infoWindowAnchor;
        markerOptions.icon = icon;
        var marker;
        marker = new GMarker( point, markerOptions );
        marker.Id = this.m_MarkerCount++;
        this.m_Map.addOverlay( marker );
        return marker;
    },

    addMarker: function( point, markerOptions )
    {
        var marker = new GMarker( point, markerOptions );
            marker.Id = this.m_MarkerCount++;
        this.m_Map.addOverlay( marker );
        return marker;
    },

    removeMarker: function( marker )
    {
        this.m_Map.removeOverlay( marker );
    },

    addMarkerListener: function( marker, eventName, eventHandler )
    {
        GEvent.addListener( marker, eventName, eventHandler );
    },

    getGoogleMap: function()
    {
        return this.m_Map;
    },
    
    get_divId: function()
    {
        return this._divId;
    },
    
    set_divId: function( value )
    {
        this._divId = value;
    },
    
    dispose: function()
    {
        this.m_Map = null;
        google.maps.Unload();
        
        MooreWilson.Web.UI.WebControls.GoogleMapWebControl.callBaseMethod( this, 'dispose' );
    }
    
}

MooreWilson.Web.UI.WebControls.GoogleMapWebControl.registerClass( 'MooreWilson.Web.UI.WebControls.GoogleMapWebControl', Sys.Component, Sys.IDisposable );


if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();