
var moving=false
var leftStopOffset=0
var rightStopOffset=0

function initCSH(){
scrollContainer=document.getElementById("scroll_container")
theScroller=document.getElementById("scroller")

scrollerElements=theScroller.getElementsByTagName("div")
scrollerWidth=0
for(var i=0;i<scrollerElements.length;i++){
scrollerWidth+=scrollerElements[i].offsetWidth

if(document.body.currentStyle){
scrollerWidth+=parseInt(scrollerElements[i].currentStyle.marginLeft)
scrollerWidth+=parseInt(scrollerElements[i].currentStyle.marginRight)
}
else{
scrollerWidth+=parseInt(document.defaultView.getComputedStyle(scrollerElements[i], '').getPropertyValue("margin-left"))
scrollerWidth+=parseInt(document.defaultView.getComputedStyle(scrollerElements[i], '').getPropertyValue("margin-right"))
}

}

theScroller.style.width=scrollerWidth

sliderContainer=document.getElementById("slider_container")
theSlider = document.getElementById("slider")

scrollAmount=theScroller.offsetWidth-scrollContainer.offsetWidth
slideAmount=sliderContainer.offsetWidth-theSlider.offsetWidth-leftStopOffset-rightStopOffset

step=scrollAmount/slideAmount

theSlider.style.left=leftStopOffset

}

function prepCSHSlider() {
moving=true
posX = tempX - theSlider.offsetLeft
}

function moveCSHSlider(e) {
tempX = (!e ? event.clientX : e.clientX)

if(moving == true){
theSlider.style.left = (tempX - posX) + "px"

if(theSlider.offsetLeft<leftStopOffset){
theSlider.style.left=leftStopOffset
}

if(theSlider.offsetLeft+theSlider.offsetWidth>sliderContainer.offsetWidth-rightStopOffset){
theSlider.style.left=sliderContainer.offsetWidth-theSlider.offsetWidth-rightStopOffset
}

scrollerPos=(theSlider.offsetLeft-leftStopOffset)*step
theScroller.style.left= -scrollerPos

}

}

document.onmousemove = moveCSHSlider
document.onmouseup=new Function("moving=false")

