// JavaScript Document
var lb = {
	unloadURL: '/lbContent/blank.php', // URL to place in iFrame when it is unloaded/closed
	lbLeft: '#leftLightbox', // left lightbox container div
	conLeft: '#leftContent', // iFrame for left content
	lbCenter: '#centerLightbox', // center lightbox container div
	conCenter: '#centerContent', // iFrame for center content
	lbRight: '#rightLightbox', // right lightbox container div
	conRight: '#rightContent', // iFrame for right content
	overlayContainer: '#overlay', // Overlay Container
	ie: false,
	ie6: false,
	
	load: function(url, position){
		var myThis = this;
		myThis.lbCurrent = myThis.findLB(position);
		
		// Placing a layer between the page and the lightbox effectively disables the page controls.
		if(position == 'center'){
			$(myThis.overlayContainer).width($('#page').width());
			$(myThis.overlayContainer).height($('#page').height());
			$(myThis.overlayContainer).show();
		}

		$(myThis.lbCurrent).fadeIn(500, function(){
			$(myThis.lbCurrent).parent().addClass(position + 'Open');
			$(myThis.lbCurrent + ' iframe').attr('src', url);
			
			// This handles the fact that IE 7/8 don't play well with png alpha transparency and fading in/out,
			//	so we use the gif background until the lightbox has faded in, then we swap it for the png.
			if(myThis.ie && !myThis.ie6){
				if(position == 'center'){
					$(myThis.lbCurrent).css('backgroundImage','url(../img/mainLightBoxBG.png)');
				} else {
					$(myThis.lbCurrent).css('backgroundImage','url(../img/lbSmallBG.png)');
				}
			}
		});
	},
	
	close: function(position){
		var myThis = this;
		myThis.lbCurrent = myThis.findLB(position);
		
		$(myThis.lbCurrent + ' iframe').attr('src', myThis.unloadURL);

		// This handles the fact that IE 7/8 don't play well with png alpha transparency and fading in/out,
		//	so we swap the png for the gif version of the background just before the lightbox fades out.
		if(myThis.ie && !myThis.ie6){
			if(position == 'center'){
				$(myThis.lbCurrent).css('backgroundImage','url(../img/mainLightBoxBG.gif)');
			} else {
				$(myThis.lbCurrent).css('backgroundImage','url(../img/lbSmallBG.gif)');
			}
		}
		
		$(myThis.lbCurrent).fadeOut(500, function(){
			if(position == 'center'){
				// Close the small lightboxes
				myThis.close('right');
				myThis.close('left');
				
				// Start the globe rendering again
				top.globeStartRender();
				
				// Remove the ovelay layer to re-enable the page controls
				$(myThis.overlayContainer).hide();
			}
			
			$(myThis.lbCurrent).parent().removeClass(position + 'Open');
		});
	},
	
	findLB: function(position){
		switch(position.toLowerCase()){
			case 'right':
				return this.lbRight;
				break;
			case 'left':
				return this.lbLeft;
				break;
			case 'center':
			default:
				return this.lbCenter;
				break;
		}
	}

};
