// AL CARGAR EL DOCUMENTO
$(document).ready(function() {
	// Alfa logos Portada
	$(".FanFacebook img").fadeTo('slow', 0.7);
	$(".FanFacebook img").mouseover(function () {
		$(this).fadeTo(300, 1);
	});
	$(".FanFacebook img").mouseout(function () {
		$(this).fadeTo('fast', 0.7);
	});
	
	// Alfa logo Facebook
	$(".LogosPortada img").fadeTo('slow', 0.6);
	$(".LogosPortada img").mouseover(function () {
		$(this).fadeTo(300, 1);
	});
	$(".LogosPortada img").mouseout(function () {
		$(this).fadeTo('fast', 0.6);
	});
	
	// Alfa logos Sponsors
	$(".Logotipos img").fadeTo('slow', 0.7);
	$(".Logotipos img").mouseover(function () {
		$(this).fadeTo(300, 1);
	});
	$(".Logotipos img").mouseout(function () {
		$(this).fadeTo('fast', 0.7);
	});
	
	// Imagen piloto
	$(".PagPilotoImg").fadeIn('slow');
	
	// Última hora
	$(".UltimaHora").fadeIn('slow');
});

// --------------------------
// 	  Selecciona una Option
// --------------------------
// Selecciona la Option de un Select que tenga el valor indicado
// - Entrada: Select y Valor
// -  Salida: Selecciona la Option correspondiente
function SelOption (Select, Valor) {
	for (i=0; i<Select.options.length; i++) {
		if (Select.options[i].value == Valor) // Si es la Elegida
			Select.selectedIndex = i;
	}
}

// --------------------------
// 	      Favoritos
// --------------------------
function Favoritos() {
	url = "http://www.luismonzon.com";
	var titulo = "Luis Monzón"; 
	var ns = "Para poner la web de Luis Monzón en tus Marcadores,\nacepta esta ventana y luego pulsa: [ Ctrl + D ]"; 
	var op = "Para poner la web de Luis Monzón en tus Preferidos de Opera, acepta esta ventana y luego pulsa: [ Ctrl + D ]";
	if (navigator.userAgent.indexOf("Opera")!=-1)
		alert (op)
	else
	{
		if (navigator.appName == "Netscape")
			alert (ns)
		else
			window.external.AddFavorite(url, titulo);
	}
}

// --------------------------
// 	      ARREGLO PNG
// --------------------------
function PNGs(){
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	
	if ((version < 7) && (version >= 5.5) && (document.body.filters)) 
	{
	   for(var i=0; i<document.images.length; i++)
	   {
		  var img = document.images[i]
		  var imgName = img.src.toUpperCase()
		  if (imgName.substring(imgName.length-3, imgName.length) == "PNG") // Si es PNG
		  {
			 var imgID = (img.id) ? "id='" + img.id + "' " : ""
			 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			 var imgStyle = "display: inline-block;" + img.style.cssText
			 imgStyle = "vertical-align: middle;" + imgStyle
			 //if (img.align == "left") imgStyle = "float:left;" + imgStyle
			 //if (img.align == "right") imgStyle = "float:right;" + imgStyle
			 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			 var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			 img.outerHTML = strNewHTML
			 i = i-1
		  }
	   }
	   if (document.getElementById('ContWeb')) // Si es con Contenido Web
	      document.getElementById('ContWeb').style.backgroundImage = "url(diseno/img/Fondo.jpg)";
	}
}

// --------------------------
// 		Tomar AJAX
// --------------------------
// Toma el Controlador de AJAX
// - Entrada: ...
// -  Salida: El Controlador de AJAX
function TomarAJAX() {
	var xmlHttp=null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

// --------------------------
// 		Respuesta Encuesta
// --------------------------
function RE(Enc, Cod) {
	window.location = './encuestas.php?E='+Enc+'&R='+Cod;
}

// --------------------------
// 		Cabecera Imágenes
// --------------------------
$(document).ready(function(){
	ImgNum = 7; // Total de imágenes
	ImgAct = 2; // Imagen actual
	// Cargamos la Imagen
	var Cargar = document.createElement('img');
	Cargar.src = "./diseno/cabeceras/Fondo"+ImgAct+".jpg";
	$('.CabLogo').fadeIn('slow');
	setInterval( function(){
		$('.CabLogo').fadeOut('slow', function() {
			$("body").css("background-image", "url('diseno/cabeceras/Fondo"+ImgAct+".jpg')");
			$('.CabLogo').fadeIn('slow');
			Aleatorio = Math.floor(Math.random()*ImgNum);
			//Aleatorio = ImgAct;
			if (Aleatorio == ImgAct)
				Aleatorio++;
			if (Aleatorio >= ImgNum)
				Aleatorio = 0;
			ImgAct = Aleatorio;
			// Cargamos la Imagen
			Cargar.src = "./diseno/cabeceras/Fondo"+ImgAct+".jpg";
		});
	}, 6000);
});

// --------------------------
// 		Galería Imágenes
// --------------------------
function Mostrar(Img, Total) {
	var CargarSig = document.createElement('img');
	if ((Img-1) > 0) { // Si hay más fotos
		$("<img />")
			.attr("src", "contenidos/galerias/"+(Img-1)+".jpg")
			.load(function(){
				$("#ImgOculta").html($(this));
		});
	}
	// Cambio de Imagen
	$('#ImagenGal').fadeOut('slow', function() {
		$('#ImagenGal').attr("src", 'contenidos/galerias/'+Img+'.jpg');
		document.getElementById('NumImgAct').innerHTML = Total-Img+1;
		$('#ImagenGal').fadeIn('slow');
	});
	document.getElementById("ImagenSig").href = 'javascript: Mostrar('+(Img-1)+', '+Total+');';
	document.getElementById("ImagenAnt").href = 'javascript: Mostrar('+(Img+1)+', '+Total+');';
	// Anterior y Siguiente
	if (Img == Total) // Si no hay Anterior
		document.getElementById("VerAnt").style.visibility = 'hidden';
	else // Si hay Anterior
		document.getElementById("VerAnt").style.visibility = 'visible';
	if (Img == 1) { // Si no hay Siguiente
		document.getElementById("VerSig").style.visibility = 'hidden';
		document.getElementById("ImagenLink").href = 'contenidos/galerias/'+Img+'.jpg';
	}
	else { // Si hay Siguiente
		document.getElementById("VerSig").style.visibility = 'visible';
		document.getElementById("ImagenLink").href = 'contenidos/galerias/'+Img+'.jpg';
	}
}

// --------------------------
// 		Ver un Vídeo
// --------------------------
function VerVideo(Idioma,CodVideo) {
	// Si se seleccionó alguno
	if (CodVideo != 0)
		window.location = './'+Idioma+'/Multimedia-'+CodVideo+'.html';
}
