/*
 * Scrollbar
 */
 function firstUpdateScroll(scrollControl, divId) {
   addEvent('domready', updateScroll(scrollControl, divId));
 }
 
 var dir_ws_images = 'images/';
 var scrollup = 'false';
 var scrolldown = 'false';
 var scrollAmount = 12;
 var scrollTime = 100;
 
 function autoScrollDown(scrollControl, divId) {
   scrolldown = scrollControl;
   ScrollDown(divId, '100');
 }
 
 function autoScrollUp(scrollControl, divId) {
   scrollup = scrollControl;
   ScrollUp(divId, '100');
 }
 
function ScrollDown(divId, amount){
  if(scrolldown == 'true'){
    scrollup = 'false';
    if (((document.getElementById(divId).scrollHeight*1) -
        (document.getElementById(divId).scrollTop*1)) >
        document.getElementById(divId).offsetHeight) { //confronta con altezza del div
      document.getElementById(divId).scrollTop = (document.getElementById(divId).scrollTop*1) + scrollAmount;
      if (amount > scrollAmount) {
      	setTimeout('ScrollDown(\''+divId+'\', '+ (amount) +')',scrollTime);
      }
    } else {
      scrolldown = 'false';
    }
  }
  updateScroll(scrolldown, divId);
}
function ScrollUp(divId, amount){
  if(scrollup == 'true'){
    scrolldown = 'false';
    if (((document.getElementById(divId).scrollHeight*1) -
        (document.getElementById(divId).scrollTop*1)) > 0) { 
      document.getElementById(divId).scrollTop = (document.getElementById(divId).scrollTop*1) - scrollAmount;
      if (amount > scrollAmount) {
      	setTimeout('ScrollUp(\''+divId+'\', '+ (amount) +')',scrollTime);
      }
    }  else {
      scrollup = 'false';
    }    
  }
  updateScroll(scrollup, divId);
}
function updateScroll(scrollControl, divId) {
  /*debugger;*/
  var scrollUp = divId+'_Up';
  var scrollDown = divId+'_Down';
  if ( ( (document.getElementById(divId).scrollHeight*1) - (document.getElementById(divId).scrollTop*1) ) >
        ( document.getElementById(divId).offsetHeight ) ) {

    document.getElementById(scrollDown).onmouseover= function() {
     autoScrollDown('true', divId);
     }
    document.getElementById(scrollDown).onmouseout=function() {
      autoScrollDown('false', divId);
    }
    document.getElementById(scrollDown).className="linkImage";
    if (scrolldown == 'true') {
      document.getElementById(scrollDown).src = dir_ws_images + 'theme/FrecciaDownON.jpg';
    } else {  
      document.getElementById(scrollDown).src = dir_ws_images + 'theme/FrecciaDownOFF.jpg';
    }
  } else {
    document.getElementById(scrollDown).onmouseover=function() {
	};
    document.getElementById(scrollDown).onmouseout= function() {
	};
    document.getElementById(scrollDown).className="linkImage"; 
    //if(scrollControl == 'true'){
  	//	document.getElementById(scrollDown).src = dir_ws_images + 'theme/FrecciaDownON.jpg';
  	//} else {
  		document.getElementById(scrollDown).src = dir_ws_images + 'theme/FrecciaDownOFF.jpg';
  	//}	
  }

  if ((document.getElementById(divId).scrollTop*1) > 0) { 
    document.getElementById(scrollUp).onmouseover=function () {
      autoScrollUp('true', divId);
    }  
    document.getElementById(scrollUp).onmouseout= function() {
      autoScrollUp('false', divId);
    }
    document.getElementById(scrollUp).className="linkImage"; 
    if (scrollup == 'true') {
      document.getElementById(scrollUp).src = dir_ws_images + 'theme/FrecciaUpON.jpg';
    } else {  
      document.getElementById(scrollUp).src = dir_ws_images + 'theme/FrecciaUpOFF.jpg'; 
    }  
  } else {
    document.getElementById(scrollUp).onmouseover=function() {
	};
    document.getElementById(scrollUp).onmouseout= function() {
	};
	document.getElementById(scrollUp).className="linkImage";

  		document.getElementById(scrollUp).src = dir_ws_images + 'theme/FrecciaUpOFF.jpg';
  	
  }
}

function CheckAndHide (scrollDiv, TextDiv) {
	if ((document.getElementById(TextDiv).scrollHeight - document.getElementById(TextDiv).offsetHeight) <= 0) {
	  document.getElementById(scrollDiv).style.visibility = "hidden";
	}
}
