﻿function Dialogs(id, title, src)
{
    this._id = id;
    this._title = title;
    this._src = src;
}

Dialogs.prototype = {

    setDialog: function()
    {
        var windowResize = new WindowResizer();

        SMap._map.removeControl(control2D);

        var dialogframe = windowResize.dialogFrame();
        var myString = dialogframe.split(",");
        var dwidth = parseFloat(myString[0]);
        var dheight = parseFloat(myString[1]);

        if (currentMap == 'Google')
        {
            windowResize.hide3D_Map();
        }

        if (this._id == "#birdseye")
        {

            windowResize.hide2DMap();
            $(this._id).dialog({
                title: this._title,
                draggable: false,
                resizable: false,
                buttons: { Oeste: function() { bmap.SetBirdseyeOrientation(VEOrientation.West); },
                    Este: function() { bmap.SetBirdseyeOrientation(VEOrientation.East); },
                    Sul: function() { bmap.SetBirdseyeOrientation(VEOrientation.South); },
                    Norte: function() { bmap.SetBirdseyeOrientation(VEOrientation.North); }
                },
                modal: true,
                width: dwidth,
                height: dheight,
                bgiframe: true,
                autoOpen: true,
                close: function(ev, ui)
                {
                    $("#birdseye").dialog("destroy");
                    if (currentMap == 'Google')
                    {
                        windowResize.show3D_Map();
                    }
                    control2D = new SAPO.Maps.Control.Navigation();
                    SMap._map.addControl(control2D);
                    windowResize.show2DMap();
                    dialog = false;

                }
            });
        }

        if (this._id == "#virtualTour")
        {
            var shimmer = document.createElement('iframe');
            shimmer.style.width = "99%";
            shimmer.style.height = "99%";
            shimmer.style.borderStyle = "none";
            shimmer.setAttribute('frameborder', '0');
            shimmer.setAttribute('scrolling', 'no');
            shimmer.setAttribute('src', this._src);
            document.getElementById("virtualTour").appendChild(shimmer);

            if (currentMap == 'Google')
            {
                windowResize.hide3D_Map();
            }

            windowResize.hide2DMap();
     
            $("#virtualTour").dialog({
                title: "Visita Virtual",
                draggable: false,
                resizable: false,
                modal: true,
                width: dwidth,
                height: dheight,
                bgiframe: true,
                autoOpen: true,
                close: function(ev, ui)
                {
                    $("#virtualTour").dialog("destroy");
                    if (currentMap == 'Google')
                    {
                        windowResize.show3D_Map();
                    }
                    control2D = new SAPO.Maps.Control.Navigation();
                    SMap._map.addControl(control2D);
                    document.getElementById("virtualTour").removeChild(shimmer);
                    windowResize.show2DMap();
                    dialog = false;
                }
            });
        }

        if (this._id == "#description")
        {
            windowResize.hide2DMap();
            var shimmer = document.createElement('iframe');
            shimmer.style.width = "95%";
            shimmer.style.height = "95%";
            shimmer.setAttribute('src', this._src);
            document.getElementById("piecies").appendChild(shimmer);

            $(this._id).dialog({
                title: "Galeria",
                draggable: false,
                resizable: false,
                modal: true,
                width: dwidth,
                height: dheight,
                autoOpen: true,
                bgiframe: true,
                close: function(ev, ui)
                {
                    $("#description").dialog("destroy");
                    if (currentMap == 'Google')
                    {
                        windowResize.show3D_Map();
                    }
                    control2D = new SAPO.Maps.Control.Navigation();
                    SMap._map.addControl(control2D);
                    document.getElementById("piecies").removeChild(shimmer);
                    windowResize.show2DMap();
                    dialog = false;

                }
            });
        }
    }
};
