function MarkerInfo(data,parent){
    this.parent_ = parent;
    this.data_ = data;
    Wiking.getMap().addOverlay(this);
    OverlayRegistry.clear('MarkerInfo');
    OverlayRegistry.register('MarkerInfo',this);
}
MarkerInfo.prototype = new GOverlay();
MarkerInfo.prototype.initialize = function(map){
    var 
      width=220,
      height=88;
    var html='<div id="markerinfox" style="cursor:pointer;position:absolute;left:'+(width-17)+'px;top:-9px;width:27px;height:27px;background: url(\'wimg/x.png\')"></div>'+
                '<div>'+
                  '<div style="font-size:1px;float:left;width:8px;height:8px;background:url(\'wimg/clefttop.png\')"></div>'+
                  '<div style="font-size:1px;float:left;background:url(\'wimg/ctop.png\');height:8px;width:'+(width-16)+'px">'+

                  '</div>'+
                  '<div style="font-size:1px;float:left;width:8px;height:8px;background:url(\'wimg/crighttop.png\')"></div>'+
                 
                  '<div style="clear:left;float:left;width:8px;background:url(\'wimg/cleft.png\');height:'+(height-16)+'px"></div>'+
                  '<div style="float:left;background:#fff;height:'+(height-16)+'px;width:'+(width-16)+'px">'+
                    //TREŚĆ
                     '<div style="padding:0px 4px">'+
                        "<strong>" + this.parent_.getName() + '</strong><div style="font-size:12px;">'+ 
                        "Data: "+ new Date(this.data_[3]*1000).toLocaleFormat('%d-%m-%Y %H:%M:%S') +
                        '<br /> Prędkość: '+ Math.round(this.data_[2]*100)/100 + ' km/h'+
                        '<br /><span style="font-style:italic;" id="objmarker_address"></span></div>' +
                     '</div>'+
                  '</div>'+
                  '<div style="float:left;width:8px;background:url(\'wimg/cright.png\');height:'+(height-16)+'px"></div>'+
               
                  '<div style="font-size:1px;float:left;clear:left;width:8px;height:8px;background:url(\'wimg/cleftbottom.png\')"></div>'+
                  '<div style="font-size:1px;float:left;background:url(\'wimg/cbottom.png\');height:8px;width:'+(width-16)+'px"></div>'+
                  '<div style="font-size:1px;float:left;width:8px;height:8px;background:url(\'wimg/crightbottom.png\')"></div>'+
                '</div>';
    var div = document.createElement('div');
    div.style.position="absolute";
    div.innerHTML=html;
    
    /*var parent = this.parent_;
    GEvent.addDomListener(div,'mouseover',function(){
        document.getElementById('obj'+parent.getImei()).style.background="#FFE4B5";
    });
    GEvent.addDomListener(div,'mouseout',function(){
        document.getElementById('obj'+parent.getImei()).style.background="#FFF";
    });*/
        
    map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
    this.div_ = div;
    
    var address = document.getElementById('objmarker_address');
    address.id='';
    var xsign = document.getElementById('markerinfox');
    var self = this; // clousure
    GEvent.addDomListener(xsign,'click',function(){
       OverlayRegistry.unregister('MarkerInfo',self);
       Wiking.getMap().removeOverlay(self);
    });
    xsign.id='';
    
    Geocoder.getLocations(new GLatLng(this.data_[1],this.data_[0]) , function(response){
        if (!response || response.Status.code != 200){
            address.innerHTML = 'Nieznany adres';
        } else {
            var place = response.Placemark[0];
            //new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
            address.innerHTML = place.address;
        }
    });
}
/*
function showAddress(response) {
  map.clearOverlays();
  if (!response || response.Status.code != 200) {
    alert("Status Code:" + response.Status.code);
  } else {
    place = response.Placemark[0];
    point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
    marker = new GMarker(point);
    map.addOverlay(marker);
    marker.openInfoWindowHtml(
        '<b>orig latlng:</b>' + response.name + '<br/>' + 
        '<b>latlng:</b>' + place.Point.coordinates[1] + "," + place.Point.coordinates[0] + '<br>' +
        '<b>Status Code:</b>' + response.Status.code + '<br>' +
        '<b>Status Request:</b>' + response.Status.request + '<br>' +
        '<b>Address:</b>' + place.address + '<br>' +
        '<b>Accuracy:</b>' + place.AddressDetails.Accuracy + '<br>' +
        '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
  }
}
}*/
MarkerInfo.prototype.redraw = function(force) {
    if (!force) return;

    var point = Wiking.getMap().fromLatLngToDivPixel(new GLatLng(this.data_[1],this.data_[0]));

      // Now position our DIV based on the DIV coordinates of our bounds
      this.div_.style.width = 250 + "px";
      this.div_.style.height = 83 + "px";
      this.div_.style.left = point.x + "px";
      this.div_.style.top = point.y + "px";
}
MarkerInfo.prototype.remove = function() {
    this.div_.parentNode.removeChild(this.div_);
}

