	function filter(arr, f) {
		var out = new Array();
       	for(var i = 0; i<arr.length; ++i)
           	if(f(arr[i]))
               	out.push(arr[i]);
       	return out;
   	}

   	function map(arr, f) {
	   	var out = new Array();
	   	for(var i = 0; i<arr.length; ++i) {
	   		out.push(f(arr[i]));
	   	}
		return out;
   	}


	function switchVisibility() {
		for(var i=0; i<arguments.length; ++i) {
			if(arguments[i].style.visibility == "hidden") {
				arguments[i].style.visibility = "";
			} else {
				arguments[i].style.visibility = "hidden";
			}
		}
	}

	function getOuterArrows(node) {
		do {
			node = node.nextSibling;
		}while(node.nodeName.toLowerCase() != 'div');
		return node.getElementsByTagName('A');
	}

	function getDivScroller(div, direction, scroll_size) {
		if(direction != "right" && direction != "left")
			throw "ArgumentError: scrolling direction should be \"right\" or \"left\"";
		scroll_size = Math.abs(parseInt(scroll_size));

		if(direction == "right") {
			return function () {
				// Check if there is a product left to scroll to
				if(div.scrollLeft + 4*scroll_size <= div.scrollWidth) {
					div.scrollLeft += scroll_size;
					return true;
				} else {
					return false;
				}
			}
		} else {
			return function() {
				// Check if we are at the start of the thingie
				if(div.scrollLeft - scroll_size >= 0) {
					div.scrollLeft -= scroll_size;
					return true;
				} else {
					return false;
				}
			}
		}

	}

	function doScrollableGifts() {
		var scrollables = filter(document.getElementsByTagName('DIV'), function (node) {
			return node.className.match(/horiscrollable/);
		});
		map(scrollables, function (node) {
			var inners = node.getElementsByTagName('DIV');
			var outers = getOuterArrows(node);
			var left_arrow = inners[0];
			var right_arrow = inners[1];
			var scrollable_content = inners[2];
			var outer_left_arrow = outers[0];
			var outer_right_arrow = outers[1];

			switchVisibility(left_arrow, outer_left_arrow);
			if(scrollable_content.scrollWidth == scrollable_content.clientWidth) {
				// Content isn't scrollable
				switchVisibility(right_arrow, outer_right_arrow);
				return null;
			}

			// Content is scrollable (spans out of the box)
			var scroll_size = parseInt(scrollable_content.clientWidth/4);
			var scroll_content_right = getDivScroller(scrollable_content, "right", scroll_size);
			var scroll_content_left = getDivScroller(scrollable_content, "left", scroll_size);

			// setup scrolling functions
			right_arrow.onclick = outer_right_arrow.onclick = function () {
				scroll_content_right();
				// Whatever state they're currently in, arrows to the left can be used
				left_arrow.style.visibility = outer_left_arrow.style.visibility = "";
				// Check if there is still room on the right
				if(scrollable_content.scrollLeft + 4*scroll_size >= scrollable_content.scrollWidth) {
					// If we can't scroll to the right anymore, remove the arrows
					right_arrow.style.visibility = outer_right_arrow.style.visibility = "hidden";
				}
				return false;
			}
			left_arrow.onclick = outer_left_arrow.onclick = function () {
				scroll_content_left()
				right_arrow.style.visibility = outer_right_arrow.style.visibility = "";
				if(scrollable_content.scrollLeft - scroll_size < 0) {
					left_arrow.style.visibility = outer_left_arrow.style.visibility = "hidden";
				}
				return false;
			}
			return null;
		});
	}