$.gallery = {
	initialize: function() {
		$("body").append("<div id='overlay' style='z-index: 11;'></div>");
		$("body").append("<div id='content_wrapper' style='z-index: 12;'><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(){
			//var new_top = ($(window).height() - $("#content_wrapper").height()) / 2 + $(window).scrollTop();
			//$('#overlay').css("top", $(window).scrollTop());
			//$("#content_wrapper").css("top", new_top);
		});
	},
	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.9, 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');
		$("#content").fadeOut("fast", function() {
			$("#content").html("");
			$("#overlay").fadeTo("fast", 0.1, function() {
				$("#overlay").hide();
			});
		});
	},
	resize: function(width, height, callback) {
	//	$("#content").css({});
		$("#content").animate({vwidth: width, height: height}, "fast", callback);
	}
}

