var divShadow;
var divBoxZoom;

function openLayer(urlLoad, w, h){
	obj = document.getElementById("cidade");
	if (obj!=null) {
		obj.style.display="none";
	}
	pageScrollBeforeZoom = getPageScroll();

	var pageSize = getPageSize();
	var pageScroll = getPageScroll();

	divShadow = document.createElement('div');
		divShadow.className = 'boxFade';
		divShadow.style.height = ((pageSize.windowHeight>pageSize.pageHeight)? pageSize.windowHeight : pageSize.pageHeight)+"px";
		divShadow.style.width = pageSize.windowWidth+"px";
		divShadow.onclick=closeLayer;
	document.body.appendChild(divShadow);
	
	divBoxZoom = document.createElement('div');
		divBoxZoom.className = 'boxZoom';
		divBoxZoom.style.width = w+"px";
	
		divBoxZoom.style.height = h+"px";
		var pLeft = (pageSize.pageWidth - w)/2;
		var pTop = ((pageSize.windowHeight - h)/2) + pageScroll.yScroll;
		divBoxZoom.style.left = pLeft+"px";
		divBoxZoom.style.top = pTop+"px";
		divBoxZoom.onclick=closeLayer;
	/*
	imgZoom = document.createElement('img');
		imgZoom.src = urlLoad;
		divBoxZoom.appendChild(imgZoom);
	*/
	document.body.appendChild(divBoxZoom);
	//AJAX load com JQuery
	
	$(".boxZoom").load(urlLoad);
	//onresize adicionar redimensionamento de bg e reposicionamento do conteudo
	//$(window).resize(adaptaDimensoesLayer);
	$(window).bind("resize", adaptaDimensoesLayer);
}


function adaptaDimensoesLayer() {
	var pageSize = getPageSize();
	var pageScroll = getPageScroll();

	divShadow.style.height = ((pageSize.windowHeight>pageSize.pageHeight)? pageSize.windowHeight : pageSize.pageHeight)+"px";
	divShadow.style.width = pageSize.windowWidth+"px";
	
	var pLeft = (pageSize.pageWidth - divBoxZoom.offsetWidth)/2;
	var pTop = ((pageSize.windowHeight - divBoxZoom.offsetHeight)/2) + pageScroll.yScroll;
	divBoxZoom.style.left = pLeft+"px";
	divBoxZoom.style.top = pTop+"px";
}


function closeLayer(){
	obj = document.getElementById("cidade");
	if (obj!=null) {
		obj.style.display="";
	}
	divShadow.parentNode.removeChild(divShadow);
	divBoxZoom.parentNode.removeChild(divBoxZoom);
	$(window).unbind("resize", adaptaDimensoesLayer);
	if(link_fecha_layer){
		location.href = "../rhonline/vagas-lista.php?tipo="+tipo;
	}
}

	function getPageSize() {
		var xScroll, yScroll;
		if (window.innerHeight && window.scrollMaxY) {
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight) {
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else {
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		var windowWidth, windowHeight;
		if (self.innerHeight) {
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) {
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
		if(yScroll < windowHeight) pageHeight = windowHeight;
			else pageHeight = yScroll;
		if(xScroll < windowWidth) pageWidth = windowWidth;
		else pageWidth = xScroll;
		objPageSize = {pageWidth:pageWidth,pageHeight:pageHeight,windowWidth:windowWidth,windowHeight:windowHeight}
		return objPageSize;
	}

	function getPageScroll(){
		var yScroll;
		if (self.pageYOffset) yScroll = self.pageYOffset;
			else if (document.documentElement && document.documentElement.scrollTop) yScroll = document.documentElement.scrollTop;
		else if (document.body) yScroll = document.body.scrollTop;
		arrayPageScroll = {yScroll:yScroll};
		return arrayPageScroll;
	}