function avvia() {
  var wndo = new oscr('lscorr', 'testoscr');
  
   wndo.bSizeDragBar = false;
  
  oscr.GeckoTableBugFix('lscorr'); 
}
oscr.alt = function(wnId) {
  if ( oscrs[wnId] ) oscrs[wnId].endScroll();
}

oscr.doppio = function(wnId) {
  if ( oscrs[wnId] ) oscrs[wnId].speed *= 2;
}

oscr.norm = function(wnId) {
  if ( oscrs[wnId] ) oscrs[wnId].speed /= 2;
}
oscr.vai = function(wnId, deg, sp) {
  if ( oscrs[wnId] ) {
    var cosine, sine; 
    deg = deg % 360;
    if (deg % 90 == 0) {
      cosine = (deg == 0)? -1: (deg == 180)? 1: 0;
      sine = (deg == 90)? 1: (deg == 270)? -1: 0;
    } else {
      var angle = deg * Math.PI/180;
      cosine = -Math.cos(angle); sine = Math.sin(angle);
    }
    oscrs[wnId].fx = cosine / ( Math.abs(cosine) + Math.abs(sine) );
    oscrs[wnId].fy = sine / ( Math.abs(cosine) + Math.abs(sine) );
    oscrs[wnId].endX = (deg == 90 || deg == 270)? oscrs[wnId].x:
      (deg < 90 || deg > 270)? -oscrs[wnId].maxX: 0; 
    oscrs[wnId].endY = (deg == 0 || deg == 180)? oscrs[wnId].y: 
      (deg < 180)? 0: -oscrs[wnId].maxY;
    oscrs[wnId].startScroll(sp);
  }
}

oscr.prototype.startScroll = function(speed) {
  if (!this.ready) return; if (this.timerId) clearInterval(this.timerId);
  this.speed = speed || oscr.speed;
  this.zed = document.getElementById(this.zedId);
  this.lastTime = ( new Date() ).getTime();
  this.on_scroll_start();  
  this.timerId = setInterval(this.animString + ".scroll()", 10); 
}

oscr.prototype.scroll = function() {
  var now = ( new Date() ).getTime();
  var d = (now - this.lastTime)/1000 * this.speed;
  if (d > 0) {
    var x = this.x + this.fx * d; var y = this.y + this.fy * d;
    if (this.fx == 0 || this.fy == 0) { 
      if ( ( this.fx == -1 && x > -this.maxX ) || ( this.fx == 1 && x < 0 ) || 
        ( this.fy == -1 && y > -this.maxY ) || ( this.fy == 1 && y < 0 ) ) {
        this.lastTime = now;
        this.shiftTo(this.zed, x, y);
        this.on_scroll(x, y);
      } else {
        clearInterval(this.timerId); this.timerId = 0;
        this.shiftTo(this.zed, this.endX, this.endY);
        this.on_scroll_end(this.endX, this.endY);
      }
    } else { 
      if ( ( this.fx < 0 && x >= -this.maxX && this.fy < 0 && y >= -this.maxY ) ||
        ( this.fx > 0 && x <= 0 && this.fy > 0 && y <= 0 ) ||
        ( this.fx < 0 && x >= -this.maxX && this.fy > 0 && y <= 0 ) ||
        ( this.fx > 0 && x <= 0 && this.fy < 0 && y >= -this.maxY ) ) {
        this.lastTime = now;
        this.shiftTo(this.zed, x, y);
        this.on_scroll(x, y);
      } else {
        clearInterval(this.timerId); this.timerId = 0;
        this.on_scroll_end(this.x, this.y);
      }
    }
  }
}

oscr.prototype.endScroll = function() {
  if (!this.ready) return;
  if (this.timerId) clearInterval(this.timerId);
  this.timerId = 0;  this.zed = null;
}

oscr.prototype.on_scroll = function() {}
oscr.prototype.on_scroll_start = function() {}
oscr.prototype.on_scroll_end = function() {}
  

