var Transition = {
    loadImage: function () {
        var image = document.createElement('img');
		var randomNum;
		
/*		//|| this.oldRandomNum == 3 || this.oldRandomNum == 4
		if (this.oldRandomNum == 1 || this.oldRandomNum == 2 ) { 
			randomNum = this.oldRandomNum + 1;
		} else {
			var randomNum = 1;
		}
		this.oldRandomNum = randomNum;
*/
		
		/*if (randomNum == undefined) {
			randomNum = 1;
		}
		if (this.oldRandomNum && randomNum == this.oldRandomNum) {
			randomNum = randomNum + 1;
			
			if (randomNum == 5) {
				randomNum = 1;
                //randomNum--;
            } else {
                //randomNum++;
            }
	 	}
		this.oldRandomNum = randomNum;*/
		
			
	    randomNum = Math.floor((Math.random() * 2) + 1);
      if (this.oldRandomNum && randomNum == this.oldRandomNum) {
          if (randomNum == 2) {
              randomNum--;
          } else {
              randomNum++;
          }
      }
      this.oldRandomNum = randomNum;
				
		// privzeto, ko ni akcij
      // image.setAttribute('src', 'http://www.kerin-povirk.si/images/fp_slideshow/razprodaja_sep_2010/slika_' + randomNum + '.jpg');
      // image.setAttribute('src', 'http://www.kerin-povirk.si/images/fp_slideshow//slika_' + randomNum + '.jpg');
		// ostalo
		//image.setAttribute('src', 'http://www.kerin-povirk.si/images/akcija_dopust/akcija_dopust' + randomNum + '.jpg');
		image.setAttribute('src', 'http://www.kerin-povirk.si/images/fp_slideshow/akcija_nobilia_jesen_2010/nobilia_' + randomNum + '.jpg');

        $(image).setStyle({position: 'absolute', left: '0', top: '0', opacity: '0'});
        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});
        } else {
					// ta se vedno prikaze prva
					// image.setAttribute('src', 'http://www.kerin-povirk.si/images/fp_slideshow/razprodaja_sep_2010/objava_zaprto.jpg');
				}
        this.oldimage = image;
        setTimeout('Transition.loadImage()', 4000);
    },

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