Two polylines and map each other

I have two polylines. When mouse is over one of then, a should map this on the other line, but haven’t got any idea how to measure distanse on that first line from the begining to current (mouse over) point.

Any ideas?