

hs = {
  scr: null,
  box: null,
  scrWidth: 0,
  scrHeight: 0,
  boxWidth: 0,
  boxHeight: 0,
  scrPosX: 0,
  scrPosY: 0,
  slideSpeed: 8,
  timer: 10,
  offset: 0,
  vis: false,
  vertOverflow: 0,
  lastTopOffset: 0,
  smoothTimer: null,
  activeArea: 10
} 
  
//============================
// inicializace HSM
//----------------------------
hs.init = function(elemID){
  hs.scr = getObj(elemID);
  hs.box = hs.scr.firstChild;
  hs.scrWidth = getDimensions(hs.scr)[0];
  hs.scrHeight = getDimensions(hs.scr)[1];
  hs.boxWidth = getDimensions(hs.box)[0];
  hs.boxHeight = getDimensions(hs.box)[1];
  hs.scrPosX = getPosition(hs.box)[0];
  hs.scrPosY = getPosition(hs.box)[1];
  
  if(hs.boxHeight < hs.scrHeight){
    hs.boxHeight = hs.scrHeight;
    hs.box.style.height = hs.scrHeight + 'px'; 
  }
  
  hs.vertOverflow = hs.boxHeight - hs.scrHeight;
 // hs.setPosition(hs.scrWidth, -hs.vertOverflow/2);  // vychozi pozice menu (0=top)
 // hs.setPosition(0, 0);  // vychozi pozice menu (0=top)
}

//===========================
// nastavi pozici elementu
//---------------------------
  hs.setPosition = function(x, y){
  hs.box.style.top = y + 'px';
  hs.box.style.left = x + 'px';
}

//===========================
// nastavi levy ofset elementu
//---------------------------
hs.setLeft = function(x){
  hs.box.style.left = x + 'px';
}

//===========================
// nastavi vrchni offset elementu
//---------------------------
hs.setTop = function(y){
  hs.box.style.top = y + 'px';
}

//===========================
// obsluhuje vertikalni skrolovani
//---------------------------
hs.scrollMenu = function(scrollRatio, resetTimer){
  if(resetTimer) clearTimeout(hs.smoothTimer);
  var targetOffset = hs.vertOverflow * (- scrollRatio);
  var newOffset = hs.lastTopOffset + (targetOffset - hs.lastTopOffset) * 0.08;
  hs.lastTopOffset = newOffset;
  if(Math.abs(targetOffset - newOffset) > 1){
    hs.setTop(newOffset);
    hs.smoothTimer = setTimeout(function(){hs.scrollMenu(scrollRatio, false)}, hs.timer);
  }
  else 
    clearTimeout(hs.smoothTimer);

}


hs.smoothScroll = function(topOffset, dy){
  dy *= 0.9;
  topOffset += dy;
  hs.setTop(topOffset);
  hs.smoothTimer = setTimeout(function(){hs.smoothScroll(topOffset, dy)}, hs.timer);
}


//===========================
// vraci pole s rozmery elementu
//---------------------------
function getDimensions(obj){
  return Array(parseInt(obj.offsetWidth), parseInt(obj.offsetHeight));
}

//===============================
// vrati pole s pozici elementu
//-------------------------------
function getPosition(obj){
  var curleft = curtop = 0;
  if(obj.offsetParent){
    do{
  		curleft += obj.offsetLeft;
  		curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
  }
  return [curleft,curtop];
}


//===============================
// zjisteni pozice mysi
//-------------------------------
hs.checkMousePosition = function(e){
  var mouseX;
  var mouseY;
  if (!e) {var e=window.event}
  if (e.pageX || e.pageY) {
    mouseX=e.pageX;
    mouseY=e.pageY;
  } 
  else if (e.clientX || e.clientY) with (document.body){
    mouseX=e.clientX+scrollLeft;
    mouseY=e.clientY+scrollTop;
  }
  
  if(mouseX >= (hs.scrPosX) && mouseX <= (hs.scrPosX + hs.boxWidth) && mouseY >= hs.scrPosY && mouseY <= (hs.scrPosY + hs.scrHeight) && hs.vertOverflow > 0){
    hs.scrollMenu((mouseY - hs.scrPosY)/(hs.scrHeight), true);
  }
  
}

//================================
// vraci instanci objektu se zadanym ID
//--------------------------------
function getObj(id){
   if(Boolean(document.getElementById))
      return document.getElementById(id);
   else if(Boolean(document.all))
      return eval('document.all.'+id);
   else
      return eval('document.'+id);
}


// inicializace zachytavani udalosti mysi
document.onmousemove = hs.checkMousePosition; 
