// Heralsoft http://heralsoft.com
// Funciones javascript para mostrar un div de actividad
// basado en la libreria lightbox http://www.huddletogether.com/projects/lightbox2/
//
function browerWidth() {return window.innerWidth != null? window.innerWidth: document.body != null? document.body.clientWidth:null;}
function browserHeight() {return window.innerHeight != null? window.innerHeight: document.body != null? document.body.clientHeight:null;}

function insertOverlay(){
	// se inserta el div overlay al final del body
	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	// se oculta el div
	objOverlay.style.display = 'none';
	// se sobreescribe el onclick
	//bjOverlay.onclick = function() { hideOverlay(); return false; }
	objBody.appendChild(objOverlay);
	
	var objLoading = document.createElement("div");
	objLoading.setAttribute('id','loading');	
	objLoading.style.display = 'none';	
	objLoading.style.left= ((getPageSize()[0] / 2)-10)-376 + "px";
	objLoading.style.top= (getPageSize()[1] / 2)-205 + "px";
	objLoading.style.width= "732px";
	objLoading.style.height= "411px";
	objLoading.style.position='absolute';
	objBody.appendChild(objLoading);
		
	var objLoadingImage = document.createElement("img");
	objLoadingImage.setAttribute('id','loading_img');	
	objLoadingImage.setAttribute('src', '../img/oferta.png');
	objLoadingImage.setAttribute('useMap', '#img_map');
	objLoadingImage.setAttribute('border', '0');
	objLoading.appendChild(objLoadingImage);
	
	var objCapaTintineo = document.createElement("div");
	objCapaTintineo.setAttribute('id','capa_tintinea');		
	//objCapaTintineo.style.left= ((getPageSize()[0] / 2)-10)-376 + "px";
	//objCapaTintineo.style.top= (getPageSize()[1] / 2)-205 + "px";
	objCapaTintineo.style.left= "250px";
	objCapaTintineo.style.top= "250px";
	objCapaTintineo.style.width= "293px";
	objCapaTintineo.style.height= "23px";
	objCapaTintineo.style.position='absolute';
	//objLoading.appendChild(objCapaTintineo);
	
	var objCapaTintineoImg = document.createElement("img");
	objCapaTintineoImg.setAttribute('id','capa_tintinea_img');	
	objCapaTintineoImg.setAttribute('src', '../img/oferta_animacion.gif');	
	objCapaTintineoImg.setAttribute('border', '0');
	//objCapaTintineo.appendChild(objCapaTintineoImg);
	
	
	var objMap = document.createElement("map");
	objMap.setAttribute('id','img_map');
	objMap.setAttribute('name', 'img_map');	
	objBody.appendChild(objMap);
	
	var objArea = document.createElement("area");
	objArea.setAttribute('id','loading_img_map_area');
	objArea.setAttribute('shape', 'rect'); 
	objArea.setAttribute('coords', '723,83,749,103');
	//objArea.setAttribute('coords', '695,167,725,197');
	objArea.setAttribute('href', '#');
	objArea.onclick=function() { hideOverlay(); return false; }
	objArea.setAttribute('alt', 'Cerrar oferta');
	objArea.setAttribute('title', 'Cerrar oferta');
	objMap.appendChild(objArea);
}


function showOverlay(){
	// insercion segura
	if ($('overlay')==null){
		insertOverlay();	
	}
	hideSelectBoxes();// se esconde las select para IE
	
	// se redimensiona el div de overlay    	
	$('overlay').style.height = getPageSize()[1] +"px";
	$('loading').style.height = getPageSize()[1] +"px";
	new Effect.Appear('overlay', { duration: 0.5, from: 0.0, to: 0.5 });
	new Effect.Appear('loading', { duration: 0.5, from: 0.0, to: 1 });	
}


function hideOverlay(){
	//Element.hide('oferta');
	new Effect.Fade('overlay', { duration: 0.5, from: 0.5, to: 0.0 });
	new Effect.Fade('loading', { duration: 0.5, from: 1, to: 0.0 });
	showSelectBoxes();
	//Element.hide('overlay');	
}



/* funciones de utilidad */

// oculta todas las selects ya que el explorer las muestra por encima
// del div de overlay
function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

function showSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}
// Funcion "prestada" que retorna el tamaño del navegador en un array
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
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){ // 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
		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;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


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

