var ConnectorEventItem = new Class({

    initialize: function( latitude, longitude ){
        this.latitude = latitude;
        this.longitude = longitude;
        this.initMap();

        var deleteButtons = $$( 'a.delete-button' );
        if( deleteButtons ){
            if( deleteButtons.length > 0 ){
                for( var i = 0; i < deleteButtons.length; i++ ){
                    deleteButtons[i].addEvent( 'click', this.deleteAction.bind(this) );
                }
            }
        }

    },

    deleteAction:function( event ){
        new Event( event ).stop();
        if( confirm( 'Are you sure you want to delete this event? This can\'t be undone!' ) ){
            var target = event.target || event.srcElement;
            var placeId = target.id;
            // make sure we have the right id
            if( placeId.test('del-') ){
                placeId = Number( placeId.substring(4).toInt() );
                new Ajax("/events/js/functions/delete.php",{
                    method:'post',
                    data:'json=json&id=' + placeId,
                    onComplete:function( response ){
                        var result = Json.evaluate( response );
                        if( result ){
                            if( result.stat ){
                                if( result.stat == 'ok' && result.id){
                                   alert( 'This event has been deleted.' );
                                }
                            }
                        }
                    }.bind(this),
                    onFailure:function( response ){}.bind(this)
                }).request();
            }
        }
    },

    setupIcon:function(colorName){
        var icon = new GIcon();
            icon.image = "/images/maps/map-icon-event.png";
        icon.iconSize = new GSize(33, 33);
        icon.iconAnchor = new GPoint(12, 33);
        icon.infoWindowAnchor = new GPoint(12, 1);
        return icon;
    },

    initMap:function(){
        if (GBrowserIsCompatible()) {
            this.map = new GMap2($( 'localMap' ));
            this.map.setCenter(new GLatLng( this.latitude, this.longitude ), 10);
            this.map.addControl(new GSmallMapControl());
            this.map.addControl(new GMapTypeControl());

            if( streamLocations ){
                if( streamLocations.latitude && streamLocations.longitude ){
                    var point = new GLatLng( Number( streamLocations.latitude ), Number( streamLocations.longitude ) );
                    var marker = new GMarker(point, {icon:this.setupIcon('green'), draggable: false, title: streamLocations.title});
                    this.map.addOverlay( marker );
                    this.map.setZoom( 15 );
                    this.map.panTo( point );
                }
            }

        } else{
            alert('Your browser is not compatible with Google Maps.');
        } // end if
    }

});