var strokeDelay = 35;
var linefeedDelay = 3000;
var separator="&nbsp;";
var article = new Array();

function updateCursor(nCharsTyped, charsInThisArticle) 
{
    if (nCharsTyped == charsInThisArticle)
        return "";
        
    if (nCharsTyped != charsInThisArticle)
        return "_";
        
    return "";
}

var articleItems = new Array(1);

function updateArticleItems(theArticle)
{
 articleItems[0] = new Array(theArticle.headline_text + "...");
}

var itemEndings = new Array("_headline");

function scroller(elementId, separator, strokeDelay, linefeedDelay)
{
    this.iCurrentArticle = -1;
    this.iCurrentItem = -1;
    this.elementId = elementId;
    this.strokeDelay = strokeDelay;
    this.linefeedDelay = linefeedDelay;
    this.nCharsTyped = 0;
    this.separator = separator;

    this.createticker();
    this.activeTag = document.getElementById(this.elementId+itemEndings[0]);//the link
	this.theContent = "test";
}

scroller.prototype.createticker = function()
{
    document.write("<div id='" + this.elementId + itemEndings[0] + "'></div>");
}

scroller.prototype.nextEntry = function()
{
    this.iCurrentItem = (this.iCurrentItem + 1) % 1;
    
    if (this.iCurrentItem == 0) 
    {
		this.iCurrentArticle = (this.iCurrentArticle + 1) % article.length;
        updateArticleItems(article[this.iCurrentArticle]);
       
		document.getElementById(this.elementId+itemEndings[0]).innerHTML = "";
    }
}

scroller.prototype.nextItem = function()
{
    this.nextEntry();
	this.theContent = articleItems[this.iCurrentItem][0];

    this.activeTag = document.getElementById(this.elementId+itemEndings[this.iCurrentItem]);

}

scroller.prototype.lastItem = function()
{
   var lastItem = 0;
   return lastItem;
}

scroller.prototype.run = function()
{
    if (this.nCharsTyped == 0)
    {
        this.nextItem();
    }
    
    this.activeTag.innerHTML = this.theContent.substring(0, this.nCharsTyped);
    this.activeTag.innerHTML += updateCursor(this.nCharsTyped, this.theContent.length);
	
    var nextDelay = this.strokeDelay;
    if(this.nCharsTyped != this.theContent.length) {
        this.nCharsTyped++;
    }
    else {
        this.nCharsTyped = 0;
        if (this.iCurrentItem == this.lastItem())
            nextDelay = this.linefeedDelay;
    }
    
    setTimeout(this.elementId+".run()", nextDelay);
}

function createscroller() 
{

	if (article == null)
    article = new Array();
		
    if (article.length == 0)
    {
document.writeln("<center>ERROR</center>");
    }
	
news_scroller = new scroller("news_scroller", separator, strokeDelay, linefeedDelay);
    
      news_scroller.run();
     

}

function headline(headline_text) 
{
 this.headline_text = headline_text
}

	article = new Array
	
	(
	new headline("30th Aug: Merlot's Magic 4th and Borough Pennyz 5th in the Intermediate at Highclere "),
	new headline("12th Aug: More Int success for Merlots Magic, 9th at Aston Le Walls!"),
	new headline("7th Aug: Fantastic 6th for Pennyz at British Novice Championships"),
	new headline("1st Aug: Merlots Magic keeps getting better, OI 3rd at Wilton"),
	new headline("12th Jul: Pennyz grabs a fine Intermediate 3rd at Tweseldown(2)"),
	new headline("27th Jun: Novice 7th for Billybob at Milton Keynes"),
	new headline("20th Jun: Yard Open Day roaring success, great weather, great company"),
	new headline("18th Jun: Novice 2nd for Merlots Magic at Longleat International"),
	new headline("13th Jun: Fantastic Novice 2nd for Merlots Magic at Great Tew"),
	new headline("1st Jun: Bourne Supremacy 3rd & Wanino 4th at Aston UA Pre-Novice"),
	new headline("21st May: Billybob finishes 7th at Mattingley Novice on score of 36.7"),
	new headline("5th May: Great 4th for Borough Pennyz on score of 37.9 at Morton Morrell")
	);