/////////////////////////////////////////////////////////////////////
// CONSTRUCTOR
/////////////////////////////////////////////////////////////////////
function UserObject(id, size){
    if(size == 0 || size == null){
        size = 100;
    }

    /* Data members */
    this.id = id;
    this.pointCollection = new Vector(size);
    this.timestampCollection = new Vector(size);
    this.markerCollection = new Vector(size);
    this.polylineCollection = new Vector(size);
    this.animatedMarker = null;
    
    this.idleMarkerCollection = new Vector(size);
    this.speedMarkerCollection = new Vector(size);
    this.ignitionMarkerCollection = new Vector(size);
    
    /* Methods */
    this.getNumPoints = getNumPoints;
    this.getPointAt = getPointAt;
    this.getTimestampAt = getTimestampAt;
    this.getMarkerAt = getMarkerAt;
    this.insertPoint = insertPoint;
    this.getId = getId;
    this.removePointAt = removePointAt;
    this.getPointCollection = getPointCollection;
    this.getTimestampCollection = getTimestampCollection;
    this.getLastPoint = getLastPoint;    
    this.getPointByTime = getPointByTime;
    this.getPolylineCollection = getPolylineCollection;
    this.setPolylineCollection = setPolylineCollection;
    this.removeAllPoints = removeAllPoints;
}

/////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
/////////////////////////////////////////////////////////////////////

function getPointByTime(timestamp){
    var returnVal = null;
    idx = this.timestampCollection.indexOf(timestamp)
    returnVal = this.pointCollection.getElementAt(idx);    
    return returnVal;
}

function getPolylineCollection(){
    return this.polylineCollection;
}

function setPolylineCollection(polylineCollection){
    this.polylineCollection = polylineCollection;
}

function getId(){
    return this.id;
}

function getNumPoints(){
    return this.pointCollection.getSize();
}

function getPointAt(i){
    return this.pointCollection.getElementAt(i);
}

function getTimestampAt(i){
    return this.timestampCollection.getElementAt(i);
}

function getMarkerAt(i){
    return this.markerCollection.getElementAt(i);
}

function insertPoint(point, timestamp, marker){
    this.pointCollection.addElement(point);
    this.timestampCollection.addElement(timestamp);
    this.markerCollection.addElement(marker);
}

function removePointAt(i){
    this.pointCollection.removeElementAt(i);
    this.timestampCollection.removeElementAt(i);
    this.markerCollection.removeElementAt(i);
}

function getPointCollection(){
    return this.pointCollection;
}

function getTimestampCollection(){
    return this.timestampCollection;
}


function getLastPoint(){
    return this.pointCollection.getLastElement();
}

function removeAllPoints(mapObj){
    if(mapObj){
        for(markerCounter = 0; markerCounter < this.markerCollection.getSize(); markerCounter++){
            mapObj.removeOverlay(this.markerCollection.getElementAt(markerCounter));
        }
        
        if(this.animatedMarker){
            mapObj.removeOverlay(this.animatedMarker);
        }
        
        if(this.polylineCollection){
            for(polylineCounter = 0; polylineCounter < this.polylineCollection.getSize(); polylineCounter++){
                mapObj.removeOverlay(this.polylineCollection.getElementAt(polylineCounter));
            }
        }
    }
    this.polylineCollection.removeAllElements();
    this.pointCollection.removeAllElements();
    this.timestampCollection.removeAllElements();
    this.markerCollection.removeAllElements();
}
