shock_limit = 3; // celkove rozpeti trepani v pixelech
shock_speed = 50; // zmena v milisekundach
menu_shocked = new Array ();
still_shock = "";
gb = 0;


function shock (id) {
  
  top_val = Math.round (Math.random () * shock_limit - shock_limit / 2);
  left_val = Math.round (Math.random () * shock_limit - shock_limit / 2);
  
  document.getElementById (id).style.top = top_val + "px";
  document.getElementById (id).style.left = left_val + "px";
  
  menu_shocked [id] = window.setTimeout ("shock ('" + id + "');", shock_speed);
    
}

function unshock (id) {
  
  if (id != still_shock) {
    
    window.clearTimeout (menu_shocked [id]);
  
    document.getElementById (id).style.top = "0px";
    document.getElementById (id).style.left = "0px";
    
  }
  
}






if (window.addEventListener)
  window.addEventListener('DOMMouseScroll', wheel, false);
        
window.onmousewheel = document.onmousewheel = wheel;



scrollbar_height = 100;
scrollbar_moved = 0;
scroll_once_speed = 80;

function scrollbar_move_from (e) {
  scrollbar_moved = 1;
}


function scrollbar_move_to (e) {
  
  if (gb)
    document.getElementById ("gb").style.display = "none";
  
  if (content_height > 486) {
  
    scrollbar_moved = 0;
    
    if (document.documentElement.scrollTop)
      scroll_top = document.documentElement.scrollTop;
    else
      scroll_top = 0;
    
    scrollbar_top = scroll_top + e.clientY - scrollbar_height / 2;
    if (scrollbar_top < 196)
      scrollbar_top = 196;
    if (scrollbar_top * 1 + scrollbar_height * 1 > 682)
      scrollbar_top = 682 - scrollbar_height;
    
    scroll_to (scrollbar_top);
    
    document.getElementById ("scrollbar").style.visibility = "hidden";
    document.getElementById ("scrollbar").style.top = scrollbar_top + "px";
    document.getElementById ("scrollbar").style.visibility = "visible";
    
  }
  
  if (gb)
    window.setTimeout ("document.getElementById ('gb').style.display = 'block';", 2)
}

function scrollbar_move (e) {
  
  if (scrollbar_moved) {
    scrollbar_move_to (e)
    scrollbar_moved = 1;
  }
  
}

function scrollbar_release (e) {
  
  if (scrollbar_moved) {
    scrollbar_move_to (e)
  }
  
}

function scroll_to (topOn) {
  
  content_top = 196 - Math.round ((topOn - 196) / 486 * content_height);
  
  document.getElementById ("content").style.top = content_top + "px";
  document.getElementById ("content").style.clip = "rect(" + (196 - content_top) + "px 406px " + (486 + 196 - content_top) + "px 0px)";
  document.getElementById ("content").style.height = (486 + 196 - content_top) + "px";
  
}


function scroll_once (delta) {
  
  if (gb)
    document.getElementById ("gb").style.display = "none";
  
  if (content_height > 486) {
  
    scroll_once_top = parseInt (document.getElementById ("content").style.top) + scroll_once_speed * delta;
    
    if (scroll_once_top > 196) {
      document.getElementById ("content").style.top = "196px";
      document.getElementById ("content").style.clip = "rect(0px 406px 486px 0px)";
      document.getElementById ("content").style.height = "486px";
      document.getElementById ("scrollbar").style.top = "196px";
    }
    else if (scroll_once_top < 196 + 486 - content_height) {
      document.getElementById ("content").style.top = (196 + 486 - content_height) + "px";
      document.getElementById ("content").style.clip = "rect(" + (content_height - 486) + "px 406px " + content_height + "px 0px)";
      document.getElementById ("content").style.height = content_height + "px";
      document.getElementById ("scrollbar").style.top = 682 - scrollbar_height + "px";
    }
    else {
      
      scroll_once_clip = document.getElementById ("content").style.clip.substring (5).split (" ");
      
      document.getElementById ("content").style.top = scroll_once_top + "px";
      document.getElementById ("content").style.clip = "rect(" + (parseInt (scroll_once_clip [0]) + scroll_once_speed * (-delta)) + "px 406px " + (parseInt (scroll_once_clip [2]) + scroll_once_speed * (-delta)) + "px 0px)";
      document.getElementById ("content").style.height = parseInt (document.getElementById ("content").style.height) + scroll_once_speed * (-delta) + "px";
      document.getElementById ("scrollbar").style.top = Math.round ((196 - parseInt (document.getElementById ("content").style.top)) / content_height * 486) + 196 + "px";
    }
    
  }
  
  if (gb)
    window.setTimeout ("document.getElementById ('gb').style.display = 'block';", 2)
    
}

function wheel (event) {
  var delta = 0;
  
  if (!event)
    event = window.event;
    
  if (event.wheelDelta) {
    delta = event.wheelDelta / 120;
    if (window.opera)
      delta = -delta;
  }
  else if (event.detail) {
    delta = -event.detail / 3;
  }
  
  if (delta)
    scroll_once (delta);

  if (event.preventDefault)
    event.preventDefault();
  event.returnValue = false;
}

function scrollbar_ini () {
  
  original_height = document.getElementById ("content").style.height;
  document.getElementById ("content").style.height = "";
  
  content_height = document.getElementById ("content").clientHeight;
  scrollbar_height = Math.min (486, 486 / content_height * 486);
  
  document.getElementById ("scrollbar").style.height = scrollbar_height + "px";
  
  if (!original_height)
    document.getElementById ("content").style.height = "486px";
  else
    document.getElementById ("content").style.height = original_height;
  
  if (!document.getElementById ("content").style.clip)
    document.getElementById ("content").style.clip = "rect(0px 406px 486px 0px)";
  if (!document.getElementById ("content").style.top)
    document.getElementById ("content").style.top = "196px";
  if (!document.getElementById ("scrollbar").style.top)
    document.getElementById ("scrollbar").style.top = "196px";
  
  browser = navigator.userAgent;
  if (browser.indexOf ("Netscape") != -1 || browser.indexOf ("Firefox") != -1)
    document.getElementById ("content").style.overflow = "-moz-hidden-unscrollable";
  else
    document.getElementById ("content").style.overflow = "hidden";
    
  document.getElementById ("content").style.visibility = "visible";
  
}
