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(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("mapa.php",
					{},
					function(retorno) {
						$("#modal .int").append(retorno);
						initializeGoogleMaps();
						$(window).unload( function () { GUnload(); } );
					});
		});
}

function closeModal() {
	$("#modal").fadeOut(300,function() {
		$("#overflow").slideUp(300,function() {
			$("#modal").remove();
			$("#overflow").remove();
		})
	})
}

/*** COMO CHEGAR - GOOGLE MAPS ***/
function initializeGoogleMaps() {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("googleMaps"));
		map.setCenter(new GLatLng(-25.429525, -49.320750), 15);
		var point = new GLatLng(-25.429525, -49.320750);
		map.addOverlay(new GMarker(point));
		map.setUIToDefault();
	}
}

window.onload = function() {
	$('.bt-cadastro').click(function() {
		$(this).fadeOut(300);
		$("#frmCadastro").slideDown(300);
		return false;
	});
	$('.bt-mapa').click(function() {
		openModal(553, 524);
		return false;
	});
}
