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("Kate and Kizingo added to the World Class Equine Pathway"),
	new headline("Kizingo wins Pulborough Horse Trials Novice Section!!!"),
	new headline("IT'S AERO second at Berkshire College PN Horse Trials"),
	new headline("CASSUS jumps double clear at South of England CIC**"),
	new headline("KIZINGO seventh at South of England Novice Horse Trials"),
	new headline("ATTAGIRL DELPHY third at Firle Place Novice Horse Trials"),
	new headline("MAESTRO Z tenth at Pontispool IN Horse Trials"),
	new headline("Wyoming II 9th Stratford Hill Novice"),
	new headline("Big Time 9th debut Intermediate at Eridge"),
	new headline("It's Aero 3rd Stonar PN"),
	new headline("It's Aero 9th Tweseldown PN"),
	new headline("Stormhill Russian gives birth to Russ, a bay colt, at 12.04 on 12 May"),
	new headline("Big Time and Kate claim fourth at Nurstead Intermediate Novice"),
	new headline("Maestro Z fourth at South of England Novice"),
	new headline("KIZINGO 3RD AND 8TH AT OPENING EVENTS OF SEASON, TWESELDOWN AND SOMERLEY"),
	new headline("MAESTRO Z 6TH NOVICE CT AT WINTER DRESSAGE CHAMP AT HARTPURY"),
	new headline("ITS AERO AND BIGTIME 5TH AND 6TH MUNSTEAD HORSE TRIALS"),	
	new headline("CASSUS WINS BSJA AT ROYAL LEISURE"),
	new headline("It's Aero 5th and Big Time 6th at Munstead BE Open Intro"),
	new headline("Kizingo 3rd at Tweseldown BE Novice"),
	new headline("Daisy Crazy wins British Dressage Medium Qualifier"),
	new headline("Attagirl Delpy, Cassus, Kizingo and Daisy Crazy qualify for JAS National Finals"),
	new headline("It's Aero and Kizingo win British Dressage at Oldencraig EC"),
	new headline("Maestro Z wins BD Novice Combined Training to qualify for Dressage Nationals"),
	new headline("Zeta Maria 9th in Pre-Novice at BCA Horse Trials"),
	new headline("Wenceslas wins debut Dressage outing with Joseph second in Class"),
	new headline("Maestro Z wins Milton Keynes PN, with Dayrells Jet 9th"),
	new headline("Kizingo gains first Novice Point jumpig double clear at Knaptoft"),
	new headline("Zeta Maria fifth at Little Mattingley Intro"),
	new headline("Maestro Z ninth at Little Mattingley Pre Novice Plus"),	
	new headline("Two exciting new horses join the team - Kizingo and Symetric"),
	new headline("Maestro Z fourth at Tweseldown Pre Novice Plus"),
	new headline("Reigning BE Intermediate Champion Daisy Crazy joins the team"),
	new headline("Mianna 6th at Munstead OPN"),
	new headline("Attagirl Delphy 6th at Tweseldown OPN"),
	new headline("Dayrells Jet wins both first two debut dressage competition"),
	new headline("Cassus and Mianna qualify for BEs JAS national finals"),
	new headline("Russian qualifies for Dressage Regionals on average score of 70%")
	);