var _UB_width  = 0;
var _UB_height = 0;
var _UB_speed  = 500;



function __ub_show(_url,_width,_height)
{


	_UB_width  = _width;
	_UB_height = _height;


	$("body").append("<div id='UB_overlay'></div>");
	$("body").append("<div id='UB_window'><div id='UB_content'></div></div>");



	$("#UB_overlay").css(
	{
		background:"#333",
		width  :__ub_getWindowWidth(),
		height :__ub_getWindowHeight(),
		position:"absolute",
		top:0,
		left:0,
		"z-index":5050,
		opacity:0
	}).animate(
		{opacity: "0.5"},
		{duration: 50, complete: function()
		{

			$("#UB_content").load(_url,function()
			{
				$('#UB_window').css({ width: _UB_width,display:'block'});
				$('#UB_content').css({"width": "100%"});
				$("#UB_window").animate({opacity: 1},{duration: 400});
				$(".ibox_close").click(function()
				{
					__ub_remove();
					this.blur();
					return false;
				});
			});

		}}
	).click(__ub_remove);


	$("#UB_window").css(
	{
		"z-index":5051,
		"position" :"absolute",
		"top"      :__ub_getPositionTop(_UB_height),
		"left"     :__ub_getPositionLeft(_UB_width),
		"width"    :_UB_width,
		"height"   :_UB_height,
		"display"  :"none",
		"background":"#fff",
		"padding"   :"20px",
		"text-align":"left",
		"overflow"  :"auto",
		"overflow-x"  :"hidden",
		"opacity": "0"
	});



	$(window).resize(function(){
		$("#UB_overlay").css({
			width  :__ub_getWindowWidth(),
			height :__ub_getWindowHeight()
		});
		$('#UB_window').css({
			top  :__ub_getPositionTop(_UB_height),
			left :__ub_getPositionLeft(_UB_width)
		});

	});

}
function __ub_remove()
{

	if(document.getElementById("UB_overlay") != null)
	{

		$(".ibox_close").unbind();

		$("#UB_window").trigger("unload").unbind().remove();

		$("#UB_overlay").fadeOut("fast",function()
		{
			$("#UB_overlay").trigger("unload").unbind().remove();
		});


	}
}
function __ub_getPositionTop(_height)
{
	var top = Math.floor(($(window).height() - _height) / 2);
	var scY = $(document).scrollTop();
	return (top + scY);
}

function __ub_getPositionLeft(_width)
{
	var left = Math.floor(($(window).width()  - _width ) / 2);
	var scX  = $(document).scrollLeft();
	return (left + scX);
}
function __ub_getWindowHeight()
{
	var windowHeight;
	var yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		yScroll = document.body.offsetHeight;
	}
	if (self.innerHeight)
	{	// all except Explorer
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{	// Explorer 6 Strict Mode
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{	// other Explorers
		windowHeight = document.body.clientHeight;
	}
	if(yScroll > windowHeight){
		windowHeight = yScroll;
	}
	return windowHeight;
}
function __ub_getWindowWidth()
{
	var windowWidth;
	var xScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
	}
	if (self.innerHeight) 
	{	// all except Explorer
		if(document.documentElement.clientWidth) windowWidth = document.documentElement.clientWidth; 
		else windowWidth = self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{	// Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
	}
	else if (document.body)
	{	// other Explorers
		windowWidth = document.body.clientWidth;
	}
	if(xScroll < windowWidth){
		windowWidth = xScroll;
	}
	return windowWidth;
}


