// JavaScript Document

//Determina la resolución de pantalla
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;
}

//Muestra u oculta el overlay de log-in
function switchOverlay() {

	var overlay = document.getElementById("overlay");
	
	if (overlay.style.visibility == 'visible') {
		
		overlay.style.visibility = 'hidden';

	} else if (overlay.style.visibility == 'hidden') {

		arrayPageSize = getPageSize();

		overlay.style.visibility = 'visible';
		overlay.style.height = arrayPageSize[1]+"px";

	}

}

//Muestra la ventana contenedora de la capa de log-in
function switchMessageWindow(size, top, id) {
	
	if (typeof size == "undefined") {
		size = "400";
	}
	if (typeof top == "undefined") {
		top = "70";
	}
	
	var arrayPageSize = getPageSize();
	//var margen = arrayPageSize[1] - top;
	
	switch (id){
		case 'loginwindow':
			var selectedwindow = document.getElementById("loginwindowcontainer");
			var destino = document.getElementById("loginwindow");
			selectedwindow.style.top = top+"px";
			break;
		case 'photowindow':
			var selectedwindow = document.getElementById("photowindowcontainer");	
			var destino = document.getElementById("photowindow");
			selectedwindow.style.top = top+"px";
			break;
	}
	
	if (selectedwindow.style.visibility == 'visible') {
		selectedwindow.style.visibility = 'hidden';
	} else if (selectedwindow.style.visibility == 'hidden') {
		destino.style.width	= size + 'px';
		selectedwindow.style.visibility = 'visible';
	}
}