/******************************************************************************
** Version 2.6
** Global JavaScript Functions   
******************************************************************************
******************************************************************************
** Copyright (c) 2004 : GTI Online Solutions Limited
**
** This software is provided under the terms of a License Agreement and
** may only be used and/or copied in accordance with the terms of such an
** agreement. Neither this software nor any copy thereof may be provided
** or otherwise made available to any other person. No title or ownership
** of this software is hereby TRansferred.
**
*******************************************************************************

Use 'writeTickerHTML()' to position the ticker. Requires 'DHTML.js'.

function returnStrCursor()
function startTicker()
function updateTicker()
function writeTickerHTML()
---------------------------------------------------------------------------*/

//---------------------------------------------------------------------------
// Returns a cursor character based on the current length of the headline.
function returnStrCursor() {
	if(intCurrentLength == strHeadline.length) return strCursor_None;
	else if((intCurrentLength % 2) == 1) return strCursor_One;
	else return strCursor_Two;
}
//---------------------------------------------------------------------------
/* Set some of the global variables that should not be manually altered, then
start the ticker. */
function startTicker() {
	/* Use 'document.all' if it is available, as the DOM is still
	inconsistently implemented across browsers, especially in its handling of
	whitespace and empty 'textNodes'. */
	if (gblnAll) objTicker = document.all["objTicker"];
	else if (gblnLayers) {
		objTicker = document.layers["objContainer"].document.layers["objTicker"];
	}
	else if (gblnDOMOnly) objTicker = document.getElementById("objTicker");
	intNumberOfHeadlines = arrstrHeadlines.length;
	intHeadlineCount = -1;
	intCurrentLength = 0;
	updateTicker();    // Start the first loop of the ticker
}
//---------------------------------------------------------------------------
// One loop of the ticker: adds to the ticker text, pauses, then calls itself.
function updateTicker() {
	// Declare function variables.
	var intCurrentHeadline;    // Index of current headline
	var intTimeout;            // Milliseconds until the next loop

	// Load next headline if applicable.
	if (intCurrentLength == 0) {
		intHeadlineCount++;

		/* Perform a hard reload after 'intReloadPageAfter' headlines. This is
		useful to avoid memory leaks and to get the latest headlines. */
		if (intHeadlineCount == intReloadPageAfter) {
			location.reload(true);
			return;
		}

		// Load headline and URL, using '%' to allow looping to start of array.
		intCurrentHeadline = intHeadlineCount % intNumberOfHeadlines;
		strHeadline        = arrstrHeadlines[intCurrentHeadline];
		strURL             = arrstrURLs[intCurrentHeadline];

		/* Netscape 4 will crash if a partly written headline is clicked on,
		so 'layers' are handled with clipping. Note that the entire '<a>' tag
		is written out here, because the text within it cannot be altered. */
		if (gblnLayers) {    // Write the new headline
			objTicker.clip.right = 0;    // Hide headline before replacing it
			objTicker.document.write('<a class="' + strCSSClass +
			                         '" href="' + strURL + '">' +
			                         strStartOfLink + strHeadline + '</a>');
			objTicker.document.close();

			/* Round up when calculating the increment to make sure that all
			of the headline will be displayed. */
			intLayerIncrement = Math.ceil(objTicker.document.width / strHeadline.length);
		}
		else objTicker.href = strURL;    // Change to the new URL
	}

	/* Set the ticker to the current ticker text. All concatenation is done
	here on the fly to avoid memory leaks. The 'substring' method is used
	here for the same reasons - it avoids persistent string concatenation.
	Again, 'document.all' is used if available. */
	if (gblnAll) {
		objTicker.innerText = strStartOfLink +
		                      strHeadline.substring(0,intCurrentLength) +
		                      returnStrCursor();
	}
	else if (gblnLayers) {
		/* Set the right edge of the clipped area to the smaller of the
		actual width of the headline and the calculated new width. */
		objTicker.clip.right = Math.min(objTicker.document.width,
		                               (intLayerIncrement * intCurrentLength));
	}
	else if (gblnDOMOnly) {
		objTicker.firstChild.nodeValue = strStartOfLink +
		                                 strHeadline.substring(0,intCurrentLength) +
		                                 returnStrCursor();
	}

	// Set the next ticker text length, and the time until the next loop.
	if(intCurrentLength != strHeadline.length) {
		intCurrentLength++;
		intTimeout = intCharacterTimeout;
	}
	else {
		intCurrentLength = 0;
		intTimeout = intHeadlineTimeout;
	}

	// Run next loop of the ticker.
	setTimeout("updateTicker()",intTimeout);
}
//---------------------------------------------------------------------------
// Writes out the HTML required for the ticker.
function writeTickerHTML() {
	if (gblnLayers) {
		/* Write a container for the ticker. Netscape 4 needs a system with an
		'<ilayer>' and a '<layer>' to properly display dynamic text inline. */
		document.write('<ilayer width="' + intILayerWidth + '" height="' +
		               intILayerHeight + '" name="objContainer">' +
		               '<layer name="objTicker"></layer></ilayer>');
	}
	else if (gblnDOM || gblnAll) {
		/* Some DOM implementations need the '&nbsp;' to create a child text
		node for the link; a space character may not work. Changing the
		'nodeValue' property of this child node changes the link's text. */
		document.write('<a id="objTicker" class="' + strCSSClass +
		               '" href="#">&nbsp;</a>');
	}
}
//---------------------------------------------------------------------------

// Declare global variables.

// These variables should not be manually altered.
var objTicker;               // Reference to the ticker's DHTML object
var intNumberOfHeadlines;    // Count of headlines to loop through.
var intHeadlineCount;        // Total number of headlines displayed so far
var intCurrentLength;        // Current amount of a headline to be displayed
var strHeadline;             // Current headline to be displayed
var strURL;                  // URL to page with full story
var intLayerIncrement;       // Step for increasing clipped '<layer>' width

// If needed, these values can be changed in pages that include this file.
var intILayerWidth      = 300;              // Maximum width of the '<ilayer>'
var intILayerHeight     = 15;               // Maximum height of the '<ilayer>'
var strCSSClass         = "clsHeadline";    // CSS class for the headlines
var strStartOfLink      = "";               // Fixed start of each link
var strCursor_One       = "_";              // Initial cursor
var strCursor_Two       = "-";              // Alternative cursor
var strCursor_None      = "";               // Used when headline is complete
var intCharacterTimeout = 50;               // Milliseconds between drawing characters
var intHeadlineTimeout  = 5000;             // Milliseconds between swapping headlines
var intReloadPageAfter  = 300;              // Number of headlines before page reloads

// Declare content arrays to be populated in all pages using this file.
var arrstrURLs = new Array();
var arrstrHeadlines = new Array();

/* If the browser supports a DHTML object, set the ticker to start
when the page loads. */
if (gblnDHTML) addOnloadFunction(startTicker);