/**
 * @author Sky
 */
var fadeInOutSpeed = "mid";

function checkMouse(e)
{
	var el = e.target;
	var login_block = document.getElementById("login_block");
	var search_block = document.getElementById("resSearch");

	while (true){
		if ((el == login_block) || (el == search_block)) {
			return true;
		} else if (el == document) {
			HideBlocks();
			return false;
		} else {
			el = el.parentNode;
		}
	}
};
	
function HideBlocks()
{
	$("#login_block").fadeOut(fadeInOutSpeed);
	$("#resSearch").fadeOut(fadeInOutSpeed);
	$(document).unbind('mousedown', checkMouse);
}

$(document).ready(function(){
	$("#table-srav").css("display", "table");
	$("#resSearch").css("display", "none");
	$(document).bind('mousedown', checkMouse);
	$("a[name='login_link']").click(function () {
		if ($("#login_block").css("display") == "none")
		{
			$("#login_block").fadeIn(fadeInOutSpeed);
			$(document).bind('mousedown', checkMouse);
		}
		else
			HideBlocks();
    });
});
