// JavaScript Document
function handleOnLoad()
{   
    var rotationList = new Array();
    var i = -1;
    var j = -1;
    
    
    // First item in loop
    
    i++;
    j = -1;
    rotationList[i] = new Array();
    
    // div element
    rotationList[i][++j] = new Object();
    rotationList[i][j].text = '';
    
    // h1 element
    rotationList[i][++j] = new Object();
    rotationList[i][j].text = 'Junior guides Project Iceberg';
    
    // p element
    rotationList[i][++j] = new Object();
    rotationList[i][j].text = 'Antarctica is providing the experience of a lifetime for UNL junior Megan Berg.';
    
    // a element
    rotationList[i][++j] = new Object();
    rotationList[i][j].href = 'http://ucommxsrv1.unl.edu/scarlet/public/FMPro?-db=scarletstory&-format=storydetail.htm&-lay=public&-op=eq&storyid=732652S36513X&-max=1&-find=';
    rotationList[i][j].text = 'View the whole story ...';
	rotationList[i][j].target = '_blank';

// img element
    rotationList[i][++j] = new Object();
    rotationList[i][j].src = 'images/homepage/megan1.jpg';
    rotationList[i][j].alt = 'image01';
    
    
    // Second item in loop
    
    i++;
    j = -1;
    rotationList[i] = new Array();
    
    // div element
    rotationList[i][++j] = new Object();
    rotationList[i][j].text = '';
    
    // h1 element
    rotationList[i][++j] = new Object();
    rotationList[i][j].text = 'Eske earns UNL\'s first Marshall Scholarship';
    
    // p element
    rotationList[i][++j] = new Object();
    rotationList[i][j].text = '2005 graduate Aaron Eske has been awarded a prestigious Marshall Scholarship.';
    
    // a element
    rotationList[i][++j] = new Object();
    rotationList[i][j].href = 'popup/eske.shtml';
	rotationList[i][j].text = 'View the whole story ...';
	rotationList[i][j].target = '_blank';
    
    // img element
    rotationList[i][++j] = new Object();
    rotationList[i][j].src = 'images/homepage/eske1.jpg';
    rotationList[i][j].alt = 'image02';
    
    
    
    
    rotator = new RotatingElement(document.getElementById('rotating'));
   	rotator.hideTimerBar();
    rotator.autoRotate(rotationList);
}









function RotatingElement(node)
{
    this.node = node;
    this.nodes = new Array();
    
    //for(var childNode = this.node.childNodes[0]; childNode != null; childNode = childNode.nextSibling) {

    this.playPauseNode = document.createElement('img');
    this.node.appendChild(this.playPauseNode);
    this.playPauseNode.style.position = 'absolute';
    this.playPauseNode.style.right = '50px';
    this.playPauseNode.style.bottom = '30px';
    this.playPauseNode.src = 'http://www.unl.edu/nmc/dev/honors/images/homepage/playpause.jpg';
    this.playPauseNode.style.zIndex = '2';
    this.playPauseNode.onclick = this.togglePause;
    this.playPauseNode.rotatorObject = this;
    this.isPaused = false;
   
    this.nextButtonNode = document.createElement('img');
    this.node.appendChild(this.nextButtonNode);
    this.nextButtonNode.style.position = 'absolute';
    this.nextButtonNode.style.right = '80px';
    this.nextButtonNode.style.bottom = '30px';
    this.nextButtonNode.src = 'http://www.unl.edu/nmc/dev/honors/images/homepage/next.jpg';
    this.nextButtonNode.style.zIndex = '2';
    this.nextButtonNode.onclick = this.goToNext;
    this.nextButtonNode.rotatorObject = this;
    
    var myChildNodes = this.node.getElementsByTagName('*');
    for(var i = 0; i < myChildNodes.length; i++) {
        var childNode = myChildNodes[i];
        if(childNode.nodeType == 1) {
            childNode.style.zIndex = '2';
            if(childNode.nodeName == 'IMG') {
                var newImageNode = document.createElement('img');
                var imageId    = childNode.id;
                var imageClass = childNode.className;
                var timerBar = document.createElement('div');

                var newNode = document.createElement('div');
                newNode.style.position = 'relative';
                newNode.style.zIndex = '1';
                if(imageId != '') {
                    childNode.id = null;
                    newNode.id = imageId;
                }
                if(imageClass != '') {
                    childNode.className = null;
                    newNode.className = imageClass;
                }
                newImageNode.src           = childNode.src;
                newImageNode.alt           = childNode.alt;
                newImageNode.style.display = 'block';
                newNode.appendChild(newImageNode);
                newNode.appendChild(timerBar);
                newNode.appendChild(this.playPauseNode);
                newNode.appendChild(this.nextButtonNode);
                newNode.isImageNode = true;

                childNode.parentNode.insertBefore(newNode, childNode);
                childNode.parentNode.removeChild(childNode);
                childNode = newNode;
                i+=4;
            }
            this.nodes.push(childNode);
        }
    }

    this.timerResolution = 160;
    this.tickerActive = false;
    this.finishedHandler = null;
}











RotatingElement.prototype.setFinishedHandler = function(functionRef)
{
    this.finishedHandler = functionRef;
}

RotatingElement.prototype.getImg = function()
{
    return this.imageNode;
}

RotatingElement.prototype.getSrc = function()
{
    return this.imageNode.src;
}

RotatingElement.prototype.setSrc = function(newSrc)
{
    this.imageNode.src = newSrc;
}

RotatingElement.prototype.autoRotate = function(rotationList)
{
    this._stageThree();
    this.setRotationList(rotationList);
}
RotatingElement.prototype._stageOne = function()
{
    this.setFinishedHandler(this._stageTwo);
    this.fadeOut(0.25);
}
RotatingElement.prototype._stageTwo = function()
{
    this.next();
    this.setFinishedHandler(this._stageThree);
    this.fadeIn(0.25);
}
RotatingElement.prototype._stageThree = function()
{
    this.setFinishedHandler(this._stageOne);
    this.countdown(2);
}






RotatingElement.prototype.setRotationList = function(rotationList)
{
    for(var i = 0; i < this.nodes.length; i++ ) {
        if(this.nodes[i].isImageNode) {
            for(var j = 0; j < rotationList.length; j++) {
                var newImage = document.createElement('img');
                newImage.src           = rotationList[j][i].src;
                newImage.alt           = rotationList[j][i].alt;
                newImage.style.display = 'block';
                rotationList[j][i] = newImage;
            }
        }
    }
    this.rotationList = rotationList;
    this.index = 0;
}

RotatingElement.prototype.next = function()
{
    this.index++;
    if(this.index == this.rotationList.length) {
        this.index = 0;
    }
    for(var i = 0; i < this.nodes.length; i++) {
        if(this.nodes[i].isImageNode) {
            this.nodes[i].removeChild(this.nodes[i].childNodes[0]);
            this.nodes[i].insertBefore(this.rotationList[this.index][i], this.nodes[i].firstChild);
            this.nodes[i].style.zIndex = '1';
        } else if(this.nodes[i].nodeName == 'A') {
            this.nodes[i].href = this.rotationList[this.index][i].href;
            this.nodes[i].target = this.rotationList[this.index][i].target;
            this.nodes[i].firstChild.data = this.rotationList[this.index][i].text;
            this.nodes[i].style.zIndex = '2';
        } else {
            this.nodes[i].firstChild.data = this.rotationList[this.index][i].text;
            this.nodes[i].style.zIndex = '2';
        }
    }
}




RotatingElement.prototype.togglePause = function()
{
    var me = this.rotatorObject;
    me.isPaused = !me.isPaused;
}
RotatingElement.prototype.goToNext = function()
{
    var me = this.rotatorObject;
    me.isPaused = false;
    me.ticks = 0;
}
RotatingElement.prototype.tick = function()
{
    if(!this.tickerActive) {
        this.tickerActive = true;
        this._tick();
    }
}
RotatingElement.prototype._tick = function()
{
    if(this.ticks > 0) {
        if(!this.isPaused) {
            this.ticks--;
            this.timedMethod();
        }
        var callwrapper = new CCallWrapper(this, 1000 / this.timerResolution, '_tick');
        CCallWrapper.asyncExecute(callwrapper);
    } else {
        this.tickerActive = false;
        this.finishedHandler(this);
    }
}

RotatingElement.prototype.countdown = function(seconds)
{
    this.ticks = seconds * this.timerResolution;
    for(var i = 0; i < this.nodes.length; i++) {
        if(this.nodes[i].isImageNode) {
            var imageWidth = this.nodes[i].childNodes[0].width;
            var imageHeight = this.nodes[i].childNodes[0].height;
            var countBar = this.nodes[i].childNodes[1];

            countBar.tickWidth = imageWidth / this.ticks;
            countBar.style.width = imageWidth + 'px';
            countBar.style.height = '2px';
            countBar.style.fontSize = '0px';
            countBar.style.position = 'absolute';
            countBar.style.bottom = '-2px';
            countBar.style.left = '0px';
            countBar.style.backgroundColor = '#444';
            countBar.className = 'count_bar';
        }
    }

    this.timedMethod = this._countdown;
    this.tick();
}
RotatingElement.prototype._countdown = function()
{
    for(var i = 0; i < this.nodes.length; i++) {
        if(this.nodes[i].isImageNode) {
            var countBar = this.nodes[i].childNodes[1];
            countBar.style.width = this.ticks * countBar.tickWidth  + 'px';
        }
    }
}

RotatingElement.prototype.fadeOut = function(seconds)
{
    this.ticks = seconds * this.timerResolution;
    this.tickWidth = 1 / this.ticks;
    this.timedMethod = this._fadeOut;
    this.tick();
}
RotatingElement.prototype._fadeOut = function()
{
    this.node.style.opacity = this.ticks * this.tickWidth + '';
}

RotatingElement.prototype.fadeIn = function(seconds)
{
    if(!seconds) { seconds = 1; }
    this.ticks = seconds * this.timerResolution;
    this.tickWidth = 1 / this.ticks;
    this.timedMethod = this._fadeIn;
    this.tick();
}
RotatingElement.prototype._fadeIn = function()
{
    this.node.style.opacity = (1 - this.ticks * this.tickWidth) + '';
}

RotatingElement.prototype.hideTimerBar = function()
{
    for(var i = 0; i < this.nodes.length; i++) {
        if(this.nodes[i].isImageNode) {
            var timerBar = this.nodes[i].childNodes[1];
            timerBar.style.display = 'none';
        }
    }
}

RotatingElement.prototype.showTimerBar = function()
{
    for(var i = 0; i < this.nodes.length; i++) {
        if(this.nodes[i].isImageNode) {
            var timerBar = this.nodes[i].childNodes[1];
            timerBar.style.display = 'block';
        }
    }
}










/*
 * CCallWrapper.js
 * $Revision: 1.3 $ $Date: 2003/07/07 18:32:43 $
 */

/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is Netscape code.
 *
 * The Initial Developer of the Original Code is
 * Netscape Corporation.
 * Portions created by the Initial Developer are Copyright (C) 2003
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s): Bob Clary <bclary@netscape.com>
 *
 * ***** END LICENSE BLOCK ***** */

function CCallWrapper(aObjectReference,
                      aDelay,
                      aMethodName,
                      aArgument0,
                      aArgument1,
                      aArgument2,
                      aArgument3,
                      aArgument4,
                      aArgument5,
                      aArgument6,
                      aArgument7,
                      aArgument8,
                      aArgument9
                      )
{
  this.mId = 'CCallWrapper_' + (CCallWrapper.mCounter++);
  this.mObjectReference = aObjectReference;
  this.mDelay     = aDelay;
  this.mTimerId = 0;
  this.mMethodName = aMethodName;
  this.mArgument0 = aArgument0;
  this.mArgument1 = aArgument1;
  this.mArgument2 = aArgument2;
  this.mArgument3 = aArgument3;
  this.mArgument4 = aArgument4;
  this.mArgument5 = aArgument5;
  this.mArgument6 = aArgument6;
  this.mArgument7 = aArgument7;
  this.mArgument8 = aArgument8;
  this.mArgument9 = aArgument9;
  CCallWrapper.mPendingCalls[this.mId] = this;
}

CCallWrapper.prototype.execute = function()
{
  this.mObjectReference[this.mMethodName](this.mArgument0,
                                          this.mArgument1,
                                          this.mArgument2,
                                          this.mArgument3,
                                          this.mArgument4,
                                          this.mArgument5,
                                          this.mArgument6,
                                          this.mArgument7,
                                          this.mArgument8,
                                          this.mArgument9
                                          );
  delete CCallWrapper.mPendingCalls[this.mId];
};

CCallWrapper.prototype.cancel = function()
{
  clearTimeout(this.mTimerId);
  delete CCallWrapper.mPendingCalls[this.mId];
};

CCallWrapper.asyncExecute = function (/* CCallWrapper */ callwrapper)
{
  CCallWrapper.mPendingCalls[callwrapper.mId].mTimerId = setTimeout('CCallWrapper.mPendingCalls["' + callwrapper.mId + '"].execute()', callwrapper.mDelay);
};

CCallWrapper.mCounter = 0;
CCallWrapper.mPendingCalls = {};
