//------------------------------------------------------------------------------
// Splash Plugin v 0.9 [2009]
// (C) 2010 Evgeny Vrublevsky <veg@tut.by>
//------------------------------------------------------------------------------

jQuery.extend(
{
	splash: function(id, width, height)
	{
		var html = 
			"<div id='"+id+"_container' style='z-index: 9999; position: fixed; top: 0; left: 0; width: 100%; height: 100%; _position: absolute; _top: expression(eval(document.body.scrollTop)); _left: expression(eval(document.body.scrollLeft)); _width: expression(eval(document.body.clientWidth)); _height: expression(eval(document.body.clientHeight));'>"+
			"<div id='"+id+"_shadow_bkg' style='position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: #000; opacity: 0.7; _height: expression(eval(document.body.clientHeight)); filter:alpha(opacity=70);'></div>"+
			"<div id='"+id+"_window' style='margin: 0px; padding: 0px; border: 0; position: absolute; top: 50%; left: 50%;'><div id='"+id+"'></div>"+
			"</div>";
		$("body").append(html);
		$("#"+id).bind("reposition", function()
		{
			var str = $("#"+id+"_window").css("height");
			var height = {value: parseInt(str), measure: str.replace(parseInt(str).toString(), "")};
			if(!height.value) height = {value: $("#"+id+"_window").height(), measure: "px"};
			var str = $("#"+id+"_window").css("width");
			var width = {value: parseInt(str), measure: str.replace(parseInt(str).toString(), "")};
			if(!width.value) width = {value: $("#"+id+"_window").width(), measure: "px"};
			$("#"+id+"_window").css("margin-left", parseInt(-width.value/2)+width.measure).css("margin-top", parseInt(-height.value/2)+height.measure);
		});
		$("#"+id).bind("resize", function(e, width, height)
		{
			if(width) 	$("#"+id+"_window").css("width", width);
			if(height) 	$("#"+id+"_window").css("height", height);
			$("#"+id).trigger("reposition");
		});
		$("#"+id).bind("close", function()
		{
			$("#"+id).unbind("reposition");
			$("#"+id).unbind("close");
			$("#"+id).remove();
			$("#"+id+"_window").remove();
			$("#"+id+"_shadow_bkg").remove();
			$("#"+id+"_container").remove();
		});
		$("#"+id+"_shadow_bkg").click(function()
		{
			$("#"+id).trigger("close");
			return false;
		});
		$("#"+id).trigger("resize", [width, height]);
		return $("#"+id);
	}
});
