﻿var SlideShow = function( showID, inImage ) {	this.initialize( showID, inImage );}var SlideShowImage = function( path, slideshow ) {	this.initialize( path, slideshow );}var SlideShowList = new Array();SlideShow.prototype = {		initialize: function( showID, inImage ) {		this.path = SlideShowList[showID]['path'];		this.preloadImageList = [];		this.imageList = [];				this.transidionSpeed	= SlideShowList[showID]["blendTime"];		this.hasPreloadImage	= SlideShowList[showID]["hasPreloadImage"];		this.pauseTime			= SlideShowList[showID]["pauseTime"];		this.isRandom			= SlideShowList[showID]["random"];		this.doesRepeat			= SlideShowList[showID]["repeat"];		this.currentImageNr = 0;		this.nextImageNr = 1; 				for ( var i=0,length = SlideShowList[showID]['list'].length ; i<length ; i++ )  {			var name = SlideShowList[showID]['list'][i];			if( this.preloadImageList[name] == null ) {				this.preloadImageList[name] = new SlideShowImage( this.path+name, this );			}			this.imageList[i] = this.preloadImageList[name];					}		try {			this.image1 = inImage;			this.imageList[this.nextImageNr].load();			this.createImageDiv();		} catch( e ) {		}	},		/**		**/	createImageDiv: function( ) {		//alert('ok');			this.imageContainer1 = $('<div>').css({					backgroundImage : this.image1.css('backgroundImage'),					backgroundRepeat : 'no-repeat',					backgroundPosition : 'center center',					width : this.image1.innerWidth(),					height : this.image1.innerHeight(),					zIndex:1,					position:"absolute",					left:0,					top:0				});						this.imageContainer2 = $('<div>').css({					backgroundImage : this.image1.css('backgroundImage'),					backgroundRepeat : 'no-repeat',					backgroundPosition : 'center center',					width : this.image1.innerWidth(),					height : this.image1.innerHeight(),					zIndex:2,					position:"absolute",					left:0,					top:0				});		this.image1.append(this.imageContainer1)					.append(this.imageContainer2)					.css('backgroundImage','');							this.imageContainer2.fadeOut(0);				var self = this;				tmpTimer = new TimedExecution(function() {							return self.callback();						},this.getCurrentPauseTime() );			},		callback : function() {		var self = this;		if( this.imageList[this.nextImageNr].isLoaded() ) {					this.imageContainer2.css('backgroundImage',"url('"+this.imageList[this.nextImageNr].image.src+"')");			this.imageContainer2.fadeIn(this.transidionSpeed*80000/*);			this.imageContainer1.fadeOut(this.transidionSpeed*80000*/, function() {				self.imageContainer1.hide();				self.imageBlende();			});					} else {			return 0.0001;		}	},		imageBlende : function() {		var tmpImage = this.imageContainer1;		this.imageContainer1 = this.imageContainer2;		this.imageContainer2 = tmpImage;		this.currentImageNr = this.nextImageNr;		this.nextImageNr++;		if( this.nextImageNr >= this.imageList.length ) {			this.nextImageNr = 0;		}				this.imageContainer2.fadeOut();		this.imageContainer1.css('zIndex',1);		this.imageContainer2.css('zIndex',2);		this.imageList[this.nextImageNr].load();		var self = this;				tmpTimer = new TimedExecution( function() { return self.callback() },this.getCurrentPauseTime());	},		getCurrentPauseTime : function() {		if( typeof this.pauseTime == "number" ) {			return this.pauseTime;		} else {			return this.pauseTime[this.currentImageNr];		}	},		imageLoaded : function( image ) {	}}SlideShowImage.prototype = {	initialize: function( path, slideshow ) {		this.path = path;		this.image = null;		this.slideshow = slideshow;		this._loaded = false;	},		isLoaded : function() {		return this._loaded;	},		loaded : function() {		this._loaded = true;		this.slideshow.imageLoaded(this);	},		load : function() {		if( this.image == null ) {			this.image = new Image();			var self = this;			this.image.onload = function() {				self.loaded();			};			this.image.src = this.path;		}	}}function initSlideShow() {	$('div[class*="slideshow_"]').each(function(){		showID = 1;		SlideShowList[showID]["slideshow"] = new SlideShow(showID,$(this));	});}$(function() {	initSlideShow();});/*********************************************/var TimedExecution = function( callback, interval ) {	this.initialize( callback, interval );}TimedExecution.prototype = {	initialize: function( callback, interval ) {		this.callback = callback;		this.interval = interval;		//this.currentlyExecuting = false;				this.registerCallback();				this.timeOut = null;	},		registerCallback: function() {		var self = this;		this.timeOut = setTimeout(function() { return self.onTimerEvent();}, this.interval*1000);	},		onTimerEvent: function() {		var self = this;		try {			var nextInterval = this.callback();						if( nextInterval == -1 ) {				nextInterval = this.interval; 			}			if( nextInterval > 0 ) {								this.interval = nextInterval;				this.timeOut = setTimeout(function() { return self.onTimerEvent();}, this.interval*1000);			}			} catch(e) {		}	}}
