// JavaScript Document
// These are the headlines that will be displayed
var items = new Array();
items[0] = "Nuremberg, looking for some guys from South Africa";
items[1] = "Gelsenkirchen, Doppelcouch im Wohnzimmer, 5 €";
items[2] = "Berlin, Vereinsraum, geeigent für Matratzenlager, am liebsten für Frauenfußballverein";
items[3] = "Leipzig, double sofabed, 10 min. walk to the stadium";
items[4] = "Kaiserslautern, will be glad, to have contact with some fans from all over the world";
items[5] = "Berlin, 400 m to lively Simon-Dach-Straße-area with many restaurants and bars, for free";
items[6] = "Berlin Zentrum, großer Raum für 4 Personen, 50 €";
items[7] = "Muenchen, kompl. möbl. DG-Wohnung, alles vorhanden, 60 €";
items[8] = "Dortmund, up to 4 persons offer for open-minded fans from all over the world, for free";
items[9] = "Hamburg, zwei Studenten, je 21, würden während der WM das Wohnzimmer freiräumen";
items[10] = "Fancamp-Portal: 17 Camps in Germany, for ex.: Hamburg, Dortmund, Southern Hub, ...";
items[11] = "Alle Angebote in unserer Datenbank EMMA ...";


// These are the URLs for the above headlines
var urls = new Array();
urls[0] = "?p=DB_searchshow&id=13";
urls[1] = "?p=DB_searchshow&id=25";
urls[2] = "?p=DB_searchshow&id=64";
urls[3] = "?p=DB_searchshow&id=107";
urls[4] = "?p=DB_searchshow&id=112";
urls[5] = "?p=DB_searchshow&id=114";
urls[6] = "?p=DB_searchshow&id=178";
urls[7] = "?p=DB_searchshow&id=188";
urls[8] = "?p=DB_searchshow&id=170";
urls[9] = "?p=DB_searchshow&id=175";
urls[10] = "?p=fancampportal";
urls[11] = "?p=bettundfans";


// 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);
	}
	
}  
