﻿function SapoMap()
{
    this._map = null;
    this._lat = null;
    this._lng = null;
    this._zoom = null;
    this._desc = null;
    this._link = null;

}

SapoMap.prototype = {

    createMap: function()
    {
        this._map = new SAPO.Maps.Map('sMap');
        //  this._map.addControl(new SAPO.Maps.Control.MapType());
        control2D = new SAPO.Maps.Control.Navigation();
        this._map.addControl(control2D);
        this._map.setBaseLayer(this._map.getBaseLayers().HYBRID_MAP);
        this._map.setMapCenter(new OpenLayers.LonLat(-9, 38), 15);
    },

    flyTo: function(lat, lng, zoom)
    {
        this._lat = lat;
        this._lng = lng;
        this._zoom = zoom;

        this._map.setMapCenter(new OpenLayers.LonLat(this._lng, this._lat), zoom);
    },

    addMarker: function(lat, lng, desc, link)
    {
        this._lat = lat;
        this._lng = lng;
        this._desc = desc;
        this._link = link;

        marker = new SAPO.Maps.Marker(new OpenLayers.LonLat(this._lng, this._lat));
        this._map.addOverlay(marker);
        marker.registerEvent('click', this, function()
        {
//            marker.openPopup('<a href="#" onclick="parent.location=' + this._link + '">Página no portal</a> <div style="width: 500px;padding-top: 10px; padding-right: 10px">' + this._desc + '</div>' +
//            '<input id="Button1" type="button" value="Birds Eye" name="getinfo" onclick="BirdEye()"/>' +
//            '<input id="Button2" type="button" value="Visita Virtual" name="getinfo" onclick="VirtualTour()"/>');

              marker.openPopup('<div style="width: 500px;padding-top: 10px; padding-right: 10px">' + this._desc + '</div>');

        });

    },

    removeMarker: function()
    {
        if (marker !== undefined)
        {
            this._map.removeOverlay(marker);
        }
    },

    getView: function()
    {
        var view = {};
        view.center = this._map.getMapCenter();
        view.zoom = this._map.getZoom();
        return (view);
    },

    setMapType: function(mapType)
    {
        if (mapType == 'Map')
        {
            this._map.setBaseLayer(this._map.getBaseLayers().NORMAL_MAP);
            document.getElementById("btn_Map").className = 'ui-state-hover ui-corner-all';
            document.getElementById("btn_Hyb").className = 'ui-state-default ui-corner-all';
            document.getElementById("btn_Sat").className = 'ui-state-default ui-corner-all';
            document.getElementById("btn_map3D").className = 'ui-state-default ui-corner-all';

        }

        if (mapType == 'Hyb')
        {
            this._map.setBaseLayer(this._map.getBaseLayers().HYBRID_MAP);
            document.getElementById("btn_Hyb").className = 'ui-state-hover ui-corner-all';
            document.getElementById("btn_Map").className = 'ui-state-default ui-corner-all';
            document.getElementById("btn_Sat").className = 'ui-state-default ui-corner-all';
            document.getElementById("btn_map3D").className = 'ui-state-default ui-corner-all';

        }

        if (mapType == 'Sat')
        {
            this._map.setBaseLayer(this._map.getBaseLayers().SATELLITE_MAP);
            document.getElementById("btn_Sat").className = 'ui-state-hover ui-corner-all';
            document.getElementById("btn_Map").className = 'ui-state-default ui-corner-all';
            document.getElementById("btn_Hyb").className = 'ui-state-default ui-corner-all';
            document.getElementById("btn_map3D").className = 'ui-state-default ui-corner-all';

        }
    }


};

