﻿Type.registerNamespace("Feratel.Website.Tosc");

// constructor
Feratel.Website.Tosc.GMapPosition = function() {
    Feratel.Website.Tosc.GMapPosition.initializeBase(this);
    this.mapContainerId;
    this.lat;
    this.lng;
    this.selectedMapType;
    this.mapTypes;

    this.mapContainer;
    this._mapObject;
}
//class definition
Feratel.Website.Tosc.GMapPosition.prototype = {
    get_lat: function() {
        return this.lat;
    },
    set_lat: function(value) {
        this.lat = value;
        this.raisePropertyChanged('lat');
    },
    get_lng: function() {
        return this.lng;
    },
    set_lng: function(value) {
        this.lng = value;
        this.raisePropertyChanged('lng');
    },

    get_selectedMapType: function() {
        return this.selectedMapType;
    },
    set_selectedMapType: function(value) {
        this.selectedMapType = value;
        this.raisePropertyChanged('selectedMapType');
    },

    get_mapTypes: function() {
        return this.mapTypes;
    },
    set_mapTypes: function(value) {
        this.mapTypes = value;
        this.raisePropertyChanged('mapTypes');
    },
    get_autoInit: function() {
        return this.autoInit;
    },
    set_autoInit: function(value) {
        this.autoInit = value;
        this.raisePropertyChanged('autoInit');
    },

    get_mapContainerId: function() {
        return this.mapContainerId;
    },
    set_mapContainerId: function(value) {
        this.mapContainerId = value;
        this.raisePropertyChanged('mapContainerId');
    },


    initialize: function() {
        Feratel.Website.Tosc.GMapPosition.callBaseMethod(this, 'initialize');
        if (this.autoInit) {
            this.initMap();
        }
    },

    initMap: function() {

        if (this._mapObject == null) {
            this.mapContainer = $get(this.mapContainerId);
            var latlng = new google.maps.LatLng(this.lat, this.lng);
            var mapTypeIds = new Array();
            var selectedMapTypeId = 1;
            if ((this.mapTypes & 1) == 1) mapTypeIds[mapTypeIds.length] = google.maps.MapTypeId.ROADMAP;
            if ((this.mapTypes & 2) == 2) mapTypeIds[mapTypeIds.length] = google.maps.MapTypeId.SATELLITE;
            if ((this.mapTypes & 4) == 4) mapTypeIds[mapTypeIds.length] = google.maps.MapTypeId.HYBRID;
            if ((this.mapTypes & 8) == 8) mapTypeIds[mapTypeIds.length] = google.maps.MapTypeId.TERRAIN;
            if (this.selectedMapType == 1) selectedMapTypeId = google.maps.MapTypeId.ROADMAP;
            if (this.selectedMapType == 2) selectedMapTypeId = google.maps.MapTypeId.SATELLITE;
            if (this.selectedMapType == 4) selectedMapTypeId = google.maps.MapTypeId.HYBRID;
            if (this.selectedMapType == 8) selectedMapTypeId = google.maps.MapTypeId.TERRAIN;
            var myOptions = {
                zoom: 15,
                center: latlng,
                mapTypeId: selectedMapTypeId,
                mapTypeControlOptions: { mapTypeIds: mapTypeIds }
            };
            this._mapObject = new google.maps.Map(this.mapContainer, myOptions);

            var marker = new google.maps.Marker({
                position: latlng,
                map: this._mapObject,
                title: ""
            });
        }

    },
    dispose: function() {
    }
}

// Optional descriptor for JSON serialization.
Feratel.Website.Tosc.GMapPosition.descriptor = {
    properties: [{ name: 'mapContainerId', type: String },
                    { name: 'mapTypes', type: Number },
                    { name: 'selectedMapType', type: Number },
                    { name: 'autoInit', type: Boolean },
                    { name: 'lat', type: Number },
                    { name: 'lng', type: Number}]
}
Feratel.Website.Tosc.GMapPosition.registerClass('Feratel.Website.Tosc.GMapPosition', Sys.Component, Sys.IDisposable);

// Notify ScriptManager that this is the end of the script.
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

