function LiveObject(json){
    WikingObject.prototype.constructor.apply(this, arguments);
    
    this.arr = [[],[],[],[]]; // lng,lat,array
    this.flags = {follow:0,visible:1,data:1};
}
LiveObject.prototype = Wiking.inherit(WikingObject);
LiveObject.prototype.constructor = LiveObject; // gdbyśmy potem Chcieli z tego dziedziczyć

LiveObject.prototype.getPosition = function(){
    var len = this.arr[0].length;
    return len>0 ? new GLatLng(this.arr[1][len-1],this.arr[0][len-1]) : false;
}

LiveObject.prototype.update = function(x,y,spd,time){// poruszmy obiekt, x,y = arrays x=lng , y=lat
	var i,j,l;
    if (x.length == 0) return;//TODO
    var lasttime = this.arr[3][this.arr[3].length-1];
    if (typeof(x) == "number"){
        if (lasttime>time) return;
        this.Pojazd.move_(new GLatLng(y,x));
		this.Label.move_(new GLatLng(y,x));
        x = [x];
        y = [y];
    }else{
        var len = x.length; // x,y length musi być równe ! (to chyba logiczne? ;-) )
        while(len--){//TODO
            if (lasttime>time[len]){
                time.pop();
                spd.pop();
                x.pop();
                y.pop();
            }
        }
        j = (x.length-1)
        this.Pojazd.move_(new GLatLng(y[j],x[j]));
		this.Label.move_(new GLatLng(y[j],x[j]));
    }
        // extendujemy tablice
    this.arr[0] = this.arr[0].concat(x)
    this.arr[1] = this.arr[1].concat(y)
    this.arr[2] = this.arr[2].concat(spd);
    this.arr[3] = this.arr[3].concat(time);
        
        /*while(this.arr[0].length > 10) // regulujemy długość arraya
        {
            this.arr[0].shift();
            this.arr[1].shift();
        }*/


    if (this.arr[0].length < 2) return;

    if (!this.Path){
        var ar = [];
        for (i=0, l = this.arr[0].length; i<l; i++){
            ar.push(new GLatLng(this.arr[1][i],this.arr[0][i]));
        }
        this.Path = new GPolyline(ar,this.color);
        Wiking.getMap().addOverlay(this.Path);
    }else{
        j = this.Path.getVertexCount();
        for (i=0, l = x.length; i<l; i++){
            this.Path.insertVertex(j,new GLatLng(y[i],x[i]));
            j+=1;
        }
    }
}

LiveObject.prototype.show = function(){
    if (this.Path){
        this.Path.show();
    }
    this.Pojazd.show();
	this.Label.show();
    return true;
}
LiveObject.prototype.hide = function(){
    if (this.Path){
        this.Path.hide();
    }
    this.Pojazd.hide();
	this.Label.hide();
}

LiveObject.prototype.applyFlags = function(){
    //TODO!!!
}

LiveObject.prototype.clear = function(){
    if (this.Path){
        Wiking.getMap().removeOverlay(this.Path);
    }
    Wiking.getMap().removeOverlay(this.Pojazd);
	Wiking.getMap().removeOverlay(this.Label);
}

LiveObject.creator = function(json)
{ 
    if (json.marker == undefined)
    {
        json.marker=0;
    }
    if (json.paymentcode == undefined) json.paymentcode = false;
    if (json.color == undefined)
    {
        json.color="rgb(255,0,0)";
    }
    if (json.name == "" || json.name == undefined)
    {
        json.name = json.imei;
    }
    return new LiveObject(json);
}
