var item_clicked = "__";

function chkSeveral(item) {
   if(document.getElementById(item)) {
   	var e = document.getElementById(item);
   	if(item != item_clicked) {
			e.className = e.className+"over";
		}else if(item == item_clicked) {
			e.className = e.className+"over";
		}
		item_clicked = item;
		//alert(e.className);
	}
}

var contentHeight = 0; 	// The total height of the content
var visibleContentHeight = 0;
var scrollActive = false;

var objHandle = false; // reference to the scroll handle
var objHandleHeight = false;
var objScrollbar_top = false;
var eventYPos = false;

var scrollActive = false;
var scrollDirection = false;
var scrollSpeed = 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;

var operaBrowser = false;
if(navigator.userAgent.indexOf('Opera') >= 0) operaBrowser = 1;

function startScroll(e)	{
	if(document.all && !operaBrowser)e = event;
	objScrollbar_top = document.getElementById('div_scrollHandle').offsetTop;
	eventYPos = e.clientY;
	scrollActive = true;
}

function stopScroll()	{
	scrollActive = false;
	scrollActive = false;
	scrollMoveToActive = false;
}

function scroll(e)	{
	if(!scrollActive) return;
	if(document.all && !operaBrowser) e = event;
	if(e.button != 1 && document.all) return;
	var topPos = objScrollbar_top + e.clientY - eventYPos;
	if(topPos<0) topPos = 0;
	if(topPos/1 > visibleContentHeight-(objHandleHeight+4)/1) topPos = visibleContentHeight-(objHandleHeight+4);
	document.getElementById('div_scrollHandle').style.top = topPos + 'px';
	document.getElementById('mainContent_content').style.top = 0 - Math.floor((contentHeight) * ((topPos)/(visibleContentHeight-objHandleHeight)))+'px';
}

/*	Click on the slider.	Move the content to the this point	*/
function scrolldiv_MoveToInit(e)	{
	if(document.all && !operaBrowser) e = event;
	scrollMoveToActive = true;
	scrollMoveToYPosition = e.clientY - document.getElementById('div_scrollBar').offsetTop;
	if(document.getElementById('div_scrollHandle').offsetTop/1 > scrollMoveToYPosition) {
		scrollDirection = scrollSpeed*-2; 
	}else{
		scrollDirection = scrollSpeed*2;
	}
	scrolldiv_MoveTo();
}

function scrolldiv_MoveTo()	{
	if(!scrollMoveToActive || scrollActive) return;
	var topPos = document.getElementById('div_scrollHandle').style.top.replace('px','');
	topPos = topPos/1 + scrollDirection;
	if(topPos<0) {
		topPos=0;
		scrollMoveToActive = false;
	}
	if(topPos/1>visibleContentHeight-(objHandleHeight+4)/1) {
		topPos = visibleContentHeight-(objHandleHeight+4);
		scrollMoveToActive=false;
	}
	if(scrollDirection<0 && topPos<scrollMoveToYPosition-objHandleHeight/2) return;
	if(scrollDirection>0 && topPos>scrollMoveToYPosition-objHandleHeight/2) return;
	document.getElementById('div_scrollHandle').style.top = topPos + 'px';
	document.getElementById('mainContent_content').style.top = 0 - Math.floor((contentHeight) * ((topPos)/(visibleContentHeight-objHandleHeight)))+'px'
	setTimeout('scrolldiv_MoveTo()',scrollTimer);
}

function cancelEvent()	{
	return false;
}

function scrollButton()	{
	if(this.id=='div_scrollDown') {
		scrollDirection = scrollSpeed; 
	}else{
		scrollDirection = scrollSpeed*-1;
	}
	scrollActive = true;
	scrolldiv_scrollButtonScroll();
}

function scrolldiv_scrollButtonScroll()	{
	if(!scrollActive) return;
	var topPos = document.getElementById('div_scrollHandle').style.top.replace('px','');
	topPos = topPos/1 + scrollDirection;
	if(topPos<0) {
		topPos=0;
		scrollActive=false;
	}
	if(topPos/1>visibleContentHeight-(objHandleHeight+4)/1) {
		topPos = visibleContentHeight-(objHandleHeight+4);
		scrollActive = false;
	}
	document.getElementById('div_scrollHandle').style.top = topPos + 'px';
	document.getElementById('mainContent_content').style.top = 0 - Math.floor((contentHeight) * ((topPos)/(visibleContentHeight-objHandleHeight)))+'px'
	setTimeout('scrolldiv_scrollButtonScroll()',scrollTimer);
}

function scrollButtonStop()	{
	scrollActive = false;
}


function scrolldiv_initScroll(h)	{
	visibleContentHeight = h+document.getElementById('div_scrollBar').offsetHeight ;
	contentHeight = document.getElementById('mainContent_content').offsetHeight - visibleContentHeight;
	objHandle = document.getElementById('div_scrollHandle');
	objHandleHeight = objHandle.offsetHeight;
	objScrollbar_top = document.getElementById('div_scrollBar').offsetTop;
	document.getElementById('div_scrollHandle').onmousedown = startScroll;
	document.body.onmousemove = scroll;
	document.getElementById('div_scrollBar').onselectstart = cancelEvent;
	document.getElementById('div_scrollHandle').onmouseup = stopScroll;
	if(document.all) {
		document.body.onmouseup = stopScroll; 
	}else{
		document.documentElement.onmouseup = stopScroll;
	}
	document.getElementById('div_scrollDown').onmousedown = scrollButton;
	document.getElementById('div_scrollUp').onmousedown = scrollButton;
	document.getElementById('div_scrollDown').onmouseup = scrollButtonStop;
	document.getElementById('div_scrollUp').onmouseup = scrollButtonStop;
	document.getElementById('div_scrollUp').onselectstart = cancelEvent;
	document.getElementById('div_scrollDown').onselectstart = cancelEvent;
	document.getElementById('div_scrollBar').onmousedown = scrolldiv_MoveToInit;
}

/*	Change from the default color	*/
function scrolldiv_setColor(newColor)	{
	document.getElementById('div_scrollBar').style.borderColor = newColor;
	document.getElementById('div_scrollHandle').style.backgroundColor = newColor;
	document.getElementById('div_scrollUp').style.borderColor = newColor;
	document.getElementById('div_scrollDown').style.borderColor = newColor;
	document.getElementById('div_scrollUp').style.color = newColor;
	document.getElementById('div_scrollDown').style.color = newColor;
	document.getElementById('mainContainer').style.borderColor = newColor;
}

/*	Setting total width of parent Container	*/
function scrolldiv_setWidth(newWidth)	{
	document.getElementById('mainContainer').style.width = newWidth-30 + 'px';
}

/*	Setting total height of parent Container	*/
function scrolldiv_setHeight(newHeight)	{
	document.getElementById('mainContainer').style.height = newHeight + 'px';
	document.getElementById('div_slider').style.height = newHeight + 'px';
	document.getElementById('div_scrollBar').style.height = newHeight-40 + 'px';
}

/*	Setting new background color to the slider	*/
function setSliderBgColor(newColor)	{
	document.getElementById('div_scrollBar').style.backgroundColor = newColor;
	document.getElementById('div_scrollUp').style.backgroundColor = newColor;
	document.getElementById('div_scrollDown').style.backgroundColor = newColor;
}

/*	Setting new content background color	*/
function setContentBgColor(newColor)	{
	document.getElementById('mainContainer').style.backgroundColor = newColor;
}

/*	Setting scroll button speed	*/
function setScrollButtonSpeed(newSpeed)	{
	scrollSpeed = newSpeed;
}

/*	Setting interval of the scroll	*/
function setTimer(newInterval)	{
	scrollTimer = newInterval;
}


