﻿if( window.Tn == null ) {	window.Tn  = {};}if( Tn.Fx == null ) {	Tn.Fx = {};}if( Tn.Util == null ) {	Tn.Util = {};}var SlideShowList = new Array();$(function() {	for( index in SlideShowList ) {		var slideShow = new Tn.Fx.SlideShow( $('.slideshow_'+index),SlideShowList[index].path, SlideShowList[index].list );	}	});	Tn.Fx.SlideShow = function ( elm, basePath, imageList ) {	if( imageList && imageList.length > 1 ) {		var self = this;		this._basePath = basePath;		this._loader = new Tn.Util.ImageLoader(this._basePath);		this._imageList = imageList;		this._divList = {};		this._elm = elm;		this._lastIndex = null;		this._currIndex = 0;		this._width = elm.innerWidth();		this._height = elm.innerHeight();		this._container = $('<div>').css({			'position':'relative',			'left' : 0,			'top' : 0,			'width': elm.innerWidth(),			'height': elm.innerHeight()		});		//@todo check if mor ethan 1 image otherwise do nothing		this._loader.loadImage(imageList[0], function( img, width, height ) { self._startUp( img, width, height ) } );	}}Tn.Fx.SlideShow.prototype = {	_startUp : function( img, width, height ) {		this._divList[img] = this._createDiv(img,width, height);		this._container.append(this._divList[img]);		this._elm.after(this._container);		this._elm.remove();				this.blendNextImage();	},		blendNextImage : function(){		var self = this;		this._lastIndex = this._currIndex;		this._currIndex++;		if( this._currIndex >= this._imageList.length ) {			this._currIndex = 0;		}		this._loader.loadImage(this._imageList[this._currIndex], function( img, width, height ) { self._imageReadyToBlend( img, width, height ) } );		},		_imageReadyToBlend : function( img, width, height ) {		if( this._divList[img] == null ) {			this._divList[img] = this._createDiv(img,width, height);		}		var self = this;		this._divList[img].hide();		this._container.append(this._divList[img]);		this._divList[img].fadeIn(5000);		this._divList[this._imageList[this._lastIndex]].fadeOut(5000, function() {			self.blendNextImage();		});	},		_createDiv : function( img,width, height ) {		var div = $('<div>').css(			{				'position' : 'absolute',				'left' : (this._width-width)/2,				'top' : (this._height-height)/2,				'width': width,				'height': height,				'background-image': 'url('+this._basePath+'/'+img+')'			}		);				if( $.browser.msie  && $.browser.version <= 7 ) {			if( img.indexOf('.png') != -1 ) {				div.css('background-image','');				var div2 = $('<div>').css(						{							'width': width,							'height': height						});				div2.get(0).style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+this._basePath+'/'+img+'");';				div.append(div2);			}		}		return div;	},		_imageLoade : function( img ) {	},		start : function() {	}}Tn.Util.ImageLoader = function ( basePath ) {	this._basePath = basePath;	this._imgs = {};}Tn.Util.ImageLoader.prototype = {	loadImage : function( img , callback ) {		var self = this;		if( this._imgs[img] == null ) {			this._imgs[img] = {};			this._imgs[img].callbacks = new Array();			this._imgs[img].callbacks.push(callback);			this._imgs[img].img = new Image();			this._imgs[img].img.onload = function() {				self._imageLoded(img);			};			this._imgs[img].img.src = this._basePath+"/"+img;						this._imgs[img].loaded = false;		} else if( this._imgs[img].loaded == true ) {			callback(img,this._imgs[img].img.width,this._imgs[img].img.height);		} else {			this._imgs[img].callbacks.push(callback);		}	},		_imageLoded : function( img ) {		var self = this;		this._imgs[img].loaded = true;		$.each(this._imgs[img].callbacks, function() {			this( img, self._imgs[img].img.width, self._imgs[img].img.height );		});	}}/*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*70000, function() {				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) {		}	}}*/
