function GHistoryPath(color,parent){
    this.path = [];
    this.pathPoints = [];
    this.color=color;
    this.parent = parent;
    this.handlers = [];
	this.breakPoints = [];
    this.polylineEncoder = new PolylineEncoder();
} 
GHistoryPath.prototype.draw = function(array){ // create
    var i,j=0,tmpPathPoints=[[]],pointsOfTheLackOfCoverage=[],point,prevPoint;
    if (array[0].length==0) return;
	
    this.pathPoints = [];
    for(i=0; i<array[0].length; i++){
		if(i>0) prevPoint = point;
		point = new GLatLng(array[1][i],array[0][i]);
		if(i>0) {
			if(array[3][i]-array[3][i-1]>60*60) {
				pointsOfTheLackOfCoverage.push([prevPoint, point]);
				if(tmpPathPoints[j].length==1) tmpPathPoints[j] = [];
				if(tmpPathPoints[j].length>0) tmpPathPoints[++j] = [];
			}
			tmpPathPoints[j].push(point);
		}
        this.pathPoints.push(point);
    }
	if(tmpPathPoints[j].length<=1) tmpPathPoints.pop();

	this.clearPath();
    j = this.handlers.length;
    if (j!=0){
        while(j--){
            GEvent.removeListener(this.handlers[j]);
        }
        this.handlers = [];
    }

	var hexColor = Wiking.tools.colorToHex(this.color);

    for(j=0; j<tmpPathPoints.length; j++){
		var x = this.polylineEncoder.dpEncodeToGPolyline(tmpPathPoints[j], hexColor, 5, 0.6);
		this.path.push(x);
		Wiking.getMap().addOverlay(x);
		this.handlers.push(GEvent.bind(x,'click',this,function(latlng){
			this.parent.pathClick(Wiking.tools.getNearestPointIndex(latlng, this.pathPoints));
		}));
    }
    for(j=0; j<pointsOfTheLackOfCoverage.length; j++){
		x = new KMPolyline([pointsOfTheLackOfCoverage[j][0], pointsOfTheLackOfCoverage[j][1]], hexColor, 1, 0.6, 'test', 'dash');
//		x = this.polylineEncoder.dpEncodeToGPolyline(pointsOfTheLackOfCoverage[j], hexColor, 1, 0.6);
		this.path.push(x);
		Wiking.getMap().addOverlay(x);
		this.handlers.push(GEvent.bind(x,'click',this,function(latlng){
		}));
    }

    var period = Wiking.DataLoader.getPeriod();
	var points = Wiking.tools.breaks(array, period[0], period[1], 600);
	for(i=0; i<points.length; i++) {
		this.breakPoints.push(new BreakPoint(this.parent, array[0][points[i][0]], array[1][points[i][0]], array[3][points[i][0]], array[3][points[i][1]], this.color));
	}

	for(i=0; i<this.path.length; i++) {
		this.handlers.push(GEvent.bind(this.path[i],'mouseover',this.parent,this.parent.mouseover));
		this.handlers.push(GEvent.bind(this.path[i],'mouseout',this.parent,this.parent.mouseout));
	}

    console.debug('draw');
}
GHistoryPath.prototype.getBoundingBox = function(){
    var ret,i,b;
    try{
		ret = this.path[0].getBounds();
		for(i=1; i<this.path.length; i++) {
			b=this.path[i].getBounds();
			ret.extend(b.getSouthWest());
			ret.extend(b.getNorthEast());
		}
	} catch(e){
		ret = new GLatLngBounds(this.pathPoints[0],this.pathPoints[0])
	}
    return ret;
}
GHistoryPath.prototype.clearPath = function(){
    if (this.path.length>0){
		for(var i=0; i<this.path.length; i++) {
	        Wiking.getMap().removeOverlay(this.path[i]);
			delete this.path[i];
		}
        this.path = [];
		for(i=0; i<this.breakPoints.length; i++){
	        Wiking.getMap().removeOverlay(this.breakPoints[i]);
			delete this.breakPoints[i];
		}
		this.breakPoints = [];
    }
}
GHistoryPath.prototype.setColor = function(c){
    if (this.path.length>0){
		for(var i=0; i<this.path.length; i++)
			this.path[i].setStrokeStyle({color:c});
		for(i=0; i<this.breakPoints.length; i++)
			this.breakPoints[i].setColor(c);
    }
}
GHistoryPath.prototype.hide = function(){
    if (this.path.length>0){
		for(var i=0; i<this.path.length; i++)
	        this.path[i].hide();
		for(i=0; i<this.breakPoints.length; i++)
			this.breakPoints[i].hide();
    }
}
GHistoryPath.prototype.show = function(){
    if (this.path.length>0){
		for(var i=0; i<this.path.length; i++)
	        this.path[i].show();
		for(i=0; i<this.breakPoints.length; i++)
			this.breakPoints[i].show();
    }
}
GHistoryPath.prototype.append = function(x,y){
    if (typeof(x)=="number"){
        x = [x];
        y = [y];
    }
    var c = this.path[this.path.length-1].getVertexCount();
    var tmp;
    for(var i=0, j = x.length; i<j; i++){
        tmp = new GLatLng(y[j],x[j]);
        this.pathPoints.push(tmp);
        this.path[this.path.length-1].insertVertex(c,tmp);
        c+=1;
    }
    
}
