﻿var currentMarker = '';

var MyOverlay = function(marker, html, width) {
    this.marker = marker;
    this.html = html;
    this.width = width;
    this.offsetX = 175;
    this.offsetY = 170;
}

MyOverlay.prototype = new GOverlay();

MyOverlay.prototype.initialize = function(map) {
    var div = document.createElement("div");
    $(div).attr("class", "contentWindow");
    $(div).html(this.html);

    $(div).find(".lightbox").css({ "right": "0px",
                           "left": map.fromLatLngToDivPixel(this.marker.getPoint()).x - this.offsetX + "px",
                           "top": map.fromLatLngToDivPixel(this.marker.getPoint()).y - this.offsetY + "px"
                       });

    $(div).css({ "left": map.fromLatLngToDivPixel(this.marker.getPoint()).x - this.offsetX + "px",
         "height": "160px",
         "width": "216px",
         "top": map.fromLatLngToDivPixel(this.marker.getPoint()).y - this.offsetY + "px"
     });

    $(div).find(".lightbox").bind("click", function() {
        closeOverlay(map);
    });

    this._map = map;
    this._div = div;

    this._map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
}

MyOverlay.prototype.remove = function() {
    this._div.parentNode.removeChild(this._div);
}

MyOverlay.prototype.redraw = function() {
    this._div.style.left = (this._map.fromLatLngToDivPixel(this.marker.getPoint()).x - this.offsetX) + 'px';
    this._div.style.top = (this._map.fromLatLngToDivPixel(this.marker.getPoint()).y - this.offsetY) + 'px';
}

function closeOverlay(map) {
    if (currentMarker) {
        map.removeOverlay(currentMarker.overlay);
        //currentMarker.show();
    }
}                
                