var scrollIncrement = 32;

var layer;
var layerHeight = 0;
var clipHeight  = 430;

function mouseScroll()
{
    if (event.wheelDelta >= 120) {
       scrollUp(1);
    } else if (event.wheelDelta <= -120) {
       scrollDown(1);
    }
}


function init()
{
   var url = "" + window.location;
   if (url.indexOf("print") != -1) {
      if (window.print) {
         window.print();
         window.close();
      }
      return;
   }
   if (document.layers) {
      layerHeight = document.innhold.document.tekstvindu.document.tekst.document.height;
   } else if (document.all) {
      layerHeight = document.all.tekst.offsetHeight;
   } else {
      layerHeight = document.getElementById("tekst").offsetHeight;
   }

   if (layerHeight > clipHeight) { 
      var htmlStr = '<A HREF="#" onClick="scrollUp(' + (clipHeight/scrollIncrement) + ')"><IMG src="/bitmaps/pil_opp.gif" border="0" alt="scroll opp" vspace="2"></A><BR><A HREF="#" onClick="scrollDown(10)"><IMG src="/bitmaps/pil_ned.gif" border="0" vspace="2" alt="scroll ned"></A>'
      if (document.layers) {
         document.innhold.document.scrollknapper.document.open();
         document.innhold.document.scrollknapper.document.write(htmlStr);
         document.innhold.document.scrollknapper.document.close();
      } else if (document.all) {
         document.all.scrollknapper.innerHTML = htmlStr;
      } else {
         var obj = document.getElementById("scrollknapper");
         obj.innerHTML = htmlStr;
      }
   }  

   preloadImages();
}


function getLayerYPos()
{
   var y = 0;
   
   if (document.layers) {
      y = document.innhold.document.tekstvindu.document.tekst.top;
   } else if (document.all) {
      y = parseInt(document.all.tekst.style.pixelTop);
   } else {
      var obj = document.getElementById("tekst");
      if (obj) {
         var browserName  = navigator.appName;
         var tmp;
         if (browserName.indexOf("Opera") != -1) {
            tmp = obj.style.pixelTop;
         } else {
            tmp = obj.style.top;
         }
         if (tmp != "") y = parseInt(tmp);
      }
   }
   return y;
}

function setLayerYPos(y)
{
   if (document.layers) {
      document.innhold.document.tekstvindu.document.tekst.top = y;
   } else if (document.all) {
      document.all.tekst.style.pixelTop = y;
   } else {
      var obj = document.getElementById("tekst");
      if (obj) {
         var browserName  = navigator.appName;
         if (browserName.indexOf("Opera") != -1) {
            obj.style.pixelTop = y;
         } else {
            obj.style.top = y;
         }
      }
   }
}


function scrollDown(count)
{
   var y = getLayerYPos();
      
   if ((y - scrollIncrement) < (-layerHeight)) {
      y = -(layerHeight);
      setLayerYPos(y);
      return -1;
   } else {
      y = y - scrollIncrement;
      setLayerYPos(y);
      if (count > 0) {
         setTimeout("scrollDown(" + (count - 1) + ")", 15);
      }
      return 0;
   }  
}


function scrollUp(count)
{
   var y = getLayerYPos();

   if (y + scrollIncrement > 0) {
      setLayerYPos(0);
      return -1;
   } else {   
      y = y + scrollIncrement;
      setLayerYPos(y);
      if (count > 0) {
         setTimeout("scrollUp(" + (count - 1) + ")", 15);
      }
      return 0;
   }
}

function printWindow() {
   var url = "" + window.location;
   var query = "?";
   if (url.indexOf("?") != -1) {
      query = "&";
   }
   
   window.open(url + query + "print=1", "printwindow");
}