/* ======================================================================
 * HistoryObject abstract
 * ====================================================================== */
function HistoryObject(json){
    WikingObject.prototype.constructor.apply(this, arguments);
    this.Path = new GHistoryPath(json.color,this); // ślad pojazdu
    
    this.flags = {follow:0,visible:1,data:0};
}
HistoryObject.prototype = Wiking.inherit(WikingObject);
HistoryObject.prototype.constructor = HistoryObject; // gdbyśmy potem Chcieli z tego dziedziczyć

/* ----------------------------------------------------------------------
 * input: [lngarray,latarray,speedarray,timearray] 
 * ---------------------------------------------------------------------- */
HistoryObject.prototype.setData = function(json){
    this.arr = json;
    
    var i = json[0].length - 1;
    
    if (i==-1){
        this.flags.data = false;
    }else{
        this.flags.data = true;
        this.Path.draw(json); 
        this.Pojazd.move_(new GLatLng(json[1][i],json[0][i]));
		this.Label.move_(new GLatLng(json[1][i],json[0][i]));
    }
}

HistoryObject.prototype.hide = function(){
    this.Path.hide();
    this.Pojazd.hide();
	this.Label.hide();
    this.flags.visible=0;
    this.flags.follow=0;
    Wiking.Event.trigger({'e':'hideobject','imei':this.imei});
};

/*
 * return true -ok, false - not ok
 */
HistoryObject.prototype.show = function(){
    if (this.flags.data){
		this.Label.show();
        this.Pojazd.show();
        this.Path.show();
        this.flags.visible=1;
        Wiking.Event.trigger({'e':'showobject','imei':this.imei});
        return true;
    }else{
        return false;
    }
}

HistoryObject.prototype.getPathBoundingBox = function(){
    return (this.flags.data ? this.Path.getBoundingBox() : false);
}

HistoryObject.prototype.setStep = function(j){
    if (this.flags.data && this.arr[0].length > j){
        this.Pojazd.move_(new GLatLng(this.arr[1][j],this.arr[0][j]));
		this.Label.move_(new GLatLng(this.arr[1][j],this.arr[0][j]));
        this.step = j;
    }
}

HistoryObject.prototype.applyFlags = function(json){
    if (this.flags.visible==0 || this.flags.data==0){
        this.hide();
    }else{
        this.show();
    }
}

HistoryObject.prototype.nextStep = function(){
       this.setStep(this.step+1);
}

HistoryObject.prototype.pathClick = function(i){
    var data = [this.arr[0][i],this.arr[1][i],this.arr[2][i],this.arr[3][i]];
    new MarkerInfo(data,this);
} 

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

/* ----------------------------------------------------------------------
 * @spec toString() -> String()
 * ---------------------------------------------------------------------- */
HistoryObject.prototype.toString = function(){
    return "HistoryObject";
};

/* ----------------------------------------------------------------------
 * @doc Creator
 * ---------------------------------------------------------------------- */
HistoryObject.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 == '') json.name = json.imei;
      
    return new HistoriaObiekt(json);
}


// żeby działało prototype dziedziczenie
HistoryObject.subclasses = [];
// end TODO: wyjebać

