function retornaTamanho()
{
	var objDivTamanhoH = document.getElementById("tamy");	
	window.parent.resizeIframeGaleria(objDivTamanhoH.offsetTop);
}

function fechaDiv()
{
	window.parent.fechaGaleria();
}

function resizeIframeGaleria(h)
{
	var objImGaleria = $('imGaleria');
	var objIfGaleria = $('ifGaleria');
	
	objImGaleria.style.height = h+"px";
	objIfGaleria.style.height = objImGaleria.style.height;
	
	ajustaTamanhos();
}

function abreGaleria(query)
{
	
	var objIfGaleria = $('ifGaleria');
	var objImGaleria = $('imGaleria');
	var objBg    	 = $('bgGaleria');
	
	//window.scroll(0,0);
	
	objIfGaleria.src		   = "promocao.php"+query;	
	objImGaleria.style.display = "block";
	objBg.style.display		   = "block";
}

function fechaGaleria()
{
	var objIfGaleria = $('ifGaleria');
	var objImGaleria = $('imGaleria');
	var objBg    	 = $('bgGaleria');
	
	objBg.style.display		   = "none";
	objImGaleria.style.display = "none";
	objIfGaleria.src		   = "";
}


//Retorna x,y do scroll da página
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;
}



//Retorna o tamanho total da página
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


function ajustaTamanhos()
{
	var arrayPageSize = getPageSize();
	var largura = arrayPageSize[0];
	var altura  = arrayPageSize[1];
	
	var objIfGaleria = $('ifGaleria');
	var objImGaleria = $('imGaleria');
	var objBg    	 = $('bgGaleria');
	
	objBg.style.width  = largura+"px";
	objBg.style.height = altura+"px";
	
	if(objIfGaleria.style.height)
	{
		objImGaleria.style.height = objIfGaleria.style.height;
	}
	
	var arrayPageScroll = getPageScroll();
	var posy			= arrayPageScroll[1];
	var ydiv			= posy + (arrayPageSize[3] / 10);
	
	objImGaleria.style.top = ydiv+"px";
}

