  /************************/
 /*****   SCROLLER   *****/
/************************/

	if (typeof $ != 'function') function $(d){return document.getElementById(d);}

	// Scroller function!
	function yo_scroll(id, backwards) {

		if (tsrScroll_on) return;
		tsrScroll_on = 1;

		// Calculate element width to scroll (get first element that has a width)
		var container = $(id);
		if (!container) return;
		for (var i = 0; i < container.childNodes.length; i++) {
			el = container.childNodes[i];
			if (el.nodeType == 1) break;
		}
		var item_width = el.scrollWidth;   // Width of one element, in pixel

		var startPosition = 0;
		var targetPosition = -item_width;
		
		if (backwards) {
			moveElementStack(id, 1);			
			targetPosition = 0;
			var startPosition = -item_width;
		}
		
		container.style.marginLeft = startPosition + 'px';
		
		tsrScroll_anim(container, startPosition, targetPosition, function(){
			container.style.marginLeft = 0;			
			if (!backwards) moveElementStack(id);			
			tsrScroll_on = 0;
		});

		return;
	}
	tsrScroll_on = 0;

	function tsrScroll_anim(obj, startPosition, targetPosition, callBack) {	
		var step = (startPosition - targetPosition) / 8;			
		step = -((step > 0) ? Math.ceil(step) : Math.floor(step));
				
		if (!step) {
			obj.style.marginLeft = targetPosition+'px';
			if (typeof callBack == 'function') callBack();
			return;
		}

		// nav.style.marginBottom = '-'+start+'px';
		obj.style.marginLeft = startPosition+'px';

		window.setTimeout(function(){
			tsrScroll_anim(obj, startPosition+step, targetPosition, callBack);
		},50);
	}


	// Take the first DOM child element and put it at the end, or the other way around if second argument is given
	function moveElementStack(id, backwards) {

		// remove all children from element
		var element = $(id);

		if (!backwards) {
			for (var i = 0; i < element.childNodes.length; i++) {
				el = element.childNodes[i];
				if (el.nodeType == 1) {
					element.removeChild(el);
					element.appendChild(el);
					break;
				}
			}
		}
		else {
			for (var i = element.childNodes.length-1; i > 0; i--) {
				el = element.childNodes[i];
				if (el.nodeType == 1) {
					element.removeChild(el);
					element.insertBefore(el, element.firstChild);
					break;
				}
			}
		}
	}
	
	window.setInterval(function(){if ($('sponsors-top-content'))yo_scroll('sponsors-top-content');},2500);
