// Ticker startup
function startTicker()
{
	// Define run time values
	theCurrentStory     = -1;
	theCurrentLength    = 0;
    theItemCount = theNewsTitles.length;

	// Locate base objects
	if (document.getElementById) 
    {	
        theTickerSpan = document.getElementById("tickerSpan");
        runTheTicker();   	
	}
	else 
    {
        document.write("<style>.ticki{display:none;}</style>");
        return true;
	}
}

// Ticker main run loop
function runTheTicker()
{
	var myTimeout;  
	// Go for the next story data block
	if(theCurrentLength == 0)
	{
		theCurrentStory++;
		theCurrentStory     = theCurrentStory % theItemCount;
		theNewsTitle     = theNewsTitles[theCurrentStory].replace(/&quot;/g,'"');		
		theNewsId           = theNewsIds[theCurrentStory];
        if (theNewsId == "") 
        {
            theTickerObjectToUse  = theTickerSpan;
        }
        else
        {
            theTickerSpan.innerHTML = "<a id =\"tickerAnchor\" href=\"/" + siteLang + "/html/news/" + theNewsId + "\" target=\"_top\" onclick=\"return loadTorrentTable('news.x','id=" + theNewsId + "')\" class=\"tickl\"></a>";
            theTickerObjectToUse = document.getElementById("tickerAnchor");
        }
	}

    // Stuff the current ticker text into the anchor (skip html code)
    if (theNewsTitle.charAt(theCurrentLength) == '<') 
    {
        while (theNewsTitle.charAt(theCurrentLength) != '>' && theCurrentLength < theNewsTitle.length) 
            theCurrentLength++;
    }

    theTickerObjectToUse.innerHTML = theNewsTitle.substring(0,theCurrentLength) + whatWidget();

	// Modify the length for the substring and define the timer
	if(theCurrentLength != theNewsTitle.length)
	{
		theCurrentLength++;
		myTimeout = theCharacterTimeout;
	}
	else
	{
		theCurrentLength = 0;
		myTimeout = theStoryTimeout;
	}
	// Call up the next cycle of the ticker
	setTimeout("runTheTicker()", myTimeout);
}

// Widget generator
function whatWidget()
{
	if(theCurrentLength == theNewsTitle.length)
	{
		return theWidgetNone;
	}

	if((theCurrentLength % 2) == 1)
	{
		return theWidgetOne;
	}
	else
	{
		return theWidgetTwo;
	}
}

var theCharacterTimeout = 50;
var theStoryTimeout     = 5000;
var theWidgetOne        = "_";
var theWidgetTwo        = "-";
var theWidgetNone       = "";

var theNewsTitles = new Array();
var theNewsIds = new Array();

