var Transition = {
    loadImage: function () {
        var image = document.createElement('img');
		var num = Math.floor(Math.random() * slike.length);
        
        if (this.oldNum && num == this.oldNum) {
            if (num == (slike.length + 1)) {
                num--;
            } else {
                num++;
            }
        }
		
		this.oldNum = num;
        image.setAttribute('src', slike[num]);
        $(image).setStyle({position: 'absolute', left: '0', top: '0', opacity: '0'});
		//$(image).observe('click', function () { location.href = povezave[num]; });
        this.holder = $('image');
        this.holder.setStyle({position: 'relative', overflow: 'hidden'});
        this.holder.appendChild(image);
        
        if (!image.complete) {
            this.bfx = this._onLoad.bindAsEventListener(null, this, image);
            Event.observe(image, 'load', this.bfx);
        } else {
            this._transitionImage(image);
        }
    },
    
    _onLoad: function (event, reference, image) {
        reference._transitionImage(image);
        Event.stopObserving(image, 'load', this.bfx);
    },
    
    _transitionImage: function (image) {
        new Effect.Appear(image, {duration: 1.5, from: 0.0, to: 1.0});
        if (this.oldimage) {
            new Effect.Appear(this.oldimage, {duration: 1.5, from: 1.0, to: 0.0, afterFinish: this._removeImage});
        }
        this.oldimage = image;
        setTimeout('Transition.loadImage()', 6000);
    },

	_removeImage: function(object) {
		object.element.remove();
	}
}
