$(document).ready(function() {
	$("table.listagem tr").mouseover(function () {
		$(this).find("div.action").parent().addClass("hover");
		$(this).find("div.action").show();
	}).mouseout(function () {
		$(this).find("div.action").parent().removeClass("hover");
		$(this).find("div.action").hide();
	});
});

function getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
};

function openModal(el, w, h) {
	if ($("#overflow").length == 0)
		$("body").append("<div id=\"overflow\"></div>");
	var maskHeight = $(document).height();
	var pageScroll = getPageScroll();
	
	$("#overflow")
		.css({'background-color':'#000','height':maskHeight,'opacity':0.8})
		.slideDown(300, function() {
			$("body").append("<div id=\"modal\"><div class=\"int\"></div></div>");
			$("#modal").prepend("<a class=\"fechar\" href=\"#\">Fechar</a>");
			var winH = $(window).height();
			var winW = $(window).width();
			$("#modal").css({'width':w,
							'height':h});
			$("#modal").css({'top':(winH/2-$("#modal").outerHeight()/2)+20+pageScroll[1],
								'left':winW/2-$("#modal").outerWidth()/2});
			
			
			$("#modal .int").css({'width':w-(parseInt($("#modal .int").css('padding-left'))*2),
								'height':h-(parseInt($("#modal .int").css('padding-left'))*2)});
			$("#modal").fadeIn(300);
			/*var fecharPT = parseInt($("#modal").css("top")) - 20;
			var fecharPR = parseInt($("#modal").css("left")) + parseInt($("#modal").outerWidth()) - 16;
			$("a.fechar").css({'top':fecharPT,'left':fecharPR});*/
			$("a.fechar").click(function() {
				$(this).remove();
				closeModal();
				return false;
			});
			$.get($(el).attr("href"),
					{},
					function(retorno) {
						$("#modal .int").append(retorno);
					});
		});
}

function closeModal() {
	$("#modal").fadeOut(300,function() {
		$("#overflow").slideUp(300,function() {
			$("#modal").remove();
			$("#overflow").remove();
		})
	})
}