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("19th Oct: Working pupils wanted, call Tom on 07740 826863 for more details"),
	new headline("5th Sep: Liberal completes a great Burghley with a double clear to finish 34th"),
	new headline("21st Aug: Burnham Beeches - Just The Things grabs an 8th in the ON"),	
	new headline("11th Aug: Aston le Walls(2) - Adv 12th for Liberal & Nov 6th Pheonix"),
	new headline("16th Jul: Great Brightling weekend - Galient 2nd & Pheonix 4th (BE100), Nelson 5th (Nov)"),
	new headline("25th Jun: Watertight excellent DC nets Int 4th at Salperton"),
	new headline("29th May: Phoenix Park nets 5th in BE100 at Borde Hill"),
	new headline("26th May: Houghton International - Paddy finishes fantastic 6th in CIC 3*"),
	new headline("10th May: We're looking for staff from working pupils to full time, send us your CV"),
	new headline("6th May: Hambleden Horse Trials - Novice 4th for Analyst"),
	new headline("30th Apr: Nurstead Horse Trials - Dazzling Illusion double clear top six (BE100)"),
	new headline("26th Apr: Milton Keynes Horse Trials - Street Wise 2nd first time out (BE90o)"),
	new headline("26th Mar: Munstead Horse Trials - Dazzling Illusion 6th (BE100)"),
	new headline("25th Mar: Great Witchingham International - Paddy finishes 8th in Open Intermediate"),
	new headline("20th Mar: Aldon Horse Trials - Herbie Double Clear and 4th (Nov)"),
	new headline("12th Mar: Poplar Horse Trials - Kiwi 8th (Int)"),
	new headline("10th Mar: Tweseldown Horse Trials - Tom Double Clear and 9th (Nov)"),
	new headline("7th Mar: Isleham Horse Trial - Paddy 4th and Joey 9th (Nov)"),
	new headline("26th Jan: Phoenix 2nd, Herbie 4th (Nov) plus Paddy 1st, Cooly 5th and Denny 7th (Ele) at Oldencraig unaff Dressage"),
 	new headline("12th Feb: Top 10 for Cooly & Paddy at Oldencraig unaff dressage, Joey (5th), Herbie (4th) & Phoenix (6th)"),
 	new headline("22nd Jan: 3rd for Paddy (Nov) & 5th for Herbie (PN) at Felbridge Combine Training"),
	new headline("19th Jan: 1st for Cooly & 2nd for Mr TOM at Golden Cross Dressage"),
  	new headline("8th Jan: Felbridge Combine Training with Mr Tom (1st Nov), Herbie (4th PN), Paddy and Denny (4th Nov)"),
	new headline("5th Jan: Golden Cross Dressage with Jo (1st Ele), Pheonix Park, Paddy, Denny (4th Ele), Herbie (2nd Nov)")
	/*new headline("4th for Tom and 6th for Analyst in Novice at BCA(2)"),	
	new headline("Fantastic 3rd for Joey at SOE, 15th in CIC2* for Paddy too!"),	
	new headline("Paddy goes double clear to secure an Int 7th at Highclere"),	
	new headline("Herbie finishes best of six with a Novice 8th at Firle"),	
	new headline("Titania III keeps getting better with Novice 4th at Chilham"),	
	new headline("10th in 5YO for Dazzling Illusion at Smiths Lawn"),	
	new headline("Titania III returns to action with a 12th at Brightling"),	
	new headline("Two Int 7th places for Team Crisp at Tweseldown(2)"),	
	new headline("Analyst nets an excellent Novice 7th at Buckminster Park"),	
	new headline("Another BE100 5th for Nelson at Stratford Hills"),	
	new headline("Herbie nets Novice 4th & Nelson BE100 5th at Borde Hill"),	
	new headline("CCI1* double clears for both Paddy and Denny at Houghton"),	
	new headline("Novice 10th and 11th for Team Crisp at Mattingley"),	
	new headline("Another good weekend for Just The Thing, 5th at Hambleden"),	
	new headline("2nd for Just The Thing at Nurstead on score of 33.2"),	
	new headline("Int 5th & 7th for Team Crisp at Belton International"),	
	new headline("Intermediate 9th for Paddy at South of England"),	
	new headline("Double clear results in 7th for Herbie at Portman"),	
	new headline("Joey completes CIC2* at Burnham Market"),	
	new headline("Intermediate 12th for Joey at Great Witchingham")*/	
	);
