// JavaScript Document
// These are the headlines that will be displayed
var items = new Array();
items[0] = "EMMA: Qualifikation zur EURO 2008";
items[1] = "YNWA: Das EDFF-Magazin";


// These are the URLs for the above headlines
var urls = new Array();
urls[0] = "?p=bettundfans";
urls[1] = "?p=ynwa";


// Settings
var headlinePos = 0; // maintains the current headline position
var delay = 4000; // delay in milliseconds between headlines

// The HTML that comes before and after the headline
var precedingHTML = '<div id="newsTicker"><span id="label">EDFF-Ticker</span><span id="headline">';
var followingHTML = '</span></div>';


if (document.getElementById)
{

	/*
     * This function assembles and returns the clickable link.
     *
     * @param position - the index of the urls and texts array
     *
     * @global items
     * @global urls
	 */
	function makeHyperlink(position)
	{
		var hyperlink = "<a href=\"" + urls[position] + "\">" + items[position] + "</a>";
		return hyperlink;
	}
	
	/*
     * This function updates the innerHTML with the next headline and resets the
     * headlinePos counter when it has reached the max value.
	 *
	 * @param position - the headline position
	 *
	 * @global urls
	 * @global headlinePos
	 */
	function replaceHTML(position)
	{
		document.getElementById("headline").innerHTML = makeHyperlink(position);
		if(position == (urls.length - 1)) {
			headlinePos = 0;
		} else {
			headlinePos++;
		}
	}

	/*
     * This function controls the main flow. It immediately prints out the first
     * headline, and then the subsequent headlines at a set interval.
	 *
	 * @global headlinePos
	 * @global delay
	 * @global precedingHTML
	 * @global followingHTML
	 */
	function writeHeadlines()
	{
		document.writeln(precedingHTML + makeHyperlink(headlinePos) + followingHTML);
		headlinePos++;
		setInterval('replaceHTML(headlinePos)', delay);
	}
	
}  
