var GB_HEIGHT = 400;
var GB_WIDTH = 400;

function GB_show(caption, url, height, width) {
	GB_HEIGHT = height || 400;
	GB_WIDTH = width || 400;
	
	$(document.body).append("<div id=\"GB_overlay\"></div><div id=\"GB_window\"><div id=\"GB_caption\"></div><a class=\"GB_hide\" href=\"#\">Close</a></div>");
	$("#GB_window a.GB_hide").click(GB_hide);
	$(window).resize(GB_position);
	
	$("#GB_window").append("<iframe id=\"GB_frame\" src=\""+url+"\" frameborder=\"0\"></iframe>");
	
	$("#GB_caption").html(caption);
	GB_position();
	
	$("#GB_overlay").css({ opacity: 0, display: "block"}).fadeTo("normal", .7);
	$("#GB_window").show();
}

function GB_hide() {
	$("#GB_window,#GB_overlay").remove();
	return false;
}

function GB_position(e) {
	var w = $(this).width(); var h = $(this).height();
	$("#GB_overlay").css({width: w, height: h});
	$("#GB_frame,#GB_window").css({width:GB_WIDTH + "px", height:GB_HEIGHT + "px"}).filter("#GB_window").height(GB_HEIGHT + $("#GB_caption").outerHeight());
	var w2 = $("#GB_window").outerWidth(); var h2 = $("#GB_window").outerHeight();
	
	windowTop = (h >= h2 ? (h - h2) / 2 : 0) + $(this).scrollTop();
	windowLeft = (w >= w2 ? (w - w2) / 2 : 0) + $(this).scrollLeft();

	$("#GB_window").css({left: windowLeft + "px", top: windowTop + "px"});
}


