function HeadlineRotator(nameOfNewObjectVariable, urlArray, labelArray, popupArray, contentFormat, delayMs)
{
    var defaultFormat = '<a class="headlineRotatorLink" href="${Url}"><span class="headlineRotator">${Label}</span></a>';

    if ((typeof(nameOfNewObjectVariable) != "string") || (!nameOfNewObjectVariable))
    {
        alert("No name specified for the variable that will hold returned object");
        return(null);
    }
    this.objName = nameOfNewObjectVariable;

    this.headlineUrls = (typeof(urlArray) != "undefined") ? urlArray : new Array();
    this.headlineLabels = (typeof(labelArray) != "undefined") ? labelArray : new Array();
    this.headlinePopups = (typeof(popupArray) != "undefined") ? popupArray : new Array();
    this.contentFormat = (typeof(contentFormat) != "undefined") ? contentFormat : defaultFormat;
    this.delayMs = (typeof(delayMs) != "undefined") ? delayMs : 3000;

    this.HeadlineInit = _HeadlineInit;

    function _HeadlineInit()
    {
        var urls = this.headlineUrls;
        var labels = this.headlineLabels;
        var popups = this.headlinePopups;

        var randPos = Math.floor((Math.random() *  urls.length));
        setTimeout('_HeadlineRotate(' + randPos + ', ' + this.delayMs + ', "' + this.objName + '")', this.delayMs);
//        setOnLoadScript('_HeadlineRotate(' + randPos + ', ' + this.delayMs + ', "' + this.objName + '")');

        var initialContent = this.contentFormat;
        if (popups[randPos])
            initialContent = initialContent.replace(/href="\$\{Url\}"/g, 'href="${Url}" target="_blank"');
        initialContent = initialContent.replace(/\$\{Url\}/g, urls[randPos % urls.length]);
        initialContent = initialContent.replace(/\$\{Label\}/g, labels[randPos % urls.length]);

        return (initialContent);
    }
}

function _HeadlineRotate(index, delayMs, headlineRotatorObjName)
{
    if (typeof(index) == "undefined")
        index = 0;

    if (typeof(delayMs) == "undefined")
        delayMs = 3000;

    ++index;

    var hrObj = eval(headlineRotatorObjName);
    var urls   = hrObj.headlineUrls;
    var labels = hrObj.headlineLabels;

    var content = hrObj.contentFormat;
    content = content.replace(/\$\{Url\}/g, urls[index % urls.length]);
    content = content.replace(/\$\{Label\}/g, labels[index % urls.length]);

    // Locate the headline rotator div
    if (typeof(document.headlineRotatorDiv) == "object")
        var headlineRotatorDiv = document.headlineRotatorDiv;
    else if ((typeof(document.getElementById) == "function") && (typeof(document.getElementById("headlineRotatorDiv")) == "object"))
        var headlineRotatorDiv = document.getElementById("headlineRotatorDiv");
    else if ((typeof(document.all) == "object") && (typeof(document.all.headlineRotatorDiv) == "object"))
        var headlineRotatorDiv = document.all.headlineRotatorDiv;
    else
    {
        // Can't find headline rotator div, abort
        return;
    }

    // Switch headline
    if (typeof(headlineRotatorDiv.filters) == "object")
    {
        // Do a dissolve using a filter
        headlineRotatorDiv.style.filter = "blendTrans(duration=1)";
        headlineRotatorDiv.filters.blendTrans.Apply();
        headlineRotatorDiv.innerHTML = content;
        headlineRotatorDiv.filters.blendTrans.Play();
    }
    else if (typeof(headlineRotatorDiv.innerHTML) == "string")
    {
        // Do a "cut", replacing the old text with the new text
        headlineRotatorDiv.innerHTML = content;
    }
    else
    {
        // Do a nothing, and abort the headline rotation
        return;
    }

    // Shampoo, rinse, repeat...
    setTimeout("_HeadlineRotate(" + index + ", " + delayMs + ", '" + headlineRotatorObjName + "')", delayMs);
}

