(function($){
	$.extend({
		lightbox: function(options){
			var defaults = {
				url:'http://www.google.com',
				width:400,
				height:400,
				closeText:'Close',
				prefix:'iframeLightBox'
			};		
			
			var options = $.extend(defaults, options),
			$window,
			$overlay,
			$iframe,
			$wrapper,
			$close;

			function $div(id,css){
				name = options.prefix + id;
				id = id ? ' id="' + options.prefix + id + '"' : '';
				css = css ? ' style="' + css + '"' : '';

				$('body').append('<div ' + id + css + '/>');

				return $('#' + name);
			}
			
			function init(){
				$window =  $(window);
				$overlay = $div('Overlay');
				$wrapper = $div('Wrapper');				
				
				$iframe = $('<iframe frameBorder="0" scrolling="true" />').attr('src', options.url).appendTo($wrapper);
				
				$overlay.click(function(){ close(); });
				$wrapper.css({width:options.width, height:options.height});
				$close = $div('Close').html(options.closeText)					
					.appendTo($wrapper)
					.click(function(){ close(); });


				//resize
				resize();
				
				$window.bind('resize', resize);
			}

			function resize(){
				$wrapper.css({left:($window.width() - $wrapper.outerWidth(true))/2, top:($window.height() - $wrapper.outerHeight(true))/2});
				$close.css({width:$wrapper.outerWidth(true), textAlign:'right'});
			}

			function close(){
				$overlay.remove();
				$iframe.remove();
				$close.remove();
				$wrapper.remove();
			}

			init();
		}
	});
})(jQuery);
