﻿var SlideShow = Class.create();var SlideShowList = new Array();SlideShow.prototype = {	init: function( showID, inImage ) {		/**the base attributes**/		this.imagePath			= SlideShowList[showID]["path"];		this.transidionSpeed	= SlideShowList[showID]["blendTime"];		this.hasPreloadImage	= SlideShowList[showID]["hasPreloadImage"];		this.pauseTime			= SlideShowList[showID]["pauseTime"];		this.isRandom			= SlideShowList[showID]["random"];		this.imageList			= SlideShowList[showID]["list"];		this.doesRepeat			= SlideShowList[showID]["repeat"];		this.nextRequestedImage = null;				if( this.doesRepeat == null ) this.doesRepeat = true;		this.isRunning		= true;					if( this.isRandom ) {			this.currentImageNr	= Math.floor(Math.random()*this.imageList.length);			this.nextImageNr		= Math.floor(Math.random()*this.imageList.length);		} else {			this.currentImageNr	= 0;			this.nextImageNr		= 0;		}				this.preloadImgCheck 	= null;		/**the storage for the images**/		this.loadedImages = new Array();						/**get the image and wait until it is load then continue*/		this.image1 = inImage;				this.preloadImgCheck = new Image()		this.preloadImgCheck.onload = this.createImageDiv.bind(this);		this.preloadImgCheck.src = this.image1.src;						},		createImageDiv: function( ) {				/** create a div to wrapp around the image **/		this.imageContainer = document.createElement("div");		//this.imageContainer.className = "blendImage";		this.imageContainer.style.width = this.image1.width+"px";		this.imageContainer.style.height = this.image1.height+"px";		/** wrapp the div around the image **/		this.image1.parentNode.insertBefore(this.imageContainer,this.image1);		this.image1.parentNode.removeChild(this.image1);		this.imageContainer.appendChild(this.image1);				this.loadNextImage();				tmpTimer = new TimedExecution(this.callback.bind(this),this.getCurrentPauseTime());	},		loadNextImage: function( ) {				this.opacity = 0;				this.currentImageNr = this.nextImageNr;		this.nextImageNr = this.getNextImageNr();				this.image1.src = this.imagePath+this.imageList[this.currentImageNr];		setOpacity(this.image1,100);				if(  this.isRunning ) {			this.waitingForImage = true;						this.preloadImgCheck = new Image()			this.preloadImgCheck.onload = this.imageLoaded.bind(this);			this.preloadImgCheck.src = this.imagePath+this.imageList[this.nextImageNr];		}			},		getCurrentPauseTime : function() {		if( typeof this.pauseTime == "number" ) {			return this.pauseTime;		} else {			return this.pauseTime[this.currentImageNr];		}	},		getNextImageNr : function() {				if( this.nextRequestedImage != null && this.nextRequestedImage != this.currentImageNr ) {			tmpNextNr = this.nextRequestedImage;		} else {			tmpNextNr = 0;						if( this.isRandom && this.imageList.length>2 ) {				do {					tmpNextNr = Math.floor(Math.random()*this.imageList.length);				} while( tmpNextNr == this.currentImageNr );			} else {				tmpNextNr = this.currentImageNr+1;				if( tmpNextNr >= this.imageList.length ) {					if( !this.doesRepeat ) this.isRunning = false;					if( this.hasPreloadImage ) tmpNextNr = 1;					else tmpNextNr = 0;				}			}		}				return tmpNextNr;	},		setImage: function( inImageNr ) {		this.opacity = 100;		this.nextImageNr = inImageNr;		this.imageContainer.style.backgroundImage = "url(\""+this.imagePath+this.imageList[this.nextImageNr]+"\")";		setOpacity(this.image1,100-this.opacity);		this.waitingForImage = true;						this.preloadImgCheck = new Image()		this.preloadImgCheck.onload = this.imageLoaded.bind(this);		this.preloadImgCheck.src = this.imagePath+this.imageList[this.nextImageNr];						//alert(inImageNr);	},		imageLoaded: function() {		this.imageContainer.style.backgroundImage = "url(\""+this.preloadImgCheck.src+"\")";		this.preloadImgCheck.onload = null;		this.preloadImgCheck = null;		this.waitingForImage = false;	},		callback: function() {		if( ! this.isRunning ) return 0;		if( !this.waitingForImage ) {			if( this.opacity < 100 ) {								this.opacity = this.opacity+5;				setOpacity(this.image1,100-this.opacity);								return this.transidionSpeed;			} else {					this.loadNextImage();				tmpPauseTime = this.getCurrentPauseTime();								return tmpPauseTime;			}		}		return 0.001;	}	}function initSlideShow() {	imgList = document.getElementsByTagName("img");	Event.stopObserving(window,"load",initSlideShow,true);		for( i=0 ; i<imgList.length ; i++ ) {		if( imgList[i].name.toLowerCase().match("slideshow_") ) {			showID = imgList[i].name.substring(10);			SlideShowList[showID]["slideshow"] = new SlideShow(showID,imgList[i]);		}	}}function setOpacity( inObject, inValue ) {	inObject.style.MozOpacity = inValue/100;	inObject.style.opacity = inValue/100;		if( inObject.filters != null ) {		if( inObject.filters.alpha == null ) {			inObject.style.filter='alpha(opacity='+inValue+')';		} else {			inObject.filters.alpha.opacity = inValue;					}	}}Event.observe(window,"load",initSlideShow,true);