(
	function () {
		GUI = {

			getFlashObjects : function (){
				var arrObj = document.getElementsByTagName("object");
				var arrEmb = document.getElementsByTagName("embed");
				if( !isArray( arrObj ) || !isArray(arrEmb) )
					return false;
				
				var allObj=[];
				if( arrObj.length > 0 && arrEmb.length > 0 ){
					for( var a = 0; a < arrObj.length; a++ )
						allObj[ allObj.length ] = arrObj[ a ];
						
					for( var b = 0; b < arrEmb.length; b++ )
						allObj[allObj.length]=arrEmb[b];
				} else if( arrObj.length > 0 ){ 
					allObj=arrObj;
				} else if( arrEmb.length > 0 ){
					allObj = arrEmb;
				}
				return ( allObj.length > 0 ) ? allObj : false;
			},
			
			hideFlashObjects : function (){
				var flashObjects = this.getFlashObjects();
				if( flashObjects )
					for( i = 0; i < flashObjects.length; i++ )
						_.invisible( flashObjects[ i ] );
			},
			
			showFlashObjects : function (){
				var flashObjects = this.getFlashObjects();
				if( flashObjects )
					for( i = 0; i < flashObjects.length; i++ )
						_.visible(flashObjects[i]);
			},


		/* **********************************************************************************
		 *  Front-End init
		 ***********************************************************************************/		
			init : function () {
			},

		/* **********************************************************************************
		 *  Event Handlers
		 ***********************************************************************************/
			/**
			 * Browser has been scrolled
			 * @param {mojoEvent} evt
			 */
			_callout : function ( evt ) {
			},
						
			
		/* **********************************************************************************
		 *  Tween Support Functions
		 ***********************************************************************************/
			/**
			 * A Tween frame for animating a vertical slide
			 */
			slideTweenFactory : function ( easing, start, diff ){
				//the function to animate a frame to spec
				return function ( htmlElement, currentFrame, totalFrames ) {
					_.y_set( htmlElement, easing(currentFrame, start, diff, totalFrames ) );
				};
			},
			
			/**
			 * A Tween frame for animating horizontally
			 */
			widthTweenFactory : function ( easing, wStart, wDiff, xStart, xDiff ){
				//the function to animate a frame to spec
				return function ( htmlElement, currentFrame, totalFrames ) {
					_.w_set( htmlElement, easing(currentFrame, wStart, wDiff, totalFrames ) );
					_.x_set( htmlElement, easing(currentFrame, xStart, xDiff, totalFrames ) );
				};
			},
			
			/**
			 * A Tween frame for animating vertically
			 */
			heightTweenFactory : function ( easing, hStart, hDiff, yStart, yDiff ){
				//the function to animate a frame to spec
				return function ( htmlElement, currentFrame, totalFrames ) {
					_.y_set( htmlElement, easing(currentFrame, yStart, yDiff, totalFrames ) );
					_.h_set( htmlElement, easing(currentFrame, hStart, hDiff, totalFrames ) );
				};				
			},

			/**
			 * A Tween frame for animating red borders
			 */
			borderTweenFactory : function ( easing, start, diff ){
				//the function to animate a frame to spec
				return function ( htmlElement, currentFrame, totalFrames ) {
					_.borderColorRGB( htmlElement, easing(currentFrame, start, diff, totalFrames ), 0, 0 );
				};
			},

			/**
			 * A Tween frame for animating vertically
			 */
			alphaTweenFactory : function ( easing, start, diff ){
				//the function to animate a frame to spec
				return function ( htmlElement, currentFrame, totalFrames ) {
					_.alpha( htmlElement, easing(currentFrame, start, diff, totalFrames ) );
				};				
			},


		/* **********************************************************************************
		 *  Logos and Images
		 ***********************************************************************************/

			updatePreview : function ( overlay_image_id ) {
				
				var image_string = '';
				var data;
				for( var i in ovs ){
					image_key = ovs[i];
					data = this.overlayData[ image_key ];
					image_string += ( ( image_string != "" ) ? '/' : '' ) + data.selectedImage;
				}
				var chair = _.$( data.html_element );
				
				if (chair) 
					chair.style.backgroundImage = "url(/srv/img/chair/" + data.chair_key + "/" + image_string + ".png)";
				
			},

		/* **********************************************************************************
		 *  Skinny Box
		 ***********************************************************************************/
			skinnyBox : {
				
				animating: false,
				matte : null,
				overlay : null,
				
				findElements : function () {
					
					this.matte = _.$("matte");
					this.overlay = _.$("overlay");					
					
					if( !this.matte ){ this.matte = _.create( 'div', 'matte', '', document.body ); }
					if( !this.overlay ){ this.overlay = _.create( 'div', 'overlay', '', document.body ); }

				},
				
				close : function () {
					
					//only close if we're not still opening
					if ( !this.animating ){
						
						//hide
						_.hide( this.matte );
						_.hide( this.overlay );
						
						//get ready to fade in
						_.alpha( this.matte, 0 );
						
						//resume flashing
						GUI.showFlashObjects();
					}
					
				},
				
				displayImage : function ( imgURL, caption ){
					
					if( !_ ) return;
					if( !_.initComplete ) return;
					
					//make sure we have the elements and references we need
					this.findElements();
					
					//start loading the image
					var img = new Image();
					img.className = "img";
					
					//build the HTML to display
					this.overlay.innerHTML = this.getOverlayHTML( caption );
					this.overlay.insertBefore ( img, this.overlay.lastChild );
					
					var ypos = parseInt( ( _.viewportH / 2 ) - (200 + 15 + 25) ) + _.scrollTop;
					var xpos = parseInt( ( _.viewportW / 2 ) - 300 );
					
					_.x( this.overlay, xpos ); 
					_.y( this.overlay, ypos );
					
					_.h( this.matte, _.documentH );
					_.w( this.matte, _.documentW );
					
					this.animating = true;
					_.show( this.matte );
															
					//wait for the image to load
					img.src = imgURL;
					if(img.complete){
						this.animateDisplay();
					}else{
						img.onload = delegate( this, this.animateDisplay );
					}
				},
				
				getOverlayHTML : function ( caption ){
					var html =	'<div style="position:absolute;right:0px;margin-top:-30px;">'+
									'<a href="javascript:GUI.skinnyBox.close();"><img src="/images/close.png" width="80" height="20" border="0" /></a>'+
								'</div><div id="caption">' + caption + '</div>';
					return html;
				},
				
				animateDisplay : function () {
					
					GUI.hideFlashObjects();
					
					_.quickTween(
						this.matte,
						{
							diffAlpha : 60,
							startAlpha : 0
						},
						Math.easeInOutQuint,
						8,
						5,
						delegate( this, this.animateCaption )
					);
				},
				
				animateCaption : function () {
					var caption = _.$("caption");
					_.show( this.overlay );
					_.h( this.matte , _.documentH );
					_.quickTween(
						caption,
						{
							diffH:25,
							startH:0,
							startY:-50,
							diffY:50
						},
						Math.easeInOutQuint,
						5,
						20,
						delegate( this, this.animationComplete )
					);
				},
				
				animationComplete : function () {
					this.animating = false;
					if( !this.matte.onclick ) this.matte.onclick = delegate( this, this.close );
				}
				
				
			}, /* end skinnyBox = {} */
			
			/******************************************************************
			 * SlipperyBox
			 */
			
			slipperyBox : {
				
				baseId : null,
				imgData : null,
				currIndex : null,
				chgInt : null,
				progress : null,
				slide1 : null,
				slide2 : null,
				currObj : null,
				nextObj : null,
				fadeRate : 8,
				
				init : function ( baseId , imgData , currIndex, chgInt){

					this.baseId = baseId;
					this.imgData = imgData;
					this.chgInt = chgInt;
					if(currIndex != null){
						this.currIndex = currIndex;	
					}else{
						this.currIndex = 0;				
					}
					
					if(this.chgInt != null && this.chgInt > 0){
						this.progress = true;
						setTimeout(delegate( this, this.nextLoop ), this.chgInt);						
					}
					
					for( var x = 0; x < imgData.length; x++){
						var srcImg = new Image();
						srcImg.src = imgData[x].imgSrc;
						srcImg.alt = imgData[x].altTxt;
						imgData[x].imgObj = srcImg;
					}
					
					this.slide1 = _.$(baseId+"Img1");
					this.slide2 = _.$(baseId+"Img2");
					
					this.currObj = this.slide1;
					this.nextObj = this.slide2;
					
					_.alpha(this.nextObj,0);
					
				},
				
				nextLoop : function(){
					
					if(this.progress){
						this.next();
					}
					setTimeout(delegate( this, this.nextLoop ), this.chgInt);
					this.progress = true;
					
				},
				
				next : function (){
					
					this.currObj.style.zIndex = 0;
					this.nextObj.style.zIndex = 3;
					
					var currThumb = _.$(this.baseId+"Thumb"+this.currIndex);
					if(currThumb != null){
						_.alpha(currThumb,50);
						currThumb.style.color = "#ffffff";
						currThumb.style.backgroundColor = "#433e38";						
					}
					
					var id = this.currObj.id;
					var nextNum = this.currIndex + 1;
					
					if(nextNum == this.imgData.length){
						nextNum = 0;
					}
					
					this.currIndex = nextNum;
					
					if(currThumb != null){
						currThumb = _.$(this.baseId+"Thumb"+this.currIndex);
						_.alpha(currThumb,100);
						currThumb.style.color = "#000000";
						currThumb.style.backgroundColor = "#ffffff";
					}
					
					var data = this.imgData[this.currIndex];
					if(data.captionTxt && data.captionTxt.length > 0){
						var caption = _.$(this.baseId+"Caption");
						caption.innerHTML ='<span style="font-size:12px;color:#6ca3bd">'+
						'<span style="font-weight:bold;color:#ffffff">'+data.altTxt+'</span> '+data.captionTxt+'</span>';
					}
					
					if(data.url.length > 0){
						this.nextObj.innerHTML = '<a href="'+data.url+'"><img alt="'+data.altTxt+'" src="'+data.imgSrc+'" /></a>';						
					}else{
						this.nextObj.innerHTML = '<img alt="'+data.altTxt+'" src="'+data.imgSrc+'" />';
					}
					
					this.nextObj.style.display = 'block';
					this.fadeIn(
							this.nextObj,
							0,
							function(){
								GUI.setOpacityById(id,0);
							}
						);
					
					var temp;
					temp = this.currObj;
					this.currObj = this.nextObj;
					this.nextObj = temp;
					
				},
				
				show : function ( i ) {
					
					
					var currThumb = _.$(this.baseId+"Thumb"+this.currIndex);
					
					if( i != null){
						if(currThumb != null){
							_.alpha(currThumb,50);
							currThumb.style.color = "#ffffff";
							currThumb.style.backgroundColor = "#433e38";							
						}
						this.currIndex = i;			
					}
					
					if(currThumb != null){
						currThumb = _.$(this.baseId+"Thumb"+this.currIndex);
						currThumb.style.color = "#000000";
						currThumb.style.backgroundColor = "#ffffff";
						_.alpha(currThumb,100);
					}
					
					
					var data = this.imgData[this.currIndex];
					
					if(data != null){
						
						if(data.captionTxt.length > 0){
							var caption = _.$(this.baseId+"Caption");
							caption.innerHTML ='<span style="font-size:12px;color:#6ca3bd">'+
							'<span style="font-weight:bold;color:#ffffff">'+data.altTxt+'</span> '+data.captionTxt+'</span>';
						}
						
						if(data.url.length > 0){
							this.currObj.innerHTML = '<a href="'+data.url+'"><img alt="'+data.altTxt+'" src="'+data.imgSrc+'" /></a>';						
						}else{
							this.currObj.innerHTML = '<img alt="'+data.altTxt+'" src="'+data.imgSrc+'" />';
						}
						
					}
					
					this.progress = false;
				},
			
				
				fadingIn : false,
				
				fadeIn : function( obj , opa, callback,preFunc){
					if(preFunc){preFunc();}
					if(opa >= 100){
						this.fadingIn = false;
						_.alpha(obj,100);
						if(callback)callback();
					}else{
						this.fadingIn = true;
						_.alpha(obj,opa);
						
						var func = delegate( this, this.fadeIn );
						var rate = this.fadeRate;
						
						setTimeout(
								
								function(){func( obj , (opa+rate),callback)}	
								
								
								
								,33);
					}
				}
				
			
			
			}, 
			
			/* end slipperyBox = {} */
						
			setOpacityById : function ( id , opa ){
				_.alpha(_.$(id),opa);
			} 
			
		}; /* end GUI = {} */
		
		//install this js into the mojo frontend
		_.pushEventChain( 'onload', delegate( GUI, GUI.init ));
	}
)();

