	 
	function Lightbox(config) {
		var config = config || {};
		config.defaultWidth  = config.hasOwnProperty('width') ? config.width : 814;
		config.width         = config.defaultWidth;
		config.height        = 0;
		config.element       = config.hasOwnProperty('element') ? config.element : $j('<div id="lightbox"><div id="lightbox-close"></div><div id="lightbox-wrap"><div id="lightbox-content"></div></div></div>');
		config.overlay       = config.hasOwnProperty('overlay') ? config.overlay : $j('<div id="overlay"></div>');
		config.closeSelector = config.hasOwnProperty('closeSelector') ? config.closeSelector : '#lightbox-close';
		config.transition    = config.hasOwnProperty('transition') ? config.transition : 'grow';
		config.delay         = config.hasOwnProperty('delay') ? config.delay : 1;
		config.offsetY       = config.hasOwnProperty('offsetY') ? config.offsetY : 0;
		config.offsetX       = config.hasOwnProperty('offsetX') ? config.offsetX : 0;
			config.closeCallback = config.hasOwnProperty('closeCallback') ? config.closeCallback : false;
	
		var visible      = false;
		var created      = false;
		var content      = false;
		var link				 = false;
		var href         = false;
		var timeout      = false;
		var delayTimeout = false;
		var frameTimeout = false;
		var currentHref  = false;
		var that 				 = this;
		var frameChanged = false;
		
		// Run the open function with a user configurable delay
		this.open = function(options) {
					link = options.triggerElement;
					if( options.hasOwnProperty('closeCallback') ) {
							config.closeCallback = options.closeCallback;
					}
					if( options.hasOwnProperty('width') ) {
							config.width = options.width;
					} else {
							config.width = config.defaultWidth;
					}
	
					if( options.hasOwnProperty('height') ) {
							config.height = options.height;
					} else {
							config.height = 0;
					}
	
			delayTimeout = setTimeout( function(){
				doOpen(link);
			}, config.delay);
		}
		
		var doOpen = function(link){
					if( link.attr('href') ) {
							href = link.attr('href');
					} else {
							href = link.attr('src');
					}
			// Create the lightbox elements if they don't already exist on the page
			if( !created ) {
				// Add a close links to selected elements in the lightbox
				if( config.closeSelector ) {
					config.element.find(config.closeSelector).click(function(){
						that.close();
					});
				}
	
				content = config.element.find('#lightbox-content');
				$j('body').prepend(config.element);
				
				// Create overlay
				if( config.overlay ) {
					config.overlay.hide();
					config.overlay.css({ 
						opacity: 0,
						width:   '100%',
						height:  $j(document).height()
					});
					config.overlay.click( that.close );
					$j('body').prepend(config.overlay);
				}
				created = true;
			}
	
			if (config.overlay) {
				config.overlay.show();
				config.overlay.animate({
					opacity: 0.8
				}, 400);
			}
	
			// Hide the lightbox by setting a position far outside the window.
			// We can't hide it it with display: none because then it's height 
			// won't be available
			config.element.css({
				left:    '-1000px',
				width:   config.width 
			});
			
			// Link hasn't changed, just show the same content again
			if( href == currentHref && !frameChanged ) {
							that.show();
			}
			
			// Load src of the clicked link in the iframe and show the lightbox once the content is loaded
			else {
							// If link is an image just load the image directly into the lightbox
							if( /(gif|png|jpg|GIF|PNG|JPG)$/.test( href ) ) {
									var image = $j('<img>');
									image.load(that.show);
									image.attr( 'src', href );
									content.empty();
									content.append(image);
							}
							else {
									content.load( href + ' .lightbox-content', that.show() );
							}
			}
		}
		
		// Shows the lightbox once it has content
		this.show = function() {
			currentHref = href;
	
			// Hide selects in IE6 when the lightbox is displayed
			$j('body').addClass('hideSelects');
			
			// Get the height of the lightbox. We will grow the lightbox to this height
		if( /(gif|png|jpg|GIF|PNG|JPG)$/.test( href ) ) {
	
							//config.height = config.element.height();
					} else {
							config.height = config.element.height();
					}
			
			// Grows the lightbox out from the clicked link
			if( config.transition == 'grow' ) {
				// Set the starting position of the lightbox to the position of the link
				// that opened the lightbox, it will grow outwards from there
				config.element.css({
					top:     link.offset().top + ( link.height() / 2 ),
					left:    link.offset().left + ( link.width() / 2 ),
					width:   '1px',
					height:  '1px'  
				});
	
				// Make the lightbox grow starting from the position of the clicked link 
				// ending up on the center of the screen
				config.element.animate({
					width:   config.width + 'px',
					height:  config.height + 'px',
					left:    ( $j(document).width() / 2 ) - ( config.width / 2 ) + 'px',
					top:     60 + $j(document).scrollTop() + 'px'
				}, 300, function(){
					// Once the animation is finished reset height to auto to allow the 
					// height to grow or shrink with new content added to the lightbox later
					// (for instance after submitting a form)
					config.element.height(config.height);
					config.element.css({
						height:  'auto'  
					});
									config.overlay.css({ 
											height:  $j(document).height()
									});
				});
			}
	
			visible = true;
		}
	
		// Close the lightbox
		this.close = function(){
					config.element.css({
							height: 0  
					});
	
			if( config.overlay ) {
				config.overlay.css({ 'opacity': 0 });
				config.overlay.hide();
			}
	
			if( timeout ) {
				clearTimeout(timeout);
			}		
	
			if( frameTimeout ) {
				clearTimeout(frameTimeout);
			}		
	
			if( delayTimeout ) {
				clearTimeout(delayTimeout);
			}		
	
			config.element.css({
				left: '-1000px',
							top: '-2000px'
			});
	
			// Show selects in IE6 when the lightbox closes
			$j('body').removeClass('hideSelects');
			visible = false;
					if( config.closeCallback ) {
							config.closeCallback();
					}
		}
	}

