var contextRoot;

function setContextRoot(ctxtRoot){
	contextRoot = ctxtRoot;
}

function rollOver(element, sobre, context){
	if(sobre == "in"){
		document.getElementById(element).src = context + element + "-sombra.gif";
	}else{
		document.getElementById(element).src = context + element + ".gif";
	}
}

function preloadImage(image_url){
	var i = 0;
	var image_array = new Array();

   	for(i=0; i<=image_url.length-1; i++){
   		image_array[i] = new Image();
   		image_array[i].src = image_url[i];
	}
}

/*
 * Añade a favoritos la página actual que está visitando el usuario
 */
function anadirFavorito() {
	try{
		var titulo = document.title;
		var url = document.location.href;

		if (window.sidebar && window.sidebar.addPanel){
			window.sidebar.addPanel(titulo, url,"");
		} else {
			window.external.AddFavorite(url, titulo);
		}
	}catch(err){
		alert("Esta funcionalidad no es soportada por su navegador");
	}
}

// Muestra / Oculta un div con el velo de fondo
function muestraCaja(divAMostrar, centrar, anchoCaja, altoCaja){
	var docBody = document.body;
	var total = document.getElementById("total").style;

	if (window.XMLHttpRequest) {
		total.height = docBody.scrollHeight;
		total.pixelWidth = docBody.scrollWidth;
		total.display = "block";
	}else{
		total.pixelHeight = docBody.scrollHeight;
		total.pixelWidth = docBody.scrollWidth;
		total.display = "block";
	}

	if(centrar){
		setVariablesCaja(anchoCaja, altoCaja, divAMostrar);
		checkLocationCaja();
	}

	document.getElementById(divAMostrar).style.display = "block";
}

/**
 * Valida si un string es un email válido a través de expresiones regulares
 * @param email
 *		String a validar
 * @return
 *		Booleano indicando la validez de la cadena como email
 */
function checkMail(email){
    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    return filter.test(email);
}

// Trim: espacios, tabuladores (\t) y saltos de l?nea (\r\n)
String.prototype.trim = function(){
	return this.replace(/^[\s\t\r\n]+|[\s\t\r\n]+$/g,'')
}

/**
 * Cambio de estilo al posicionarse encima del enlace o del icono de la galeria
 * @param pos
 *		Posicion del elemento a cambiar el estilo
 * @param inside
 *		Parametro que indica la situacion del cursor, dentro o fuera del elemento
 */
function mouseMove(pos,inside){
	if(inside){
		document.getElementById("bgc_" + pos).className = "fondoGaleriaIn";
		document.getElementById("url_" + pos).style.color = "#e3cfaa";
		document.getElementById("url_" + pos).style.textDecoration  = "underline";
	}else{
		document.getElementById("bgc_" + pos).className = "fondoGaleriaOut";
		document.getElementById("url_" + pos).style.color = "#e7822a";
		document.getElementById("url_" + pos).style.textDecoration  = "none";
	}
}

/**
 * Si el ancho de la foto de la galeria es superior al marco, ajusta este
 */
function adjustImage(){
	for(var actual = 1; actual <= elementos; actual++){
		var cargaImagen = false;
		var img = document.getElementById("gal_" + actual);

		if(img != null && img.width > 97){
			document.getElementById("gal_" + actual).width = "95";
		}
	}
}
