//------------------------------------------------------------------------------
// Splash Plugin v 0.9.7 [14.02.2011] !!! Modded 04.04.2011
// (C) 2010-2011 Evgeny Vrublevsky <veg@tut.by>
//------------------------------------------------------------------------------

jQuery.extend(
{
	splash: function(id, width, height)
	{
		var html =
			"<div id='"+id+"_container' style='z-index: 99999; position: absolute; top: 0; left: 0;'>"+
			"<div id='"+id+"_shadow_bkg' style='position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: #000; opacity: 0.7; 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>";
		jQuery("body").append(html);
		jQuery("#"+id+"_container").width("100%").height(jQuery(document).height()+"px");
		jQuery("#"+id).bind("reposition", function()
		{
			var top = jQuery(document).scrollTop() + (jQuery(window).height() - jQuery("#"+id+"_window").height()) / 2;
			jQuery("#"+id+"_window").attr('style', 'position: absolute; left: 50%;').css('top', parseInt(top)+"px");
			// var str = jQuery("#"+id+"_window").css("height");
			// var height = {value: parseInt(str), measure: str.replace(parseInt(str).toString(), "")};
			// if(!height.value) height = {value: jQuery("#"+id+"_window").height(), measure: "px"};
			var str = jQuery("#"+id+"_window").css("width");
			var width = {value: parseInt(str), measure: str.replace(parseInt(str).toString(), "")};
			if(!width.value) width = {value: jQuery("#"+id+"_window").width(), measure: "px"};
			jQuery("#"+id+"_window")
				.css("margin-left", parseInt(-width.value/2)+width.measure)
				/*.css("margin-top", parseInt(-height.value/2)+height.measure)*/
				;
		});
		jQuery("#"+id).bind("resize", function(e, width, height)
		{
			if(width) 	jQuery("#"+id+"_window").css("width", width);
			if(height) 	jQuery("#"+id+"_window").css("height", height);
			jQuery("#"+id).trigger("reposition");
		});
		jQuery("#"+id).bind("close", function()
		{
			jQuery("#"+id).unbind("reposition");
			jQuery("#"+id).unbind("close");
			jQuery("#"+id).remove();
			jQuery("#"+id+"_window").remove();
			jQuery("#"+id+"_shadow_bkg").remove();
			jQuery("#"+id+"_container").remove();
		});
		jQuery("#"+id+"_shadow_bkg").click(function()
		{
			jQuery("#"+id).trigger("close");
			return false;
		});
		jQuery("#"+id).trigger("resize", [width, height]);
		return jQuery("#"+id);
	}
});

