function ImageObject(s,h,c) {
    this.src = s;
    this.href = h;
    this.caption = c;
    this.image = new Image();
    this.image.src = s;
    this.image.alt = c;
}

/**
 * Class for rotating through a list of images.  Performs a crossfade for
 * transitioning between images.  This class will clear out all children of
 * container object on initialization.
 *
 * Note: All functions were declared within parent because of setInterval scoping.
 *
 * @param imageArray {Array}  an array of ImageObject objects containing images to rotate through
 * @param container {String | Element} DOM element (or ID of element) of element containing the rotating images
 */
function ImageRotator(imageArray, container) {
    var currentIndex = 0;          // current index in the image array

    if(imageArray.length == 0)  return;
    
    // convert id to element
    if(YAHOO.lang.isString(container))
        container = document.getElementById(container);

    // clear container of child nodes
    while(container.hasChildNodes()) {
        container.removeChild(container.firstChild);
    }

    // initialize "fade-in image" (currently displayed)
    var fadeInDiv = document.createElement("div");
    fadeInDiv.style.position = "absolute";
    container.appendChild(fadeInDiv);

    var fadeInHref = document.createElement("a");
    fadeInDiv.appendChild(fadeInHref);

    var fadeInImg = document.createElement("img");
    fadeInImg.setAttribute("border", "0");
    fadeInHref.appendChild(fadeInImg);

    // initialize "fade-out image"
    var fadeOutDiv = document.createElement("div");
    fadeOutDiv.style.position = "absolute";
    container.appendChild(fadeOutDiv);

    var fadeOutHref = document.createElement("a");
    fadeOutDiv.appendChild(fadeOutHref);

    var fadeOutImg = document.createElement("img");
    fadeOutImg.setAttribute("border", "0");
    fadeOutHref.appendChild(fadeOutImg);

    /**
     * Fade-out animation
     */
    var fadeOutAnim = new YAHOO.util.Anim(fadeOutImg, {
            opacity: { to: 0 }
        }, 0.8, YAHOO.util.Easing.easeNone);

    /**
     * Fade-in animation
     */
    var fadeInAnim = new YAHOO.util.Anim(fadeInImg, {
            opacity: { to: 1 }
        }, 0.8, YAHOO.util.Easing.easeNone);

    /**
     * Sets images attributes from an ImageObject
     *
     * @param imgEl {Element} image element to set attributes on
     * @param hrefEl {Element} anchor element to set href on
     * @param imgObj {ImageObject}  image object to pull values from
     */
    var setImageAttributes = function(imgEl, hrefEl, imgObj) {
        imgEl.setAttribute("src", imgObj.src);
        imgEl.setAttribute("alt", imgObj.caption);
        hrefEl.setAttribute("href", imgObj.href);
    }

    /**
     * Rotates to the next image
     */
    var nextImage = function() {
        if(imageArray.length <= 0)
            return;

        // increment index
        currentIndex = ((currentIndex + 1) < imageArray.length) ? currentIndex + 1 : 0;

        // prepare image for fading out
        fadeOutImg.setAttribute("src", fadeInImg.getAttribute("src"));
        YAHOO.util.Dom.setStyle(fadeOutImg, 'opacity', 1);

        // make fade-in image invisible and update to show next image
        YAHOO.util.Dom.setStyle(fadeInImg, 'opacity', 0);
        setImageAttributes(fadeInImg, fadeInHref, imageArray[currentIndex]);

        // perform crossfade
        fadeOutAnim.animate();
        fadeInAnim.animate();
    };

    // initialize images
    if(imageArray.length > 0) {
        YAHOO.util.Dom.setStyle(fadeInImg, 'opacity', 0);
        YAHOO.util.Dom.setStyle(fadeOutImg, 'opacity', 0);

        setImageAttributes(fadeInImg, fadeInHref, imageArray[0]);
        setImageAttributes(fadeOutImg, fadeOutHref, imageArray[0]);

        // fade in first image
        fadeInAnim.animate();
    }

    // set rotation interval timer
    setInterval(nextImage, 6000);   // anonymous function for scoping issues
}
