DNow.GeographyBar = Class.create( aw.ui.GeographyBar, {

    initialize: function ( properties, events ) {
        this.inheritCSS = true;

        Object.extend( properties, {
            'standardOptions': [
                {'label':'Create Custom Location(s)...','callback':this._onCreateCustomLocationsClicked.bind(this),'icon':'./core/img/GeographyBar/customlocation.png'},
                {'label':'Pick From Geography List...','callback':this._onPickFromGeographyListClicked.bind(this),'icon':'./core/img/GeographyBar/geographylist.png'},
                {'label':'Select Saved Geography...','callback':this._onSelectSavedGeographyClicked.bind(this),'icon':'./core/img/GeographyBar/saved.png'}
            ]
        });

        aw.ui.GeographyBar.prototype.initialize.apply( this, [properties, events] );
    },

    _onCreateCustomLocationsClicked: function ( ) {
        new DNow.CustomRadiiDialog( { 'componentBus': this.componentBus }, { 'onpointscreated': this._onCustomPointsCreated.bind( this ) } );
    },

    _onCustomPointsCreated: function ( geoCollection ) {
        var gm = this.componentBus.getComponentReferences( 'aw.GeographyManager' );
        if ((gm) && (gm.length > 0))
            gm[0].setActiveGeography( geoCollection, true );
    },

    _onEditButtonClick: function ( control ) {
        var gm = this.componentBus.getComponentReferences( 'aw.GeographyManager' );
        if ((gm) && (gm.length > 0)) {
            new DNow.GeographyDialog( { 'componentBus': this.componentBus, 'geoCollection': gm[0].activeGeography }, { 'ongeographyselected': this._onGeographySelected.bind( this ) } );
        }
    },

    _onGeographySelected: function ( geoCollection, minx, miny, maxx, maxy ) {
        var gm = this.componentBus.getComponentReferences( 'aw.GeographyManager' );
        if ((gm) && (gm.length > 0))
            gm[0].setActiveGeography( geoCollection, true, minx, miny, maxx, maxy );
    },

    _onPickFromGeographyListClicked: function ( ) {
        new DNow.GeographyDialog( { 'componentBus': this.componentBus }, { 'ongeographyselected': this._onGeographySelected.bind( this ) } );
    },

    _onSelectSavedGeographyClicked: function ( ) {
        if (this.isSessionValidated() === true)
            new DNow.SavedGeographyDialog( { 'componentBus': this.componentBus } );
        else
            new aw.ui.Dialog.Error( { 'title': 'Error', 'content': 'You must be logged in to access this functionality.' } );
    },

    CLASS_NAME: 'DNow.GeographyBar'
});
