
//---------------------------------+
//  CARPE  S l i d e r        1.0  |
//  2004 - 06 - 25                 |
//  By Tom Hermansson Snickars     |
//  Copyright CARPE Design 2003 -  |
//---------------------------------+

mouseover    = true
sliderScale  = 0
valueCount   = 0
fromValue    = 0
pixelLength     = 0
displayDecimals = 0

function moveSlider()
{
	if (mouseover && (event.button == 1))
	{
		x = pxLeft + event.clientX - xCoord
		y = pxTop + event.clientY - yCoord
		if (x > xMax) x = xMax
		if (x < xMin) x = xMin
		if (y > yMax) y = yMax
		if (y < yMin) y = yMin
		sliderObject.style.pixelLeft = x
		sliderObject.style.pixelTop = y
		sliderValue = x + y
		sliderPosition = (pixelLength / valueCount) * 
			Math.round(valueCount * sliderValue / pixelLength)
		v = Math.round((sliderPosition * sliderScale + fromValue) *
			Math.pow(10, displayDecimals)) / Math.pow(10, displayDecimals)
		displayObject.value = v
		return false
	}
}

function slide(sliderID, direction, length, from, to, count, decimals, displayID)
{
	pixelLength = length
	sliderScale = (to - from) / length
	if (direction == 'horizontal') {
		fromValue = from
		xMin = 0
		xMax = length
		yMin = 0
		yMax = 0
	}
	if (direction == 'vertical') {
		fromValue = to
		xMin = 0
		xMax = 0
		yMin = 0
		yMax = length
		sliderScale = -sliderScale
	}
	valueCount = count - 1
	displayDecimals = decimals
	sliderObject = document.getElementById(sliderID)
	displayObject = document.getElementById(displayID)
	if (event.srcElement.id == sliderID) {
		mouseover = true
		pxLeft = sliderObject.style.pixelLeft
		pxTop = sliderObject.style.pixelTop
		xCoord = event.clientX
		yCoord = event.clientY
		document.onmousemove = moveSlider
	}
}
function mouseup()
{
	mouseover = false
}
document.onmouseup = mouseup
