/************************************************************************************************************
	(C) www.dhtmlgoodies.com, September 2005
	
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission.
	
	Thank you!
	
	www.dhtmlgoodies.com
	Alf Magne Kalleland
	
	************************************************************************************************************/	
	var contentHeight = 0; 	// The total height of the content
	var visibleContentHeight = 0;	
	var scrollActive = false;
	
	var scrollHandleObj = false; // reference to the scroll handle
	var scrollHandleHeight = false;
	var scrollbarTop = false;
	var eventYPos = false;

	var scrollbuttonActive = false;
	var scrollbuttonDirection = false;
	var scrollbuttonSpeed = 2; // How fast the content scrolls when you click the scroll buttons(Up and down arrows)
	var scrollTimer = 10;	// Also how fast the content scrolls. By decreasing this value, the content will move faster	
	
	var scrollMoveToActive = false;
	var scrollMoveToYPosition = false;
	function scrollDiv_startScroll_half(e)
	{
		if(document.all)e = event;
		scrollbarTop = document.getElementById('scrolldiv_theScroll_half').offsetTop;
		eventYPos = e.clientY;
		scrollActive = true;
		//alert('Scroll Full in');
	}
	
	function scrollDiv_stopScroll_half()
	{
		scrollActive = false;
		scrollbuttonActive = false;
		scrollMoveToActive = false;
		//alert('stop');
	}
	function scrollDiv_scroll_half(e)
	{
		if(!scrollActive)return;
		if(document.all)e = event;
		if(e.button!=1 && document.all)return;
		var topPos = scrollbarTop + e.clientY - eventYPos; 
		if(topPos<0)topPos=0;
		if(topPos/1>visibleContentHeight-(scrollHandleHeight+4)/1)topPos = visibleContentHeight-(scrollHandleHeight+4);
		document.getElementById('scrolldiv_theScroll_half').style.top = topPos + 'px';
		document.getElementById('scrolldiv_content_half').style.top = 0 - Math.floor((contentHeight) * ((topPos)/(visibleContentHeight-scrollHandleHeight)))+'px' 
	}
	
	/*
	Click on the slider
	Move the content to the this point
	*/
	function scrolldiv_scrollMoveToInit_half(e)
	{		
		if(document.all)e = event;
		scrollMoveToActive = true;
		scrollMoveToYPosition = e.clientY - document.getElementById('scrolldiv_scrollbar_half').offsetTop;
		if(document.getElementById('scrolldiv_theScroll_half').offsetTop/1 > scrollMoveToYPosition) scrollbuttonDirection = scrollbuttonSpeed*-2; else  scrollbuttonDirection = scrollbuttonSpeed*2;
		scrolldiv_scrollMoveTo();	
	}
	
	function scrolldiv_scrollMoveTo_half()
	{
		if(!scrollMoveToActive || scrollActive)return;
		var topPos = document.getElementById('scrolldiv_theScroll_half').style.top.replace('px','');
		topPos = topPos/1 + scrollbuttonDirection;
		if(topPos<0){
			topPos=0;
			scrollMoveToActive=false;
		}
		if(topPos/1>visibleContentHeight-(scrollHandleHeight+4)/1){
			topPos = visibleContentHeight-(scrollHandleHeight+4);	
			scrollMoveToActive=false;
		}
		if(scrollbuttonDirection<0 && topPos<scrollMoveToYPosition-scrollHandleHeight/2)return;	
		if(scrollbuttonDirection>0 && topPos>scrollMoveToYPosition-scrollHandleHeight/2)return;			
		document.getElementById('scrolldiv_theScroll_half').style.top = topPos + 'px';
		document.getElementById('scrolldiv_content_half').style.top = 0 - Math.floor((contentHeight) * ((topPos)/(visibleContentHeight-scrollHandleHeight)))+'px' 		
		setTimeout('scrolldiv_scrollMoveTo()',scrollTimer);		
	}
	
	function cancelEvent_half()
	{
		return false;			
	}

	function scrolldiv_scrollButton_half()
	{
		if(this.id=='scrolldiv_scrollDown_half')scrollbuttonDirection = scrollbuttonSpeed; else scrollbuttonDirection = scrollbuttonSpeed*-1;
		scrollbuttonActive=true;
		scrolldiv_scrollButtonScroll();
	}
	function scrolldiv_scrollButtonScroll_half()
	{
		if(!scrollbuttonActive)return;
		var topPos = document.getElementById('scrolldiv_theScroll_half').style.top.replace('px','');
		topPos = topPos/1 + scrollbuttonDirection;
		if(topPos<0){
			topPos=0;
			scrollbuttonActive=false;
		}
		if(topPos/1>visibleContentHeight-(scrollHandleHeight+4)/1){
			topPos = visibleContentHeight-(scrollHandleHeight+4);	
			scrollbuttonActive=false;
		}	
		document.getElementById('scrolldiv_theScroll_half').style.top = topPos + 'px';
		document.getElementById('scrolldiv_content_half').style.top = 0 - Math.floor((contentHeight) * ((topPos)/(visibleContentHeight-scrollHandleHeight)))+'px' 			
		setTimeout('scrolldiv_scrollButtonScroll()',scrollTimer);
	}
	function scrolldiv_scrollButtonStop_half()
	{
		scrollbuttonActive = false;
	}
	
	
	function scrolldiv_initScroll_half()
	{
		visibleContentHeight = document.getElementById('scrolldiv_scrollbar_half').offsetHeight ;
		contentHeight = document.getElementById('scrolldiv_content_half').offsetHeight - visibleContentHeight;		
		scrollHandleObj = document.getElementById('scrolldiv_theScroll_half');
		scrollHandleHeight = scrollHandleObj.offsetHeight;
		scrollbarTop = document.getElementById('scrolldiv_scrollbar_half').offsetTop;		
		document.getElementById('scrolldiv_theScroll_half').onmousedown = scrollDiv_startScroll_half;
		document.body.onmousemove = scrollDiv_scroll_half;
		document.getElementById('scrolldiv_scrollbar_half').onselectstart = cancelEvent_half;
		document.getElementById('scrolldiv_theScroll_half').onmouseup = scrollDiv_stopScroll_half;
		if(document.all)document.body.onmouseup = scrollDiv_stopScroll_half; else document.documentElement.onmouseup = scrollDiv_stopScroll_half;
		document.getElementById('scrolldiv_scrollDown_half').onmousedown = scrolldiv_scrollButton_half;
		document.getElementById('scrolldiv_scrollUp_half').onmousedown = scrolldiv_scrollButton_half;
		document.getElementById('scrolldiv_scrollDown_half').onmouseup = scrolldiv_scrollButtonStop_half;
		document.getElementById('scrolldiv_scrollUp_half').onmouseup = scrolldiv_scrollButtonStop_half;
		document.getElementById('scrolldiv_scrollUp_half').onselectstart = cancelEvent_half;
		document.getElementById('scrolldiv_scrollDown_half').onselectstart = cancelEvent_half;
		document.getElementById('scrolldiv_scrollbar_half').onmousedown = scrolldiv_scrollMoveToInit_half;
		
	}
	/*
	Change from the default color
	*/	
	function scrolldiv_setColor_half(rgbColor)
	{	
		document.getElementById('scrolldiv_scrollbar_half').style.borderColor = rgbColor;
		document.getElementById('scrolldiv_theScroll_half').style.backgroundColor = rgbColor;
		document.getElementById('scrolldiv_scrollUp_half').style.borderColor = rgbColor;
		document.getElementById('scrolldiv_scrollDown_half').style.borderColor = rgbColor;
		document.getElementById('scrolldiv_scrollUp_half').style.backgroundColor = rgbColor;
		document.getElementById('scrolldiv_scrollDown_half').style.backgroundColor = rgbColor;
		document.getElementById('scrolldiv_parentContainer_half').style.borderColor = rgbColor;
		
	}
	/*
	Setting total width of scrolling div
	*/
	function scrolldiv_setWidth_half(newWidth)
	{
		document.getElementById('dhtmlgoodies_scrolldiv_half').style.width = newWidth + 'px';
		document.getElementById('scrolldiv_parentContainer_half').style.width = newWidth-30 + 'px';	

	}
	
	/*
	Setting total height of scrolling div
	*/
	function scrolldiv_setHeight_half(newHeight)
	{
		document.getElementById('dhtmlgoodies_scrolldiv_half').style.height = newHeight + 'px';
		document.getElementById('scrolldiv_parentContainer_half').style.height = newHeight + 'px';
		document.getElementById('scrolldiv_slider_half').style.height = newHeight + 'px';
		document.getElementById('scrolldiv_scrollbar_half').style.height = newHeight-40 + 'px';		
	}
	/*
	Setting new background color to the slider 
	*/
	function setSliderBgColor_half(rgbColor)
	{
		document.getElementById('scrolldiv_scrollbar_half').style.backgroundColor = rgbColor;
		//document.getElementById('scrolldiv_scrollUp_half').style.backgroundColor = rgbColor;
		//document.getElementById('scrolldiv_scrollDown_half').style.backgroundColor = rgbColor;
	}
	/*
	Setting new content background color
	*/
	function setContentBgColor_half(rgbColor)
	{
		document.getElementById('scrolldiv_parentContainer_half').style.backgroundColor = rgbColor;
	}
	
	/*
	Setting scroll button speed
	*/
	function setScrollButtonSpeed_half(newScrollButtonSpeed)
	{
		scrollbuttonSpeed = newScrollButtonSpeed;
	}
	/*
	Setting interval of the scroll
	*/
	function setScrollTimer_half(newInterval)
	{
		scrollTimer = newInterval;
	}
	
	