
function upScr(el){
	timerScroll = setInterval("moveScr("+(-offsetpx)+")",50);
	el.onmouseup = function(){clearInterval(timerScroll);}
	el.onmouseout = function(){clearInterval(timerScroll);}
	return false;
}
function downScr(el){
	timerScroll = setInterval("moveScr("+offsetpx+")",50);
	el.onmouseup = function(){clearInterval(timerScroll);}
	el.onmouseout = function(){clearInterval(timerScroll);}
	return false;
}

function setBarPos(el,pCent){
	var maxx = el.parentNode.clientHeight - el.clientHeight;
	var newPos = Math.ceil(maxx  / 100 * pCent);
	el.style.marginTop = newPos+'px';
}

function moveScr(moffset){
	sDiv.scrollTop = sDiv.scrollTop + moffset;
	var pCent = Math.ceil((sDiv.scrollTop / parseInt(sDiv.scrollHeight - sDiv.clientHeight))*100);
	setBarPos(sBt,pCent);
}
function moveScrTo(mpCent){
	var newPos = Math.ceil(sDiv.scrollHeight / 100) * mpCent;
	sDiv.scrollTop = newPos;
	setBarPos(sBt,mpCent);
}
function moveScrLink(mlink){
	var vLinkStr = mlink.hash.substring(1);
	var vLinkObj = document.getElementById(vLinkStr);
	sDiv.scrollTop = vLinkObj.offsetTop;
	pCent = Math.ceil((sDiv.scrollTop / parseInt(sDiv.scrollHeight - sDiv.clientHeight))*100);
	setBarPos(sBt,pCent);
}

function dragBar(el){
	sBt.initPos = tempY - findOffset(sBt.parentNode) - (sBt.clientHeight) ;
	sBt.maxx = sBt.parentNode.clientHeight - sBt.clientHeight;
	sBt.initPos = (sBt.initPos <= 0 ) ? 0 : (sBt.initPos >= sBt.maxx ) ? sBt.maxx : sBt.initPos; /* if < 0 =0 . if > container size = container size - height. else ok*/
	var sCent = Math.ceil(sBt.initPos / parseInt(sBt.parentNode.clientHeight) *100);
	moveScrTo(sCent);
	return false;
}

function releaseBar(){
	sBt.onmousemove = null;
	return false;
}

function onDragBar(){
	this.onmousemove = dragBar;
}
function montaScrollBar(el){

	if(!document.getElementById || !document.createElement ||  window.opera || !window.print ) return false;
	sDiv = document.getElementById('contentScroll');
	offsetpx = 20;


// create scroll elements
var newElem = document.createElement("DIV");
newElem.id = "scrollCont";
newElem.innerHTML = '<a href="#" id="scrolltop" class="btscroll" onmouseover="return upScr(this);">up</a>\n	<div id="scrollbar"><a href="#" class="btscroll" id="scrollbarbt">bar</a></div>\n	<a href="#" id="scrollbottom" class="btscroll" onmouseover="return downScr(this);">down</a>';
sDiv.parentNode.appendChild(newElem);

sDiv.parentNode.insertBefore(sDiv, newElem);

	sBt = document.getElementById('scrollbarbt');

	sBt.onclick = function(){return false;}
	sBt.onmousedown = onDragBar;
	sBt.onmouseup = releaseBar;
	sBt.parentNode.onmouseup = releaseBar;
	document.onmouseup = releaseBar;


	sDiv.style.height = sDiv.clientHeight+'px';
	sDiv.style.overflow = "hidden";


	// init mouseY
	IE = document.all?true:false;
	if (!IE) document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = getMouseXY;
	tempY = 0;
}




function getMouseXY(e) {
	if(IE){tempY = event.clientY + document.body.scrollTop;}
	else{tempY = e.pageY;}
	if (tempY < 0){tempY = 0}
	//document.Show.MouseY.value = tempY;
	return true;
}


function findOffset(elem) {
var obj = elem;
var curtop = 0;
if (obj.offsetParent) {
	while (obj.offsetParent){
		curtop += obj.offsetTop;
		obj = obj.offsetParent;
	}
} else if (obj.y) {curtop += obj.y;}
return curtop;
}

