//Devel: ABQIAAAAcDEUJmjiQB-sXzwwvbb0OxTzeKIs3FyoIHS8cXm2lvGc8D7zCRQpPk5y-fgSdXh0CrwIiT79h31xdw
//Munka: ABQIAAAAcDEUJmjiQB-sXzwwvbb0OxTjuelWmQ1d2GpCou8NIOCiPmlVpRQlKLnDw7lRhWPrMDFdECHSqwsrVQ
function googleMaps( container ) {
    this.map         = null;
    this.geoCache    = null;
    this.geocoder    = null;
    this.directions  = null;
    this.lastPoint   = null;

    this.controls   = new Array();


    if ( GBrowserIsCompatible() ) {
        this.geoCache    = new GGeocodeCache();
        this.geoCoder    = new GClientGeocoder( this.geoCache );

        this.map = new GMap2( container );

        this.map.enableDoubleClickZoom();
        this.map.enableContinuousZoom();
/*
        this.map.enableScrollWheelZoom();

        function wheelevent(e) {
            if (!e){
                e = window.event
            }

            if (e.preventDefault){
                e.preventDefault()
            }
        
            e.returnValue = false;
        }

        GEvent.addDomListener(this.map.getContainer(), "DOMMouseScroll", wheelevent);
        this.map.getContainer().onmousewheel = wheelevent; 
*/
        this.directions  = new GDirections(this.map);

    }
}

googleMaps.prototype = {
    
    addControl: function( type ) {
        this.controls.push( type );
    },


    createInfoWindow: function( point, text, opened ) {
        this.lastPoint = point;
//        console.log(point);
        this.map.clearOverlays();

        var marker = new GMarker( point );
        this.map.addOverlay( marker );

        if ( opened ) {
            marker.openInfoWindowHtml( text );
        } else {
            GEvent.addListener(marker, "mouseover", function() {
                marker.openInfoWindowHtml(text);
            });    
        }

    },

    LargeControl: function() {
        this.map.addControl(new GLargeMapControl());
    },

    SmallControl: function() {
        this.map.addControl(new GSmallMapControl());
    },

    SmallControl: function() {
        this.map.addControl(new GSmallZoomControl());
    },

    MapControl: function() {
        this.map.addControl(new GOverviewMapControl());
    },


    getAddressPoint: function( address, callback ) {
        var args = arguments;
        this.geoCoder.getLatLng( address, function(point) { if (!point) {alert(address + " not found");} else { callback( point, args );} } );
    },

    _addMarker: function( point, args ) {
        args[4].createInfoWindow( point, args[2], args[3] );
    },

    addAddressMarker: function( address, text, opened ) {
        this.getAddressPoint( address, this._addMarker, text, opened, this );
    },

    addPointMarker: function( point, text, opened ) {
        this.createInfoWindow( point, text, opened );
    },

    setCenter: function( point, zoom ) {
        this.map.setCenter(point, zoom);
    },

    setCenterAddress: function( address, zoom ) {
        this.getAddressPoint( address, function( point, args ) { args[3].setCenter(point, args[2]); }, zoom, this );
    },

    consolePoint: function( address ) {
        this.getAddressPoint( address, function( point ) { console.log(point.toString()); } );
    },

    getPoint: function( cX, cY ) {
        return new GLatLng( cX, cY );
    },

    getDirections: function() {
        var obj = this;
        GEvent.addListener(this.directions,"load", function() {
            
            for (i=0; i<obj.directions.getRoute(0).getNumSteps(); i++ )
            {
                document.getElementById( 'route2' ).innerHTML = document.getElementById( 'route2' ).innerHTML + obj.directions.getRoute(0).getStep(i).getDescriptionHtml()+ ' - ' + obj.directions.getRoute(0).getStep(i).getDistance().html +'<br>';
            }
        });

        this.directions.loadFromWaypoints(['vasut utca 17, 9653 Repcelak, Hungary','Semmelweis Ignac u. 2, 9700 Szombathely, Hungary'],{getPolyline:true,getSteps:true});
    }

}
