function createScrollUrl(currentHref)
{
  var scrollPositionPosition = currentHref.indexOf("scrollPosition");
  
  if (scrollPositionPosition == -1) {
    return appendScroll(currentHref);
  }
  else {
    return appendScroll(currentHref.substr(0, scrollPositionPosition - 1));
  }
}

function appendScroll(url)
{
    var scrollPosition = getScrollPosition();

    if (scrollPosition != null)
    {
        return url + '&scrollPosition=' + getScrollPosition();
    }
    else
    {
        return url;
    }
}

function getScrollPosition()
{
    var scrollDiv = document.getElementById('scrolldiv');
    
    if (scrollDiv != null) {
        return scrollDiv.scrollLeft;
    }
    else
    {
        return null;
    }
}
var scrollRepeat;
var elementId = 'scrolldiv';

var cssWidth = 483;
var scrollAmount = (cssWidth / 7) + 1;
var timerAmount = 60;

function getScrollDiv() {
  return document.getElementById(elementId);
}

function scroller(direction)
{
    if (direction == 'left')
    {
        scroll(-scrollAmount);
        scrollRepeat = setInterval("scroll(-scrollAmount)", timerAmount);
    }
    else
    {
        scroll(scrollAmount);
        scrollRepeat = setInterval("scroll(scrollAmount)", timerAmount);
    }
}

function scroll(amount)
{
    var theDiv = getScrollDiv();

    if (theDiv)
    {
        theDiv.scrollLeft += amount;
    }
    else
    {
        alert("'" + elementId + "' does not exist.")
    }

    updateControllers();
}

function updateControllers()
{
    var theDiv = getScrollDiv();
    var backcontroller = document.getElementById("backcontroller");
    var nextcontroller = document.getElementById("nextcontroller");
    if (theDiv.scrollLeft == 0)
    {
        backcontroller.className = "controller backdisabled";
    }
    else
    {
        backcontroller.className = "controller back";
    }

    // dunno why but scrollWidth returns an amount that appears to
    // be the actual width plus the width set for theDiv in css.
    //Decresed the width of scrolldiv by 1 pixel and added a pixel to
    //stop the scroller from moving the images on getting to the last image.
    if (theDiv.scrollLeft == (theDiv.scrollWidth + 1) - cssWidth)
    {
        nextcontroller.className = "controller nextdisabled";
    }
    else
    {
        nextcontroller.className = "controller next";
    }
}

function stopScrolling()
{
    var theDiv = getScrollDiv();
    clearInterval(scrollRepeat);
}