﻿var t;
var kadras=0;
var target_id=new Array();
var id_scroll=0;

function scrollingSystemPre(scroll, idnr){
  id_scroll=idnr;

  if (scroll>0){scrollingSystem(10);} else if(scroll<0) {scrollingSystem(-10);}
}

function scrollingSystem(x){

  clearTimeout(t);

  document.getElementById(target_id[id_scroll]).scrollTop=document.getElementById(target_id[id_scroll]).scrollTop+x;

  if (x>0) {
	if (kadras<10){
		t=setTimeout("scrollingSystem(2)", 20);
	} else if(kadras<25){
		t=setTimeout("scrollingSystem(4)", 20);
	} else if(kadras<50){
		t=setTimeout("scrollingSystem(6)", 20);
	} else {
		t=setTimeout("scrollingSystem(8)", 20);
	}
  } else {
	if (kadras<10){
		t=setTimeout("scrollingSystem(-2)", 20);
	} else if(kadras<25){
		t=setTimeout("scrollingSystem(-4)", 20);
	} else if(kadras<50){
		t=setTimeout("scrollingSystem(-6)", 20);
	} else {
		t=setTimeout("scrollingSystem(-8)", 20);
	}
  }

  kadras+=1;

}



function bandex(){

clearTimeout(t);
kadras=0;

}

function scrollingSystem_ini(id_text, id_scrollbar, reset){  //scrolinamas objektas, skrolinimo rodykliu laikiklis, ar inicijuojant resetinti pozicija (1- taip)

  var jau=false;
  var i=0;
  while (!jau){
    if (target_id[i]){i++;} else {jau=true;}
  }
  target_id[i]=id_text;

  var ob=document.getElementById(id_text);

  if (reset==1){  ob.scrollTop=0; }

  if (ob.scrollHeight>ob.offsetHeight){

    var tekstas="";
    var scrollAukstis=ob.offsetHeight-22;

    tekstas="<img src='gal-.gif' onmousedown='scrollingSystemPre(-10, "+i+")' onmouseup='bandex()' style='cursor:pointer;' />";
    tekstas+="<div style='height:"+scrollAukstis+"'>&nbsp;</div>";
    tekstas+="<img src='gal+.gif' onmousedown='scrollingSystemPre(10, "+i+")' onmouseup='bandex()' style='cursor:pointer;' />";

    document.getElementById(id_scrollbar).innerHTML=tekstas;

    scrollingSystemPre(0, i);
    bandex();

    /* Initialization code. */
    if (window.addEventListener)
	ob.addEventListener('DOMMouseScroll', wheel, false);
    ob.onmousewheel = wheel;


  }

}

//mouse wheel control====================

/** This is high-level function; REPLACE IT WITH YOUR CODE.
 * It must react to delta being more/less than zero.
 */
function handle(delta) {
	if (delta < 0){
		/* something. */
		scrollingSystem(20);
		bandex();
	}else{
		/* something. */
		scrollingSystem(-20)
		bandex();
	}
}

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)
		handle(delta);
        if (event.preventDefault)
                event.preventDefault();
        event.returnValue = false;
}

/* Initialization code. */
/*
if (window.addEventListener)
	window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;
*/
//mouse wheel control====================
