//casting blanket
function cast_blanket(popup)
{
	var document_h = $(document).height();
	var document_w = $(window).width();
	$("<div></div>").attr({id: "blanket"}).css({height: document_h, left: 0, opacity: 0.5, position: "absolute", top: 0, width: document_w, zIndex: 100}).appendTo($("body"));
	//$("#blanket").animate({opacity: 0.5}, 400);
	if ($.browser.msie)
	{
		$("<iframe></iframe>").attr({id: "blanket_iframe"}).css({border: 0, height: document_h, left: 0, opacity: 0, position: "absolute", top: 0, width: document_w, zIndex: 99}).appendTo($("body"));
	}
	var view_width = $(window).width();
	var view_height = $(window).height();
	var popup_width = popup.width();
	var popup_height = popup.height();
	var popup_loading_left = Math.ceil((view_width - popup_width) / 2) + $(document).scrollLeft();
	var popup_loading_top = Math.ceil((view_height - popup_height) / 2) + $(document).scrollTop();
	if (Math.ceil((view_width - popup_width) / 2) < 0)
	{
		popup_loading_left = $(document).scrollLeft() + 10;
	}
	if (Math.ceil((view_height - popup_height) / 2) < 0)
	{
		popup_loading_top = $(document).scrollTop() + 10;
	}
	popup.css({left: popup_loading_left, top: popup_loading_top});
	popup.fadeIn(400, function()
		{
			// correct if outbonds
			document_h = $(document).height();
			document_w = $(window).width();
			$("#blanket").css({height: document_h, width: document_w});
			$("#blanket_iframe").css({height: document_h, width: document_w});
		}
	);
	$(window).bind("resize", function()
		{
			change_blanket();
		}
	);
	$("#blanket").live("click", function()
		{
			remove_blanket();
		}
	);
	return;
}
// changing dimensions of blanket
function change_blanket()
{
	var document_h = $("body").height();
	var document_w = $("body").width();
	$("#blanket").css({height: document_h, width: document_w});
	$("#blanket_iframe").css({height: document_h, width: document_w});
}
//castaway blanket
function remove_blanket()
{
	$("#ww_auth").fadeOut(300);
    $("#ww_auth .error").css({display : "none"});
	setTimeout(function() { $("#blanket").css({opacity: 0}); }, 300);
	setTimeout(function() { $("#blanket_iframe").remove(); }, 300);
	setTimeout(function() { $("#blanket").remove(); }, 300);
	return;
}
$(document).ready(function()
{
	$(".iepng").ifixpng();
	// submit change
	$(":submit").hover(
	function()
		{
			$(this).css({backgroundPosition : "0 -20px"});
		},
	function()
		{
			$(this).css({backgroundPosition : "0 0"});
		}
	);
	// auth window showup
	$("#m_top .auth a").bind("click", function(e)
		{
			e.preventDefault();
			cast_blanket($("#ww_auth"));
		}
	);
	$("#ww_auth .close a").bind("click", function(e)
		{
			e.preventDefault();
			remove_blanket();
		}
	);
});
