$.gallery = {
	initialize: function() {
		$("body").append("<div id='overlay'></div>");
		$("body").append("<div id='content_wrapper'><div id='content'></div></div>");

		width = 500;

		$("#overlay").click(function() {$.gallery.hide()});
		$("#overlay").css("opacity", 0);
		$("#overlay").css({
			position: "absolute",
			left: "0",
			top: "0",
			width: "100%",
			height: $(window).height(),
			background: "black",
			display: "none"
		});
		$(document).keydown( function( e ) {  	
			if (e == null) { // ie
				keycode = event.keyCode;
			} else { // mozilla
				keycode = e.which;
			}
			if(keycode == 27) // close
				$.gallery.hide()	
		});

		$("#content_wrapper").click(function() {$.gallery.hide()});
		
		$("#content_wrapper").css({
			position: "absolute",
			top: "100px",
			left: "0",
			width: $(document).width()
		});
		$("#content_wrapper").css("text-align", "center");

		$("#content").css({
			position: "relative",
			background: "black",
			margin: "0px auto",
			width: width,
			height: "350",
			display: "none",
			border:" 50px solid white"
		});

		$(window).scroll(function(){});
	},
	show: function(width, height, content, iframe) {
		$('html').css('overflow-y', 'hidden');
		$("#content").css({width: width, height: height});
		i_frame = iframe || false;
		$("#overlay").show();
		$("#overlay").fadeTo("medium", 0.7, function() {
		var new_top = ($(window).height() - height) / 2 + $(window).scrollTop()-50;
		$("#content_wrapper").css({top: new_top, left: 8});
		$('#overlay').css("top", $(window).scrollTop());
		$("#content").fadeIn("fast", function() {
				$.gallery.resize(width, height, function() { 
					if (! i_frame)
						$("#content").html(content);
					else  
						$("#content").html("<iframe scrolling='no' frameborder='0' style='border: 0px solid black;' width='"+width+"' height='"+height+"' src='"+content+"'></iframe>");
				})
			});
		});
	},
	hide: function() {
		$('html').css('overflow-y', 'auto');
		$('html').css('overflow-x', 'hidden');
		$("#content").fadeOut("medium", function() {
			$("#content").html("");
			$("#overlay").fadeTo("fast", 0.1, function() {
				$("#overlay").hide();
			});
		});
	},
	resize: function(width, height, callback) {
		$("#content").css({width: width, height: height});
		$("#content").animate({}, "fast", callback);
	}
};
