
function shadeClose()
{
	var wrapper = $("#shade_wrapper");
	$.cookie ( "shade_cookie", "closed", { expires: 14 } );
	wrapper.animate ( { opacity: 0 }, 350, function() { wrapper.remove(); } );
	return false;
}

function shadeComplete()
{
	var background = $("#shade_background");
	var content = $("#shade_content");
	$.cookie ( "shade_cookie", "closed", { expires: 14 } );
	background.animate ( { opacity: 0.5 }, 250 );
	content.animate ( { opacity: .25 }, 250 );
	return true;
}



$(document).ready(function(){
	if ( $.cookie ( "shade_cookie" ) == null )
	{
		$("head").append ( "<link rel='stylesheet' type='text/css' href='/apps/shade/shade.css?" + Math.random() + "' />" );
		$("body").append ( "<div id='shade_wrapper'><div id='shade_background'></div><div id='shade_content_wrapper'><a id='shade_close' href='#'>Close&nbsp;X</a><div id='shade_content'></div></div></div>" );
		var wrapper = $("#shade_wrapper");
		var background = $("#shade_background");
		var content_wrapper = $("#shade_content_wrapper");
		var content = $("#shade_content");
		var sclose = $("#shade_close");
		background.css ( { opacity: 0 } );
		content_wrapper.css ( { opacity: 0, width: 0 } );
		background.click(function(){return shadeClose();});
		sclose.click(function(){return shadeClose();});
		content.load ( "/apps/shade/content.html", function(){
			setTimeout(function(){
				content_wrapper.css ( { width: content.width() } );
				$(".shade_complete").each(function(){
					$(this).click(function(){
						return shadeComplete();
					});
				});
				setTimeout ( function(){
					background.animate ( { opacity: 0.3 }, 500 );
					content_wrapper.animate ( { opacity: 1 }, 1000 );
				}, 1000 );
			}, 250 );
		});
	};
});
