var Splash = Class.create({	id: null,	src: null,	img: null,	credit: null,	initialize:function(idOrElement, src, credit){		if(Object.isElement(idOrElement)){			var element = idOrElement;			this.img = element;			this.id = element.id;			this.src = element.src;						if(credit == null){				this.credit = element.alt;			}						//for opera			this.img.setOpacity(0);			this.img.onload = function(){};		}else{			this.id = idOrElement;			this._initWithFileName(idOrElement, src, credit);		}	},	_initWithFileName:function(id, src, credit){		this.id = id;		this.src = src;		this.credit = credit;	},	load: function(){		if(this.img != null){			return;		}		this.img = new Element('img', {			src:this.src,			id:this.id		});		//for opera		this.img.setOpacity(0);		this.img.onload = function(){};		//this.img.hide();	}});var SplashManager = Class.create({	_container: null,	_splash: null,	_credit: null,	/**	 * constructor	 */	initialize:function(container){		this._container = container;		this._splash = container.down("#splash");		this._credit = container.down("#splash-credit")				this.current = null;				this.fitImageToScreenEvent = this.fitImageToScreen.bind(this);		Event.observe(window, 'resize', this.fitImageToScreenEvent);	},	show:function(splash, options){		this.showContainer();		if(splash.img.complete){			this._showInternal(splash, options);		}else{			splash.img.onload = function(){this._showInternal(splash, options)}.bind(this);		}	},	_showInternal:function(splash, options){		hideLoader({queue:options.queue});		splash.img.setStyle(this._getStyles(splash));		splash.img.setStyle({zIndex: 1});		if(this._credit.visible()){			this._credit.fade({queue:options.queue});		}		splash.img.appear({			queue: options.queue, 			afterFinish:function(){				if(this.current != null){					this.current.img.hide();				}				splash.img.setStyle({zIndex:0});				this.current = splash;								if(splash.credit != null && splash.credit != ""){					this._credit.update(splash.credit);					this._credit.appear({queue:options.queue});				}				applyAfterFinish(options);			}.bind(this),			duration: 1.0,			transition: Effect.Transitions.linear		});	},	hide:function(splash, options){		if(this._credit.visible()){			this._credit.fade({queue:options.queue});		}		if(splash.img != null && splash.img.visible()){			splash.img.fade({				queue: options.queue, 				afterFinish:function(){					this.current = null;					applyAfterFinish(options);				}.bind(this)			});		}else{			applyAfterFinish(options);		}	},	hideCurrent:function(options){		if(this.current != null){			this.hide(this.current, options);		}else{			applyAfterFinish(options);		}	},	hideAll: function(splashes, options){		splashes.each(function(splash){			this.hide(splash, options);		}.bind(this));	},	hideContainer: function(options){		if(this._container.visible()){			new Effect.Opacity(this._container, {				from: 1.0, 				to: 0.0, 				duration: 1.0, 				afterFinish:function(){					if(this.current != null){						this.current.img.hide();						this.current = null;					}					options.afterFinish();				}.bind(this)			});		}	},	showContainer: function(options){		if(! this._container.visible()){			//this._container.setOpacity(0);			//this._container.appear(options);		}			this._container.show();			this._container.setOpacity(1);	},	insert:function(splash){		splash.load();		this._splash.insert(splash.img);	},		// -------- private	_getStyles:function(splash){			var element = splash.img;			var srcWidth = element.getWidth();		var srcHeight = element.getHeight();				if(element.orgWidth == undefined){			element.orgWidth = srcWidth;			element.orgHeight = srcHeight;		}						var objBody = $(document.body);		var dstWidth = document.viewport.getWidth();		var dstHeight = document.viewport.getHeight();			if(dstWidth < 1024){			dstWidth = 1024;		}		if(dstWidth > element.orgWidth){			dstWidth = element.orgWidth;		}		if(dstHeight < 768){			dstHeight = 768;		}		if(dstHeight > element.orgHeight){			dstHeight = element.orgHeight;		}			var styles = {};		if((srcWidth/srcHeight) > (dstWidth/dstHeight)){			var styleWidth = srcWidth  * (dstHeight/srcHeight);			styles['width'] = styleWidth + "px";			styles['height'] = dstHeight + "px";			styles['marginLeft'] = ((styleWidth - document.viewport.getWidth()) / 2 * -1) + "px";			styles['marginTop'] = ((dstHeight - document.viewport.getHeight()) / 2 * -1) + "px";		}else{			var styleHeight = srcHeight * (dstWidth/srcWidth);			styles['width'] = dstWidth + "px";			styles['height'] = styleHeight + "px";			styles['marginLeft'] = ((dstWidth - document.viewport.getWidth()) / 2 * -1)+"px";			styles['marginTop'] = ((styleHeight - document.viewport.getHeight()) / 2 * -1) + "px";		}		return styles;	},	fitImageToScreen:function(){		if(this.current != null && this.current.img.visible()){			this.current.img.setStyle(this._getStyles(this.current));		}	}});var IndexSplash = Class.create({	manager: null,	splashTimer: null,	queueName: null,	endQueue: null,	running: false,	index: 0,	splashes: null,		initialize:function(manager, imageFiles, credits){		this.manager = manager;		this.splashTimer = null;		this.queueName = "indexSplash";		this.endQueue = {			scope:this.queueName,			position:'end'		};		this.running = false;		this.index = 0;		this.splashes = new Array(imageFiles.length);		for(var i=0; i<imageFiles.length; i++){			this.splashes[i] = new Splash("splash_"+i, imageFiles[i], credits[i]);			//this.splashes[i].load();		}		this.randomize();				//for nowhere, special splash		//this.splashes.unshift(new Splash("splash_x", '../common/images/works/nowhere/splash_2.jpg', 'dots - peformance "nowhere " at sunsui, Osaka on 7th-9th March, 2009'));		//this.splashes.unshift(new Splash("splash_z", '../common/images/works/nowhere/splash.jpg', 'dots - peformance "nowhere " at sunsui, Osaka on 7th-9th March, 2009'));				//for KISS, special splash		//this.splashes.unshift(new Splash("splash_y", '../common/images/kiss/3.jpg', '"KISS", 2009 photo by Yoshikazu Inoue'));		//this.splashes.unshift(new Splash("splash_z", '../common/images/kiss/1.jpg', '"KISS", 2009 photo by Yoshikazu Inoue'));		//this.splashes.unshift(new Splash("splash_x", '../ut/ut-main.jpg', 'Unknown Theory, Still in Progress...<br /> at Atelier GEKKEN, Kyoto on 1st June, 2010'));
		this.splashes.unshift(new Splash("splash_x", '../common/images/kakame/kakame_splash.jpg', 'new work "kakame", September(Sakira, Shiga, Japan)/October(Artelio Theater, Kanagawa, Japan), 2010'));
	},	start:function(){		if(this.running){			return;		}		cancelEffect(this.endQueue);		this.manager.hideCurrent({queue:this.endQueue});		showLoader({queue:this.endQueue});		this.splashTimer = setTimeout(this.next.bind(this), 1000);		this.running = true;	},	stop:function(){		if(! this.running){			return;		}		clearTimeout(this.splashTimer);		cancelEffect(this.endQueue);		this.manager.hideAll(this.splashes, {queue:this.endQueue});		this.running = false;	},	next:function(){		if(this.splashTimer != null){			clearTimeout(this.splashTimer);		}		cancelEffect(this.endQueue);		var splash = this.splashes[this.index];		if($(splash.id) == null){			this.manager.insert(splash);		}		this.manager.show(splash, {queue:this.endQueue});		this.splashTimer = setTimeout(this.next.bind(this), 15000);		this.index++;		if(this.index > this.splashes.length-1){			this.index = 0;		}	},	randomize:function(){		for(var i=this.splashes.length-1; i>0; i--)		{			var index = Math.floor(Math.random()*i);			var splash = this.splashes[index];			this.splashes[index] = this.splashes[i];			this.splashes[i]= splash;		}	}});