/*
	Slimbox v1.3 - The ultimate lightweight Lightbox clone
	by Christophe Beyls (http://www.digitalia.be) - MIT-style license.
	Inspired by the original Lightbox v2 by Lokesh Dhakar.
*/
var LightboxForWaiter = {

	init: function( options )
	{
		this.options = Object.extend(
			{
				resizeDuration: 400,
				resizeTransition: Fx.Transitions.sineInOut,
				initialWidth: 250,
				initialHeight: 250,
				animateCaption: true
			}, options || {} );
		this.eventKeyDown = this.keyboardListener.bindAsEventListener( this );
		this.eventPosition = this.position.bind( this );
		this.overlay = new Element( 'div' ).setProperty( 'id', 'lbOverlayWaiter' ).injectInside( document.body );
		this.center = new Element( 'div' ).setProperty( 'id', 'lbCenterWaiter' ).setStyles( { width: this.options.initialWidth+'px', height: this.options.initialHeight+'px', marginLeft: '-'+( this.options.initialWidth/2 )+'px', display: 'none' } ).injectInside( document.body );
		var nextEffect = this.nextEffect.bind( this );
		this.fx = {
			overlayOn: this.overlay.effect( 'opacity', { duration: 1, onComplete: nextEffect } ).hide(),
			//resizeY: this.center.effects( { duration: this.options.resizeDuration, transition: this.options.resizeTransition, onComplete: nextEffect } ),
			//resizeX: this.center.effects( { duration: this.options.resizeDuration, transition: this.options.resizeTransition, onComplete: nextEffect } ),
			overlayOff: this.overlay.effect( 'opacity', { duration: 1 } ).hide()
			//overlayOff: this.overlay.effect( '', {} ).hide()
		};
	},

	show: function( url, title )
	{
		return this.open( [[url, title]], 0 );
	},

	open: function( urlAndTitle, divNum )
	{
		this.dataDivs = urlAndTitle;
		//this.center.setStyles({width: this.options.initialWidth+'px', height: this.options.initialHeight+'px', marginLeft: '-'+(this.options.initialWidth/2)+'px', display: 'none'});
		this.position();
		this.setup( true );
		this.top = window.getScrollTop()+( window.getHeight()/5 );
		this.center.setStyles( { top: this.top+'px', display: '' } );
		this.fx.overlayOn.start( 0.5 );
		this.center.className = 'lbLoadingWaiter';
		if( this.dataDivs[0][1] != "" )
		{
			//this.dataDiv = $( this.dataDivs[0][1] ).injectInside( this.center );
			this.nextEffect();
		}
		manageFlash( 0 );
		manageSelectsAll( 'hidden' );
		slimboxVis = 1;
		return false;
	},

	position: function()
	{
		this.overlay.setStyles( { top: window.getScrollTop()+'px', height: window.getHeight()+'px' } );
	},

	setup: function( open )
	{
		var elements = $A( document.getElementsByTagName( 'object' ) );
		elements.each( function( el ){ el.style.visibility = open ? 'hidden' : ''; } );
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]( 'scroll', this.eventPosition )[fn]( 'resize', this.eventPosition );
		document[fn]( 'keydown', this.eventKeyDown );
		this.step = 0;
	},

	keyboardListener: function( event )
	{
		/*switch( event.keyCode )
		{
			case 27: case 88: case 67: this.close(); break;
		}*/
	},

	nextEffect: function()
	{
		/*
		if( this.dataDivs[0][1] != "" )
		{
			switch( this.step++ )
			{
				case 1:
					this.center.className = '';
					this.dataDiv = $( this.dataDivs[0][1] ).injectInside( this.center );
					this.dataDiv.style.display = 'block';
					if( this.center.clientHeight != this.dataDiv.offsetHeight )
					{
						this.fx.resizeY.start( { height: this.dataDiv.offsetHeight } );
						break;
					}
					this.step++;
				case 2:
					if( this.center.clientWidth != this.dataDiv.offsetWidth )
					{
						this.fx.resizeX.start( { width: this.dataDiv.offsetWidth, marginLeft: -this.dataDiv.offsetWidth/2 } );
						break;
					}
					this.step++;
				case 3:
					for( var f in this.fx ) this.fx[f].stop();
					this.step = 0;
					break;
			}
		}
		*/
	},

	close: function()
	{
		if( this.step < 0 ) return;
		this.step = -1;
		if( this.preload )
		{
			this.preload.onload = Class.empty;
			this.preload = null;
		}
		for( var f in this.fx ) this.fx[f].stop();
		this.center.style.display = 'none';
		this.fx.overlayOff.chain( this.setup.pass( false, this ) ).start( 0 );
		slimboxVis = 0;
		flashesAreManaged = setTimeout( 'manageFlash( 1 )', 1000 );
		timeOutSelect2 = setTimeout( 'manageSelectsAll( "visible" )', 1000 );
		return false;
	}
};

window.addEvent( 'domready', LightboxForWaiter.init.bind( LightboxForWaiter ) );
