function loadScript() {
externalLinks();
backLinks();
}

function backLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("class") == "backlink") {
     anchor.href = "javascript:void(0);";
     anchor.onclick = function(){history.go(-1);};
   }
 }
}

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
Event.observe(window, 'load', loadScript);

function SetupRotatingBanner(containerId)
{
    var container = $(containerId);
    if(container)
    {
        container.startTimer = function()
        {
            setTimeout("NextBanner('"+containerId+"');", 4000);
        };
        container.nextBanner = function()
        {
            var banners = this.getElementsByClassName('banner');
            
            if(banners.length > 1)
            {
                var currentBanner;
                var nextBanner;
                var i;
                
                //Find the current banner
                for(i=0; i<banners.length; i++)
                    //If this is the current banner
                    if($(banners[i]).hasClassName('visible'))
                    {
                        currentBanner = banners[i];
                        break;
                    }
                //Determine the next baner
                if(++i == banners.length)
                    i=0;
                nextBanner = $(banners[i]);
                
                //Switch the banners
                new Effect.Opacity(nextBanner, {duration:0, from:1, to:0});
                new Effect.Opacity(currentBanner,
                    {
                        duration:0.75, from:1, to:0,
                        afterFinish:function(obj)
                        { 
                            currentBanner.removeClassName('visible');
                            nextBanner.Opacity = 0;
                            nextBanner.addClassName('visible');
                            new Effect.Opacity(nextBanner, {duration:1.25, from:0, to:1});
                        }
                    });
                this.startTimer();
            }
        };
        
        container.startTimer();
    }
}

function NextBanner(containerId)
{
    $(containerId).nextBanner();
}