function AlternatingLink(href, text, title)
{
    this.Href = href;
    this.Text = text;
    this.Title = title;
}

function RotatingLinkDisplay(interval, theLink)
{
    this.Interval = interval;
    this.Link = theLink;
    this.LinkItems = new Array();
    this.CurrentLinkIndex = 0;
}

RotatingLinkDisplay.prototype.AddLink = function(linkToAdd)
{
    this.LinkItems.push(linkToAdd);
}

RotatingLinkDisplay.prototype.InitialiseLink = function()
{
    if(this.LinkItems.length > 0)
    {
        this.SetLink(this.LinkItems[0]);
    }
}

RotatingLinkDisplay.prototype.SetLink = function(theLink)
{    
    //switch the href, text and title
    this.Link.href = theLink.Href;
    this.Link.title = theLink.Title;
    
    //first remove text to add new text
    while(this.Link.childNodes.length > 0)
    {
        this.Link.removeChild(this.Link.childNodes[0]);
    }
    
    //switch the text
    this.Link.appendChild(document.createTextNode(theLink.Text));
}

RotatingLinkDisplay.prototype.RotateLink = function()
{
    if(this.LinkItems.length > 0)
    {        
        this.SetLink(this.LinkItems[this.CurrentLinkIndex]);
        this.CurrentLinkIndex++;
        
        if(this.CurrentLinkIndex >= this.LinkItems.length)
        {
            //reset when end is reached
            this.CurrentLinkIndex = 0;
        }
    }
}

var g_AlternatingRotator;

function CreateRotatingLink(interval)
{
    var alternatingLink = document.getElementById("alternatingLink");    
    g_AlternatingRotator = new RotatingLinkDisplay(interval, alternatingLink);
}

function BeginRotation()
{
    window.setInterval("DoRotationAlternating();", g_AlternatingRotator.Interval);
}

function DoRotationAlternating()
{
    g_AlternatingRotator.RotateLink();
}
