function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
function scroll(direction){
	// Use config to set necessary values
	// scrollID is the id of the element that acts as the frame of the scrolling content
	// scrollElements is the kind of element that will be moving
	// distance is how much we increment the margin by each iteration

	var config = {
		scrollID : 'products',
		scrollElements : 'dl',
		distance : 2
	}
	var scrollableDiv = document.getElementById(config.scrollID);
	var theMargin = scrollableDiv.style.marginLeft;
	if (theMargin != ""){
		theMargin = parseInt(theMargin);
	}
	if (scrollableDiv.movement){
		clearTimeout(scrollableDiv.movement);
	}
	var theElements = scrollableDiv.getElementsByTagName(config.scrollElements);
	var count = 0;
	for (i=0; i<theElements.length; i++){
		count = count + 1;
	}
	var theWidth = (count * 110) - 330;
	theWidth = theWidth * -1;
	if (direction == "left"){
		if (theMargin != 0){
			theMargin = theMargin + config.distance;
			scrollableDiv.style.marginLeft = theMargin + "px";
			scrollableDiv.movement = setTimeout("scroll(\"left\"), 3");
		}
	}
	if (direction == "right"){
		if (theMargin != theWidth){
			theMargin = theMargin - config.distance;
			scrollableDiv.style.marginLeft = theMargin + "px";
			scrollableDiv.movement = setTimeout("scroll(\"right\"), 3");
		}
	}
}
function clearScroll(){
	var scrollableDiv = document.getElementById("products");
	if (scrollableDiv.movement){
		clearTimeout(scrollableDiv.movement);
	}
}
function prepareScroll(){
	if(!document.getElementById) return false;
	
	// Set below based on the structure of the page
	// The leftID is the id of the link that will move the element to the left
	// The rightID is the id of the link that will move the element to the right

	var scrollLinks = {
		leftID : 'left',
		rightID : 'right'
	}
	
	var scrollLeft = document.getElementById(scrollLinks.leftID);
	var scrollRight = document.getElementById(scrollLinks.rightID);
	scrollLeft.onmouseover = function(){
		scroll("left");
	}
	scrollRight.onmouseover = function(){
		scroll("right");
	}
	scrollLeft.onmouseout = function(){
		clearScroll();
	}
	scrollRight.onmouseout = function(){
		clearScroll();
	}
}
addLoadEvent(prepareScroll);
