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("January: Pennyz & Rock Model back in work aiming for early season 3* run"),
	new headline("December: Young horses Eclipse & Borough Free Flight make great winter progress"),
	new headline("November: Welton Sophisticat back into work after 2011 tooth extraction")
	/* new headline("23rd Oct: Rock Model 3rd in the Cameri CIC*** with a clear xc in the time!"),
	new headline("17th Oct: River Vally Robert 2nd on 23.0 and DC in BE100o at Broadway"),
	new headline("17th Oct: Frankfort Glen wins in first BE100 & Relaxed wins again at Broadway!"),
	new headline("2nd Oct: Heartbreaker gains first Novice rosette with 9th place at Dauntsey"),	
	new headline("2nd Oct: Relaxed wins Dauntsey BE100 on first outing after a last minute entry!"),
	new headline("2nd Oct: Heartbreaker gains first Novice rosette with 9th place at Dauntsey"),
	new headline("24th Sept: River Valley Robert & Frankfort Glen 1st/2nd BE90o at Moreton Morrell"),
	new headline("24th Sept: Prince Son of Karniz Wins BE100 at Moreton Morrell on a 22!"),
	new headline("18th Sept: Rock Model wins in 1st run after 2yrs at Gatcombe with OInt DC!"),
	new headline("11th Sept: Borough Pennyz 6th with a clear in the time xc at Blenheim CCI***!!"),
	new headline("6th Sept: Heartbreaker finishes 5th with double clear Goring BE100"),
	new headline("6th Sept: Rock Model now ready to return to eventing again!"),
	new headline("7th Aug: Borough Pennyz 3rd with a thrilling double clear at Gatcombe Int Champs"),
	new headline("2nd Aug: Heartbreaker's first BE100 placing with a bold xc clear at Homme House"),
	new headline("Vittoria thanks horsejumpsforsale.co.uk for great svce & best practical show jumps"),
	new headline("23rd July: Pennyz 4th place in a large class of 8/9 y.o. Adv at Aston le Walls"),
	new headline("20th July: Horses for sale, see 'Horses' page"),
	new headline("19th July: A clear for Regal Rascal in a challenging BE100 at Dauntsey"),
	new headline("14th July: Patch and Murphy go clear in their first event, a BE90 at Upton"),
	new headline("10th July: Merlot's Magic DC and finishes 16th at Barbury Castle CIC3*"),
	new headline("6th July: 7th for Borough Pennyz at the London 2012 Test Event in Greenwich"),
	new headline("16th June: Rock Model starts jumping again after 2 years!"),
	new headline("4th June: Top10 CIC3* finishes for Pennyz(7th) and Merlot's Magic(8th) at Bramham"),
	new headline("23rd May: Borough Pennyz wins Brigstock Adv Int! Merlot's Magic 4th in CIC2*!"),
	new headline("14th May: New ride Welton Sophisticat double clear for 5th in ON at Aston le Walls!"),
	new headline("4th May: BE90o 2nd with great double clear for Connaght Schwepps at Moreton Morrell"),
	new headline("30th April: Merlot's Magic clear xc in his first Advanced at Withington Manor"),
	new headline("22nd April: Connaght Schwepps double clear (24 dressage) in his 1st Intro at Broadway!"),
	new headline("20th April: Borough Pennyz double clear and 4th in first Advanced at Burnham Market!"),
	new headline("3rd April: George wins Goring Heath BE100 today on 25.3 dressage then a double clear"),
	new headline("10th March: Excellent Merlot's Magic 2nd (I) and Borough Pennyz 5th (OI) at Tweseldown"),
	new headline("10th Dec: Livery of all kinds available, particularly hunt livery in the winter.")
	new headline("25th Oct: Borough Pennyz ends season with fantastic 9th at World 7YO championships"),
	new headline("3rd Oct: Borough Pennyz wins the CCI2* 7YO championships at Osberton"),
	new headline("28th Sep: Alfiano Del Ferro wins BE100 at BCA(2) on dressage of 23.0!"),
	new headline("25th Sep: Merlots Magic posts a magic 2nd place with OI double clear at SOE(2)"),
	new headline("24th Sep: BE100 3rd for Alfiano Del Ferro at Morton Morrell(2)"),
	new headline("19th Sep: Borough Pennyz finishes a great 8th in the CCI at Gamcombe(2)"),
	new headline("15th Sep: Double clear and 3rd for Shanaclough Haity at Purston Manor(2)"),
	new headline("4th Sep: Shanaclough Haity and Freddies Star finish 2nd & 3rd in ON at Goring(2)")
	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")*/
	);
