function imageOnResize(size, objectId)
{
    //check to see if the object id ends in a slice
    var groups = objectId.match(/^image_([a-f0-9]+)/);
    if (groups) {
        var instance = groups[1];
        if ($("imagePart_" + instance)) {
            $("imagePart_" + instance).style.height = size + "px";
        }
    }
}

function imageFadeEffect()
{
    if (!imageFadeEffect.effects) {
        imageFadeEffect.effects = new Array();
        imageFadeEffect.frames = 50;
    }
    this.effectId = imageFadeEffect.effects.length;
    imageFadeEffect.effects[this.effectId] = this;
    this.images = new Array();
    //copy all image ids into an array
    for(var i = 0; i < arguments.length; i++) {
        this.images[i] = arguments[i];
    }
    this.position = 0;
    this.playCount = 0;

    this.playButton  = createFloatingElement("div", "imageSlideshowPlayButton");
    var effectId = this.effectId;
    this.playButton.onclick = function() {
        var effect = imageFadeEffect.effects[effectId];
        if (effect.playing) {
            effect.stop();
        } else {
            effect.start();
        }
    }
    this.reposition();
}

imageFadeEffect.prototype.reposition = function()
{
    var imageId = this.images[this.position];
    if ($(imageId) && this.showPlayButton) {
        var position = findPosition($(imageId));
        setElementPosition(this.playButton, position.x + 5, position.y + 5);
    } else {
        //not visible
        setElementPosition(this.playButton, -1000, -100);
    }
}

imageFadeEffect.prototype.start = function(showPlayButton)
{
    if (showPlayButton) {
        this.showPlayButton = showPlayButton;
    }
    this.playing = true;
    this.playCount++;
    this.playButton.className = "imageSlideshowPauseButton";
    this.fadeIn(this.playCount);
}

imageFadeEffect.prototype.stop = function()
{
    for (var i = 0; i < this.images.length; i++) {
        if ($(this.images[i])) {
            $(this.images[i]).style.opacity = 1;
        }
    }
    this.playing = false;
    this.playButton.className = "imageSlideshowPlayButton";
}

imageFadeEffect.prototype.fadeIn = function(playSequence)
{
    this.reposition();
    var imageId = this.images[this.position];
    if ($(imageId)) {
        $(imageId).style.display = "block";
        //select the element in the slider
        if (isDefined("_aponSelectEditor")) {
            _aponSelectEditor.selectByElement($(imageId));
        }
        var effectId = this.effectId;
        var continueToNext = this.images.length > 1 && this.playing && this.playCount == playSequence;
        var frameFunction = function(frame) {
            if (document.all) {
                $(imageId).style.filter = "alpha(opacity=" + Math.floor(100*frame/imageFadeEffect.frames) + ")";
            } else {
                $(imageId).style.opacity = frame/imageFadeEffect.frames;
            }
            if (frame == imageFadeEffect.frames) {
                if (continueToNext) {
                    setTimeout("imageFadeEffect.effects[" + effectId + "].fadeOut(" + playSequence + ");", 5000);
                }
            }
        }
        var animation = new _aponAnimation(0, imageFadeEffect.frames, 30, "linear", frameFunction);
        animation.start();
    }
}

imageFadeEffect.prototype.fadeOut = function(playSequence)
{
    if (!this.playing) {
        return;
    }
    var imageId = this.images[this.position];
    if ($(imageId)) {
        var effectId = this.effectId;
        var frameFunction = function(frame) {
            if (document.all) {
                $(imageId).style.filter = "alpha(opacity=" + Math.floor(100*frame/imageFadeEffect.frames) + ")";
            } else {
                $(imageId).style.opacity = frame/imageFadeEffect.frames;
            }
            if (frame == 0) {
                imageFadeEffect.effects[effectId].fadeNext(playSequence);
            }
        }
        var animation = new _aponAnimation(imageFadeEffect.frames, 0, 30, "linear", frameFunction);
        animation.start();
    }
}

imageFadeEffect.prototype.fadeNext = function(playSequence)
{
    this.position = (this.position < this.images.length - 1) ? (this.position + 1) : 0;
    for (var i = 0; i < this.images.length; i++) {
        if ($(this.images[i])) {
            $(this.images[i]).style.display = (i == this.position ? "block" : "none");
        }
    }
    this.fadeIn(playSequence);
}
