function BreakInfo(parent, lat, lng, ts_start, ts_stop){
    this.parent_ = parent;
	this.lat = lat;
	this.lng = lng;
	this.ts_start = ts_start;
	this.ts_stop = ts_stop;
    Wiking.getMap().addOverlay(this);
    OverlayRegistry.clear('BreakInfo');
    OverlayRegistry.register('BreakInfo',this);
}
BreakInfo.prototype = new GOverlay();
BreakInfo.prototype.initialize = function(map){
    var
      width = 210,
      height = 190;
    var div = document.createElement('div');
    div.style.position="absolute";
    var x = document.createElement("div");
    x.style.cssText='cursor:pointer;position:absolute;left:'+(width-17)+'px;top:-9px;width:27px;height:27px;background: url(\'wimg/x.png\')'

    this.visible_ = true;

    var self = this; //clousure
    GEvent.addDomListener(x,'click',function(){
        Wiking.getMap().removeOverlay(self);
    });
    div.appendChild(x);
    var innerdiv = document.createElement('div');
    div.appendChild(innerdiv);

    innerdiv.innerHTML =
                 '<div style="float:left;width:8px;height:39px;background:url(\'wimg/eclefttop.png\')"></div>'+
                 '<div style="float:left;background:url(\'wimg/ectop.png\');height:39px;width:'+(width-16)+'px">'+
                    '<p style="font-size:14px;font-weight:bold;margin-top:12px;margin-left:5px;">Postój</p>'+
                 '</div>'+
                 '<div style="float:left;width:8px;height:39px;background:url(\'wimg/ecrighttop.png\')"></div>'+

                 '<div style="clear:left;float:left;width:8px;background:url(\'wimg/cleft.png\');height:'+(height-47)+'px"></div>'+
                 '<div style="float:left;background:#fff;height:'+(height-47)+'px;width:'+(width-16)+'px">'+
                    //TREŚĆ
                   '<div style="padding:10px;">'+
				     this.generateContent()+
                   '</div>'+
                 '</div>'+
                 '<div style="float:left;width:8px;background:url(\'wimg/cright.png\');height:'+(height-47)+'px"></div>'+

                 '<div style="float:left;width:8px;height:8px;background:url(\'wimg/cleftbottom.png\')"></div>'+
                 '<div style="float:left;background:url(\'wimg/cbottom.png\');height:8px;width:'+(width-16)+'px"></div>'+
                 '<div style="float:left;width:8px;height:8px;background:url(\'wimg/crightbottom.png\')"></div>';

    map.getPane(G_MAP_FLOAT_PANE).appendChild(div);

	var address = document.getElementById('breakinfo_address');
    address.id='';
    Geocoder.getLocations(new GLatLng(this.lat,this.lng) , function(response){
        if (!response || response.Status.code != 200){
            address.innerHTML = 'Nieznany adres';
        } else {
            address.innerHTML = response.Placemark[0].address;
        }
    });

    this.div_ = div;
    return div;
}
BreakInfo.prototype.redraw = function(force) {
    if (!force) return;

    //var pos = this.parent_.parent.getPosition();
	var pos = new GLatLng(this.lat,this.lng);
    var point = Wiking.getMap().fromLatLngToDivPixel(pos);
    var viewpoint = Wiking.getMap().fromLatLngToContainerPixel(pos);
    var size = Wiking.getMap().getSize();

    var x = point.x+30;
    var y = point.y-50;

    //TODO przeliczenia by sie przesuwało ładnie

    // Now position our DIV based on the DIV coordinates of our bounds
    this.div_.style.width = 210 + "px";
    this.div_.style.height = 200 + "px";
    this.div_.style.left = x + "px";
    this.div_.style.top = y + "px";

    if (size.height < viewpoint.y + 200){
        Wiking.getMap().panBy(new GSize(0,-(viewpoint.y+200-size.height)));
    }else if(viewpoint.y < 70){
        Wiking.getMap().panBy(new GSize(0,50));
    }

}
BreakInfo.prototype.remove = function(){
    this.visible_ = false;
    this.div_.parentNode.removeChild(this.div_);
}
BreakInfo.prototype.generateContent = function(){
	var s = this.ts_stop - this.ts_start;
    var content = '<b>'+this.parent_.getName()+'</b>'+
				  "<br><b>Imei:</b> "+this.parent_.getImei()+
				  '<div style="margin:5px 0;height:1px; background:#eee"></div>'+
				  '<b>Data:</b> '+new Date(this.ts_start*1000).toLocaleFormat('%d-%m-%Y %H:%M')+
                  "<br><b>Czas:</b> ~"+(s/60 < 60 ? Math.round(s/60)+" minut" : Math.floor(s/60/60)+" godzin "+ Math.round((s-(Math.floor(s/60/60)*60*60))/60)+" minut")+
                  '<div style="margin:5px 0;height:1px; background:#eee"></div>'+
				  '<span style="font-style:italic;" id="breakinfo_address"></span>';
    return content;
}
BreakInfo.prototype.isVisible = function(){
    return this.visible_;
}
