//ALMAFA
var MapItem= Class.extend({
	
    init: function(options) {
        this.remoteMapRoute=new cItem({
            OnReady:jQuery.proxy(this.onReadyMapRoute,this)
        });



    },

    OpenWindowMapRoute: function (i,e,c) {
        showLoader();
        Parameter = new Object;
        Parameter.mode = 1;
        Parameter.honnan = i;
        Parameter.hova = e;
        Parameter.centered = c;
        this.centered = c;
        this.remoteMapRoute.callMethod('se','MapWin',Parameter);

    },
    onReadyMapRoute: function(sender,item) {
        window.Loader.hide();
        /*Modalbox.show(item,{title: 'Térkép', width: 900});*/
        this.newDialog=showDialog('Térkép',item,{
            modal:true,
            center:true,
            width: 900/*,
            height: 600*/
        });
        MapData.showMap('map_1',15);
        MapData.codeAddress(MapData.centered,MapData);

    },
    showMap: function (d,z) {

        this.geocoder = new google.maps.Geocoder();
        this.directionsDisplay = new google.maps.DirectionsRenderer();
        this.directionsService = new google.maps.DirectionsService();
        var latlng = new google.maps.LatLng(-34.397, 150.644);

        var myOptions = {
            zoom: z,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP


        };
        
        this.map = new google.maps.Map(document.getElementById(d),myOptions);

        this.directionsDisplay.setMap(this.map);

    },
    codeAddress: function (address,m) {
        this.geocoder.geocode( {
            'address': address
        }, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                m.map.setCenter(results[0].geometry.location);
                var marker = new google.maps.Marker({
                    map: m.map,
                    position: results[0].geometry.location
                });
                var infowindow = new google.maps.InfoWindow({
                    content: address
                });
                google.maps.event.addListener(marker, 'click', function() {
                    infowindow.open(m.map,marker);
                });
            } else {
                alert("Geocode was not successful for the following reason: " + status);
            }
        });
    },
    calcRoute: function (o,d,m) {
        o=$('#'+o).val();
        d=$('#'+d).val();
        var selectedMode = "DRIVING";
        var request = {
            origin: o,
            destination: d,

            travelMode: google.maps.DirectionsTravelMode[selectedMode]
        };
        m.directionsService.route(request, function(response, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                m.directionsDisplay.setDirections(response);
            }
        });
    }



});
var MapData = new MapItem();
