/**
 * File: anp_scroll_text.js
 * 	Contains a function for creating scrolling text bars.
 *
 * Usage:
 * 	> <div id="bar"></div>
 * 	>
 *  > <script type="text/javascript">
 *  >   ANPScroll('bar', '"We must secure the existence of our people and a future for White children." -The 14 Words', 88);
 *  > </script>
 *
 * Copyright:
 * 	(C) 2011 American Nazi Party
 */

/**
 * Function: ANPScroll
 * 	Creates a scrolling text bar.
 *
 * Parameters:
 * 	id - The html id for the object in which you wish to place the scrolling text bar.
 *  text - The text you want scrolled. This can contain html.
 *  speed - The speed you want the text to scroll. Smaller values for faster scrolling. If no value is given the default value is 100.
 */
function ANPScroll(id, text, speed) {
	if(speed == null)
		speed = 100;
	var cwidth = document.getElementById(id).offsetWidth;
	document.getElementById(id).style.overflow = "hidden";
	document.getElementById(id).innerHTML = '<div id="' + id + '_canvas" style="position:relative;overflow:hidden;float:left;white-space:nowrap;left:' + cwidth + 'px">' + text + '</div>';
	var swidth = document.getElementById(id + '_canvas').offsetWidth;
	__ANPScrollem(id, cwidth, speed);
}

/**
 * Function: __ANPScrollem
 * 	This function is used internaly by ANPScroll. DO NOT USE THIS FUNCTION IN YOUR CODE!
 */
function __ANPScrollem(id, left, speed) {
	var dx = 4;
	var base = document.getElementById(id);
	var canvas = document.getElementById(id + '_canvas');

	left -= dx;

	canvas.style.left = left + 'px';
	if(left < -canvas.offsetWidth)
		left = base.offsetWidth;
	var timer = setTimeout("__ANPScrollem('"+id+"',"+left+","+speed+")", speed);

	function speedTime() {
		__ANPScrollem(id, left, speed);
	}
	function slowTime() {
		clearTimeout(timer);
	}

	base.onmouseover = slowTime;
	base.onmouseout = speedTime;
}

