// JavaScript Document
function initTicker()
{
	var tickerTape = "\"Without frugality none can be rich, and with it very few would be poor.\" Samuel Johnson.  \"Industry, perseverance, and frugality make fortune yield.\" Benjamin Franklin.   \"It is great wealth to a soul to live frugally with a contented mind.\" Lucretius.   \"I was brought up in an era when thrift was still considered a virtue.\" Paul Getty.   \"Frugality is founded on the principal that all riches have limits.\" Edmund Burke.   \"He who does not economise will have to agonise.\" Confusius.   \"Beware of little expenses; a small leak will sink a great ship.\" Benjamin Franklin.   \"By sowing frugality we reap liberty, a golden harvest.\" Agesilaus.   \"I believe that thrift is essential to well-ordered living.\" John D. Rockefeller."; // text to scroll
	var ticker = tickerTape.split(""); // split into individual letters
	var elm = $("ticker"); // identify conatiner for scrolling message
	var let = "";
	var intrval = 12;
	var tickerWidth = elm.offsetWidth;
	var containerWidth = "5900px";
	var start = "150px";
	var stopper = null;
	
	setUp();
	function setUp()
	{
		var newElm = document.createElement("div");
		elm.appendChild(newElm);
		newElm.appendChild(document.createTextNode(tickerTape));
		newElm.style.cssText = "position:absolute; display:inline-block; height:20px; left:50%; top:50%; margin-top:-8px; background-color:#ffffff; color:#666666; font-family:courier new, courier, monospace; font-size:13px; font-weight:600; text-align:left;";
			
		newElm.style.width = containerWidth;
		newElm.style.marginLeft = start;
		
		mover(newElm);
	}
	
	// loops through array-like "ticker" letter by letter
	for(i = 0; i < ticker.length; i++)
	{
		let = ticker[i];
		// what to do now ? do it here even ? need to think it through…
	}
	
	// div scroll
	function mover(el)
	{
		var moveMe = 0;
		var brake = parseInt(containerWidth.slice(0, -2)) * -1; 
		var timer = setInterval( function()
		{
			moveMe = parseInt(el.style.marginLeft.slice(0, -2)) - 1;
			el.style.marginLeft = moveMe + "px";
			elm.onclick = stopMe;
			if(el.offsetLeft <= brake + (tickerWidth / 2))
			{
				el.style.marginLeft = start;
				moveMe = 0;
				setUp();
			}
			if(stopper !== null)
			{
				clearInterval(timer);
			}
		}, intrval);
	}
	
	function stopMe(evt)
	{
		evt = (evt) ? evt : ((window.event) ? window.event : null);
		if(evt)
		{
			if(stopper === null)
			{
				stopper = "yes";
			}
		}
	}
	
	// garbage collection
	function killEl(lmnt)
	{
		alert(lmnt);
	}
	
	// element getter helper
	function $(l)
	{
		var el = document.getElementById(l);
		return el;
	}
}

window.onload = initTicker;
