var portal = (portal) ? portal : new Object();

portal.activeDisplay = null;
portal.activeDisplayIndex = -1;
portal.timeoutID = null;
portal.enableSwapTimer = true;
portal.timeoutLength = 8000;
portal.displays = new Array('musm', 
                            'tribune', 
                            'journal', 
                            'mutv', 
                            'wmur', 
                            'interactive', 
                            'ads');
                            

portal.init = function() {
    var main = document.getElementById("display-musm");
    main.style.display = "block";
    portal.activeDisplay = "musm";
    portal.swap();
}

portal.setSwapTimer = function(swap) {
    portal.enableSwapTimer = swap;
}

portal.swap = function() {
    var i = portal.activeDisplayIndex;
    i = ((i + 1) >= portal.displays.length) ? 0 : i+1;
    
    portal.activeDisplayIndex = i;
    portal.showDisplay(portal.displays[i], false);
    
    if (portal.enableSwapTimer)
        portal.timeoutID = setTimeout('portal.swap()', portal.timeoutLength);

}

portal.showDisplay = function(display, manual) {
    if (manual)
        portal.timeoutID = clearTimeout(portal.timeoutID);

    if (display == portal.activeDisplay) {
        display = "musm";
        
        if (manual && portal.enableSwapTimer)
            portal.timeoutID = setTimeout('portal.swap()', portal.timeoutLength);
    }
    
    portal.switchDisplay(portal.activeDisplay, display);
}

portal.switchDisplay = function(prev, next) {
    var prevIcon = document.getElementById(prev + "-image");
    var nextIcon = document.getElementById(next + "-image");
    
    var prevDisplay = document.getElementById("display-" + prev);
    var nextDisplay = document.getElementById("display-" + next);
    
    if (prevIcon != null)
        prevIcon.src = "img/"+prev+".gif";
    if (nextIcon != null)
        nextIcon.src = "img/blank.gif";
    
    prevDisplay.style.display = "none";
    nextDisplay.style.display = "block";
    
    portal.activeDisplay = next;
}
