nO.barScroll = new Object()
nO.barScroll.intPicWidth = 17
nO.barScroll.intArrowHeight = 17
nO.barScroll.intBarHeight = 33
nO.barScroll.xOffset = 5
nO.barScroll.timer = null

nO.barScroll.init = function(strLayer, blnNoBar, blnNoBarBg){
	nO.barScroll[strLayer] = new Object()
	nO.barScroll[strLayer].h = nO.getH(strLayer)
	nO.barScroll[strLayer].sh = nO.getScrollH(strLayer)
	nO.barScroll[strLayer].y = nO.getY(strLayer)
	if(nO.barScroll[strLayer].sh>nO.barScroll[strLayer].h){
		nO.barScroll[strLayer].maxscroll = nO.barScroll[strLayer].sh - nO.barScroll[strLayer].h
		nO.barScroll[strLayer].curpos = 0

		var x = nO.getX(strLayer) + nO.getW(strLayer) + nO.barScroll.xOffset
		var str1 = "<a href='javascript:;' onmouseover=\"nO.barScroll.arrow('" + strLayer + "', "; var str2 = ")\" onmouseout=\"clearTimeout(nO.barScroll.timer)\"><img src='"; var str3 = "' border='0'></a>"

		if(!nO.getObj(strLayer + "ArrowUp")) nO.createLayer(strLayer + "ArrowUp", x, nO.barScroll[strLayer].y, nO.barScroll.intPicWidth, 5, str1 + "1" + str2 + nO.barScroll.urlUpArrowPic + str3)

		var a = nO.barScroll[strLayer].y+nO.barScroll[strLayer].h-nO.barScroll.intArrowHeight
		nO.createLayer(strLayer + "ArrowDown", x, a, nO.barScroll.intPicWidth, 5, str1 + "-1" + str2 + nO.barScroll.urlDownArrowPic + str3)

		var a = nO.barScroll[strLayer].y+nO.barScroll.intArrowHeight
		var b = nO.barScroll[strLayer].h - 2*nO.barScroll.intArrowHeight

		if(!blnNoBarBg){
			nO.createLayer(strLayer + "BarBg", x, a, nO.barScroll.intPicWidth, 6,  "<img src='" + nO.barScroll.urlBarBgPic + "' name='" + strLayer + "BgPic' width=" + nO.barScroll.intPicWidth + " height=" + b + ">")
			nO.catchMouseEvent("click", "nO.barScroll.click", strLayer+"BarBg")	
		}
		if(!blnNoBar && !(nO.ie && nO.mac && nO.realVersion<5)){
			nO.createLayer(strLayer + "Drag", x, a, nO.barScroll.intPicWidth, 7, "<img name='" + strLayer + "DragPic' src='" + nO.barScroll.urlBarPic + "' border='0'>")
			if(nO.ie) document.ondragstart = function(){ return false}
			nO.catchMouseEvent("mousedown", "nO.barScroll.startDrag", strLayer+"Drag")	
		}
	}
}

nO.barScroll.scroll = function(strLayer, perc) {
	nO.barScroll[strLayer].curpos = Math.floor(perc * nO.barScroll[strLayer].maxscroll)

	var scrollHeight = nO.barScroll[strLayer].h - 2*nO.barScroll.intArrowHeight

	nO.moveTo(strLayer+"Drag", null, perc * (scrollHeight-nO.barScroll.intBarHeight) + nO.barScroll[strLayer].y + nO.barScroll.intArrowHeight)
	nO.moveTo(strLayer, null, nO.barScroll[strLayer].y - nO.barScroll[strLayer].curpos)
	nO.clip(strLayer, nO.barScroll[strLayer].curpos, nO.getW(strLayer), nO.barScroll[strLayer].curpos+nO.barScroll[strLayer].h,0)
}

nO.barScroll.arrow = function(strLayer, direction){
	if(nO.getObj(strLayer)){
		nO.barScroll[strLayer].curpos -= direction*nO.barScroll.scrollSpeed
		if(nO.barScroll[strLayer].curpos<0) nO.barScroll[strLayer].curpos = 0
		else if(nO.barScroll[strLayer].curpos>nO.barScroll[strLayer].maxscroll) nO.barScroll[strLayer].curpos = nO.barScroll[strLayer].maxscroll

		nO.barScroll.scroll(strLayer, nO.barScroll[strLayer].curpos / nO.barScroll[strLayer].maxscroll)
		nO.barScroll.timer = setTimeout("nO.barScroll.arrow('" + strLayer + "', " + direction + ")", 30)
	}
}

nO.barScroll.startDrag = function(evt){
	if(nO.ie) var targetID = window.event.srcElement.parentElement.id
	else if(nO.ns4 || nO.w3c) var targetID = evt.target.name
	nO.barScroll.curDrag = targetID.substr(0,targetID.indexOf("Drag"))
	nO.barScroll.deltaY = nO.getEventY(evt) - nO.getY(nO.barScroll.curDrag + "Drag")
	nO.catchMouseEvent("mousemove", "nO.barScroll.drag")	
	nO.catchMouseEvent("mouseup", "nO.barScroll.stopDrag")
	return false
}

nO.barScroll.stopDrag = function(evt){
	nO.catchMouseEvent("mousemove", "nO.barScroll.drag", null, true)	
	nO.catchMouseEvent("mouseup", "nO.barScroll.stopDrag", null, true)
}

nO.barScroll.drag = function(evt){
	var topY = nO.getEventY(evt) - nO.barScroll.deltaY 
	var scrollTop = nO.barScroll[nO.barScroll.curDrag].y + nO.barScroll.intArrowHeight
	var scrollHeight = nO.barScroll[nO.barScroll.curDrag].h - 2*nO.barScroll.intArrowHeight
		
	var scrollBottom = scrollTop + nO.barScroll[nO.barScroll.curDrag].h - 2*nO.barScroll.intArrowHeight - nO.barScroll.intBarHeight

	if(topY>=scrollTop && topY<=scrollBottom) var scrollPerc = (topY - scrollTop) / (scrollHeight-nO.barScroll.intBarHeight)
	else if(topY<scrollTop) var scrollPerc = 0
	else if(topY>scrollBottom) var scrollPerc = 1

	nO.barScroll.scroll(nO.barScroll.curDrag, scrollPerc)
}

nO.barScroll.click = function(evt){
	if(nO.ie) var targetID = window.event.srcElement.parentElement.id
	else if(nO.ns4 || nO.w3c) var targetID = evt.target.name
	targetID = targetID.substr(0, targetID.length-5)
	var clickY = nO.getEventY(evt) - nO.barScroll[targetID].y - nO.barScroll.intArrowHeight
	var scrollHeight = nO.barScroll[targetID].h - 2*nO.barScroll.intArrowHeight
	nO.barScroll.scroll(targetID, clickY / scrollHeight)
}

nO.barScroll.reset = function(strLayer){
	var objLayer = nO.getObj(strLayer)
	if(objLayer){
		nO.moveTo(strLayer, null, nO.barScroll[strLayer].y)
		nO.clip(strLayer, 0,nO.getW(strLayer),nO.barScroll[strLayer].h,0)
		if(nO.getObj(strLayer)+"Drag") nO.moveTo(strLayer+"Drag", null, nO.barScroll[strLayer].y + nO.barScroll.intArrowHeight)
		nO.barScroll[strLayer].curpos = 0
	}
}

nO.barScroll.hide = function(strLayer){
	nO.hide(strLayer + "ArrowUp")
	nO.hide(strLayer + "ArrowDown")
	nO.hide(strLayer + "BarBg")
	nO.hide(strLayer + "Drag")
}

nO.barScroll.show = function(strLayer){
	nO.show(strLayer + "ArrowUp")
	nO.show(strLayer + "ArrowDown")
	nO.show(strLayer + "BarBg")
	nO.show(strLayer + "Drag")
}

nO.barScroll.moveBy = function(strLayer,x,y){
	nO.moveBy(strLayer + "ArrowUp",x,y)
	nO.moveBy(strLayer + "ArrowDown",x,y)
	nO.moveBy(strLayer + "BarBg",x,y)
	nO.moveBy(strLayer + "Drag",x,y)
}
