﻿// JavaScript Document
function cu_scrollBarVer(){
	var ME = this
	var Buttons = ME.getElementsByTagName("BUTTON")
	var topButton = Buttons[0]
	var bottomButton = Buttons[1]
	var scrollStage = ME.getElementsByTagName("DIV")[0]
	var scrollStageContent = ME.getElementsByTagName("DIV")[1]
	var anchors=scrollStageContent.getElementsByTagName("A")
	var butListener, scrollUp, scrollDown, s, stopScroll
	var play = false
	var changedWidth = false
	if(bowserType!='explorer6')scrollStageContent.style.position='absolute'
	//alert(ME.getElementById)
	function butListener(){
		topButton.style.visibility= scrollStage.scrollTop>1? "visible":"hidden";
		bottomButton.style.visibility= scrollStage.offsetHeight < scrollStageContent.offsetHeight -scrollStage.scrollTop  ?"visible":"hidden";
		
		if (!changedWidth || bowserType!='explorer6'){
			
			ME.style.width= (scrollStageContent.offsetWidth+2).toString() +"px"
			changedWidth = true
		}
		
	}
	setInterval(butListener,200)
	topButton.onmousedown = function(){
		play = true
		scrollUp()	
		window.document.onmouseup=stopScroll
	}
	topButton.onmouseover =  topButton.onmousedown
	bottomButton.onmousedown = function(){
		play = true
		scrollDown()
		window.document.onmouseup=stopScroll
	}
	bottomButton.onmouseover =  bottomButton.onmousedown
	
	bottomButton.onmouseout=function(){play=false; }
	topButton.onmouseout=function(){play=false; }
	//topButton.onmouseout=Function('play=false')
	function stopScroll(){
		play = false	
		window.document.onmouseup=""
	}
	
	function scrollDown(){
		if(play){
			scrollStage.scrollTop = scrollStage.scrollTop +2
			clearTimeout(s)
			s=setTimeout(scrollDown, 30)
			
		}	
	}
	function scrollUp(){
		if(play){
			scrollStage.scrollTop = scrollStage.scrollTop -2
			clearTimeout(s)
			s=setTimeout(scrollUp, 30)
			
		}	
	}
	/*scrollStage.onmousewheel = function(e){
		if (!e) e = window.event;
		if(e.detail){
			scrollStage.scrollTop = e.detail  > 0 ? scrollStage.scrollTop +  7: scrollStage.scrollTop -  7
		}else if(e.wheelDelta){
			scrollStage.scrollTop = e.wheelDelta<0 ? scrollStage.scrollTop + 7 : scrollStage.scrollTop -  7
		}
		return false
		
	}
	
	if (window.addEventListener) {
		scrollStage.addEventListener('DOMMouseScroll', scrollStage.onmousewheel , false);
		
	}*/
	/// ************* check selecten anchors ****************//////////////
	function getSelectenAnchor(){
		var n
		//alert(anchors.length)
		for(n=0;n<anchors.length;n++){
			if(anchors[n].className.toLowerCase() == 'selected'){
				return  anchors[n]
				break
				//alert(anchors[n].className)
			}
			//alert(anchors[n].className)
			
		}
		return false
	}
	
	function jumpToSelectedAnchor(){
		var anchorTop = selectedAnchor.offsetTop + selectedAnchor.offsetHeight
		//alert(scrollStage.offsetHeight)
		if(anchorTop>scrollStage.offsetHeight){
			scrollStage.scrollTop = anchorTop - scrollStage.offsetHeight/2
			
		}
	}
	// get the selected anchor
	var  selectedAnchor = getSelectenAnchor()
	// if exists scroll to the location
	if(selectedAnchor) jumpToSelectedAnchor()
	
	

}
