//move.js      

//  ---------------------------------------------------------------------------
HTMLDivElement.prototype.move = function(pathFunction, speedFunction, startFunction, stopFunction) {

  this.drawFunction = function (node) {
    node = node.onStart (node);
    node.interval = setInterval(function () {node.moveFunction(node)}, speedFunction(node));
  };
  
  this.moveFunction = function (node) {
    if (stopFunction(node)) {
      clearTimeout (node.interval);
      node = node.onStop (node);
      return node;
    } else
      return node.changePosition(new pathFunction(node));
  };
  
  this.onStart = function (node) {
    return node;
  };

  this.onStop = function (node) {
    return node;
  };

  this.changePosition = function (pos) {
    this.style.position = 'absolute';
    this.style.left = Math.max(0, parseInt(pos.left, 10)) + 'px';
    this.style.top  = Math.max(0, parseInt(pos.top , 10)) + 'px';
    return this;
  };

  var node = this;
  window.setTimeout(function () {node.drawFunction(node)}, startFunction(node));
  return this;
};
//  ---------------------------------------------------------------------------

