var stories = new Array();
var links   = new Array();


stories[0] = "Dalton Firth Limited: Specialist Data Consultants";
links[0] = "/df.we/content/dfns/experience.html";

stories[1] = "We power Telegraph.co.uk school league tables";
links[1] = "/df.we/content/dfns/news-item_3.html";

stories[2] = "Rapid development of custom data applications";
links[2] = "/df.we/content/dfns/news-item_2.html";

stories[3] = "Budget Activity Tracker: Budget Bathmat!";
links[3] = "http://www.budget-bathmat.com/";

stories[4] = "Have you considered your Social Media strategy?";
links[4] = "/df.we/content/dfns/social-media.html";

stories[5] = "Project management, system design &amp; lifecycle improvement";
links[5] = "/df.we/content/dfns/lifecycle.html";




displayTicker();

function displayTicker()
{
    itemNum             = -1;
    charsDisplayed      = 0;
    charsDisplayedLeft  = 0;
    charsDisplayedRight = 0;

    if (document.getElementById) 
    {	
        theAnchorObject = document.getElementById("tickerElement");
	setTimeout("tickerGo()", 1000);
    }
    else 
    {
        return true;
    }
}

function tickerGo()
{
    var leadString = "";
    var charDelay  = 20;
    var storyDelay = 5000;
    var nextDelay;  
    
    if(charsDisplayed == 0)
    {
    	itemNum++;
    	itemNum              = itemNum % stories.length;
    	theStorySummary      = stories[itemNum].replace(/&quot;/g,'"');		
    	theTargetLink        = links[itemNum];
    	theAnchorObject.href = theTargetLink;
    	thePrefix 	     = "<span class=\"leadString\">" + leadString + "</span>";
    }
    
    theAnchorObject.innerHTML = thePrefix + 
        theStorySummary.substring(0,charsDisplayedLeft) + 
        getTypeEffectChar(charsDisplayed) + 
        theStorySummary.substring(theStorySummary.length - charsDisplayedRight, 
                                  theStorySummary.length ) + "&nbsp;";
    
    if(charsDisplayed < theStorySummary.length)
    {
        // Left hand side gets up to half of the characters	       
        if (charsDisplayedLeft < theStorySummary.length/2) 
        {	    
            charsDisplayedLeft++;
            charsDisplayed++;
        }
    
        // Right hand side gets up to half of the characters minus 1 - so 
        // in the event of an odd number of charaters, right hand side shows
        // the odd character, not both	       
        if (charsDisplayedRight < (theStorySummary.length-1)/2) 
        {
            charsDisplayedRight++;
            charsDisplayed++;
        }
        nextDelay = charDelay;
    }
    else
    {
        // Reset values
    	charsDisplayed = 0;
        charsDisplayedLeft=0;
        charsDisplayedRight=0;
    	nextDelay = storyDelay;
    }
    
    setTimeout("tickerGo()", nextDelay);
}

function getTypeEffectChar(dispChars)
{
    if(charsDisplayed == theStorySummary.length)
    {
        return "";
    }
    else
    {
        return "  ";
    }
}

