﻿
//PB - PBMarker: marker testuale con link

    function PBMarker(point, html) {
        
        this.point = point;
        this.html = html;
        this.classname = '';
        this.pixelOffset = new GSize(0, 0);
        this.percentOpacity = 100;
        this.overlap = false;
        this.hidden = false;
    }

    PBMarker.prototype = new GOverlay();

    PBMarker.prototype.initialize = function(map) {

        var div = document.createElement("div");
        
        div.style.position = "absolute";
        div.style.overflow = "auto";

        var divI1 = document.createElement("div");
        var divI2 = document.createElement("div");
        var divI3 = document.createElement("div");

        divI1.innerHTML = '<div style="float:left; background:transparent url(/markers/left.png) no-repeat; height:27px; width:7px;"></div>';
        divI2.innerHTML = '<div style="width: auto; white-space:nowrap; clear:right; float:left; background:transparent url(/markers/mid.png) no-repeat; background-position: center top; height:27px; font-family:Arial; font-weight: bold; font-size:10px; padding-top:6px;">' + this.html + '</div>';
        divI3.innerHTML = '<div style="clear:right; float:left; background:transparent url(/markers/right.png) no-repeat; height:27px; width:7px;"></div>';

        map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div);

        div.appendChild(divI1);
        div.appendChild(divI2);
        div.appendChild(divI3);

        //PB - Impostazione dimensione div contenitore - Verificare per differenti browser

        //if (navigator.userAgent.indexOf("MSIE") == -1) {
            var totalwidth = div.clientWidth + 14;
            div.style.width = totalwidth + "px";
        //}

        this.map_ = map;
        this.div_ = div;
        
        if (this.hidden) {
            this.hide();
        }
    }

    PBMarker.prototype.remove = function() {
        this.div_.parentNode.removeChild(this.div_);
    }

    PBMarker.prototype.copy = function() {
        return new PBMarker(this.point, this.html, this.classname, this.pixelOffset, this.percentOpacity, this.overlap);
    }

    PBMarker.prototype.redraw = function(force) {
        
        var p = this.map_.fromLatLngToDivPixel(this.point);
        var h = parseInt(this.div_.clientHeight);
        
        //PB - Allineamento div al centro
        
        this.div_.style.left = (p.x - (this.div_.clientWidth / 2)) + "px";
        this.div_.style.top = (p.y - 25) + "px";
    }

    PBMarker.prototype.show = function() {
        if (this.div_) {
            this.div_.style.display = "";
            this.redraw();
        }
        this.hidden = false;
    }

    PBMarker.prototype.hide = function() {
        if (this.div_) {
            this.div_.style.display = "none";
        }
        this.hidden = true;
    }

    PBMarker.prototype.isHidden = function() {
        return this.hidden;
    }

    PBMarker.prototype.supportsHide = function() {
        return true;
    }

    PBMarker.prototype.setContents = function(html) {
        this.html = html;
        this.div_.innerHTML = '<div class="' + this.classname + '">' + this.html + '</div>';
        this.redraw(true);
    }

    PBMarker.prototype.setPoint = function(point) {
        alert(this.width);
        this.point = point;
        if (this.overlap) {
            var z = GOverlay.getZIndex(this.point.lat());
            this.div_.style.zIndex = z;
        }
        this.redraw(true);
    }

    PBMarker.prototype.setOpacity = function(percentOpacity) {
        if (percentOpacity) {
            if (percentOpacity < 0) { percentOpacity = 0; }
            if (percentOpacity > 100) { percentOpacity = 100; }
        }
        this.percentOpacity = percentOpacity;
        if (this.percentOpacity) {
            if (typeof (this.div_.style.filter) == 'string') { this.div_.style.filter = 'alpha(opacity:' + this.percentOpacity + ')'; }
            if (typeof (this.div_.style.KHTMLOpacity) == 'string') { this.div_.style.KHTMLOpacity = this.percentOpacity / 100; }
            if (typeof (this.div_.style.MozOpacity) == 'string') { this.div_.style.MozOpacity = this.percentOpacity / 100; }
            if (typeof (this.div_.style.opacity) == 'string') { this.div_.style.opacity = this.percentOpacity / 100; }
        }
    }

    PBMarker.prototype.getPoint = function() {
        return this.point;
    }
