var minAncho = 1000;
var minAlto = 495;

var winName = "titulo";
var win = null;


var contenidoAbierto = 778;
var contenidoCerrado = 328;

var btInstPicado = null;
var btOfertaPicado = null;

//ABRIR BANDAS SUPERIORES...
function AbreCabecera()
{
	$('#bandaNegra').animate(
		{width: "100%"}, 
		{duration: 600,
		complete: function() {
			AbreGris(); 
		}
	});
}

function AbreGris()
{
	$('#bandaGris').animate(
		{height: "30px"}, 
		{duration: 400,
		complete: function() {
			AbreNavegacion(); 
		}}
	);
	
	
}

function AbreNavegacion()
{
	$('#zonaNavegacion').animate(
		{opacity: "100"}, 
		{duration: 700,
		complete: function() {
			AbreCabeceraInf();
		}}
	);
}

function AbreCabeceraInf()
{
	$('#cabeceraInf').animate(
		{opacity: '100',
		 marginTop: ['-5', 'swing']}, 
		{duration: 500,
		complete: function() {
			AbreContenido();
		}}
	);
	
	
}

function AbreContenido()
{
	$('#contenido').animate(
		{opacity: '100'}, 
		{duration: 200
		}
	);
}

/*************************
ANIMACIONES APARTADOS
*************************/
function AbreApartado() 
{
	$('#flecha' + btInstPicado).animate(
		{marginLeft: '10'}, 
		{duration: 400,
		complete: function() {
			AbreContenedor();
		}
	}
	);
}

function AbreContenedor() 
{
	$('#contenedor').animate(
		{width: '600'}, 
		{duration: 600
		}
	);
}

function AbreContenedorG() 
{
	$('#contenedor').animate(
		{width: '990'}, 
		{duration: 600
		}
	);
}


function CargaContenido(cual, idBt, idioma)
{
	if (btInstPicado != null) {
		document.getElementById("subBt" + btInstPicado).className = 'aptBt';
		document.getElementById("flecha"+ btInstPicado).style.visibility = 'hidden';
		$("#subBt" + btInstPicado ).stop().animate( { backgroundColor: '#ffffff' }, 'slow' );
		$("#texto" + btInstPicado ).stop().animate( { color: '#000000' }, 'slow' );
		$("#flecha" + btInstPicado ).stop().animate( { marginLeft: '0' }, 'slow' );
	}
	btInstPicado = idBt;
	document.getElementById("subBt" + btInstPicado).className = 'aptBtPicado';
	document.getElementById("flecha"+ btInstPicado).style.visibility = 'visible';
	
	$("#subBt" + btInstPicado ).stop().animate( { backgroundColor: '#000000' }, 'slow' );
	$("#texto" + btInstPicado ).stop().animate( { color: '#cdb68e' }, 'slow' );
	$("#flecha" + btInstPicado ).stop().animate( { marginLeft: '10' }, 'slow' );
		
	pagina = cual + '_'+ idioma +'.php';
	
	$('#contenedor').animate(
		{width: '0'}, 
		{duration: 600,
		complete: 
			function() 
			{
				/*var ajax;
				ajax = ajaxFunction();

				ajax.open("POST", pagina, true);

				ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				ajax.onreadystatechange = function()
				{
					if (ajax.readyState == 4)
					{
					document.getElementById('elContenido').innerHTML = ajax.responseText;
					
					AbreContenedor();

					}
				}
				ajax.send(null);*/
				$("#elContenido").load(pagina);
				AbreContenedor();
			}
			
		}
	);
}



function ajaxFunction() {
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		return xmlHttp;
		} catch (e) {
		// Internet Explorer
	try {
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		return xmlHttp;
		} catch (e) {
	try {
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		return xmlHttp;
		} catch (e) {
		alert("Tu navegador no soporta AJAX!");
		return false;
	}}}
}

/*************************
CARGA DE OFERTAS
*************************/
function CargaOferta(cual, idBt, idioma)
{
	if (btOfertaPicado != null) {
		document.getElementById("oferta" + btOfertaPicado).className = 'ofertaMini';
		document.getElementById("flecha"+ btOfertaPicado).style.visibility = 'hidden';
		$("#oferta" + btOfertaPicado ).stop().animate( { backgroundColor: '#ffffff' }, 'slow' );
		$("#titulo" + btOfertaPicado ).stop().animate( { color: '#000000' }, 'slow' );
		$("#flecha" + btOfertaPicado ).stop().animate( { marginLeft: '0' }, 'slow' );
	}
	btOfertaPicado = idBt;
	document.getElementById("oferta" + btOfertaPicado).className = 'ofertaMiniPicada';
	document.getElementById("flecha"+ btOfertaPicado).style.visibility = 'visible';
	$("#oferta" + btOfertaPicado ).stop().animate( { backgroundColor: '#000000' }, 'slow' );
	$("#titulo" + btOfertaPicado ).stop().animate( { color: '#cdb68e' }, 'slow' );
	$("#flecha" + btOfertaPicado ).stop().animate( { marginLeft: '10' }, 'slow' );
		
	pagina = 'noticia.php?id='+ idioma +'&numOfer=' + cual;
	
	$('#contenedor').animate(
		{width: '0'}, 
		{duration: 600,
		complete: 
			function() 
			{
				$("#elContenido").load(pagina);
				AbreContenedor();
			}
			
		}
	);
}

/*************************
ANIMACIONES SOLO DE INDEX
***************************/
function SacaBandaMarron() 
{
	$('#bandaMarron').animate(
		{width: "100%"}, 
		{duration: 600}
	);
}




function AbreN( theURL, ancho, alto )
{
    var h = (screen.width-ancho)/2;
    var v = (screen.height-alto)/2;
    var windowprops = "top=0,left=0,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes, resizable=no,width="+ancho+",height="+alto+",left="+h+", top="+v;
    
    if (win)
    {
        win.close();
    }
    
    win = window.open(theURL, winName, windowprops);
}


function Actualiza ()
{
    w = document.getElementById ('imgFondo');
	minAncho = 1000;
	minAlto = 700;
	
    if (typeof (window.innerWidth) == 'number') {
        ancho = window.innerWidth;
        alto = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        ancho = document.documentElement.clientWidth;
        alto = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        ancho = document.body.clientWidth;
        alto = document.body.clientHeight;
    }
	
	if(ancho > alto) {
		w.style.width = ancho < minAncho ? minAncho + "px" : "100%";
		w.style.height = alto < minAlto ? minAlto + "px" : "100%";
	}else {
		w.style.height = alto < minAlto ? minAlto + "px" : "100%";
		w.style.width = ancho < minAncho ? minAncho + "px" : "100%";
	}
}




function CmpIE()
{
	if( navigator.appName == "Microsoft Internet Explorer" )
	{
		version = parseFloat( navigator.appVersion.split( "MSIE" )[ 1 ] );
		
		if( version < 8 )
		{
			document.getElementById( 'avisoIE' ).innerHTML = "<img src=\"imagenes/error.png\" ><b>Su Internet Explorer est&aacute; desactualizado.</b><br>Para lograr la mejor experiencia posible usando nuestro sitio web y <b>evitar problemas de seguridad</b>, le recomendamos actualizar a una nueva <a href=\"http://www.microsoft.com/spain/windows/internet-explorer/\" target=\"_blank\" style=\"color: #333\" >versi&oacute;n de Internet Explorer</a>.";
			document.getElementById( 'avisoIE' ).className = "avisoJS";
		}
	}
}

// CAMBIA COLOR ENLACES... //
function CambiaColor( cual, estado )
{
	if( estado == "over" )
	{
		$("#"+cual ).stop().animate( { color: "#ece6d5" }, 200 );
	}
	else
	{
		$("#"+cual ).stop().animate( { color: "#cdb68e" }, 200 );
	}
}

function CambiaImg( idElemento, imagen )
{
	document.getElementById( idElemento ).src = imagen;
}

function CambiaSubBt(estado, cual) 
{
	if(cual != btInstPicado) {
		if( estado == "over" )
		{
			$("#subBt" + cual ).stop().animate( { backgroundColor: '#000000' }, 'slow' );
			$("#texto" + cual ).stop().animate( { color: '#fdfdfd' }, 'slow' );
			
		}
		else
		{
			$("#subBt" + cual ).stop().animate( { backgroundColor: '#ffffff' }, 'slow' );
			$("#texto" + cual ).stop().animate( { color: '#000000' }, 'slow' );
		}
	}
}


function CambiaOferta(cual, estado) 
{
	if(cual != btOfertaPicado) {
		if( estado == "over" )
		{
			$("#oferta" + cual ).stop().animate( { backgroundColor: '#000000' }, 'slow' );
			$("#titulo" + cual ).stop().animate( { color: '#fdfdfd' }, 'slow' );
			
		}
		else
		{
			$("#oferta" + cual ).stop().animate( { backgroundColor: '#ffffff' }, 'slow' );
			$("#titulo" + cual ).stop().animate( { color: '#000000' }, 'slow' );
		}
	}
}


//ENVIO DE FORMULARIO DE RESERVA...//
function FormuSolicitud(errorCampos, errorMail, mailOk)
{
	var campo1 = document.getElementById( 'nombre' ).value;
	var campo2 = document.getElementById( 'apellidos' ).value;
	var campo3 = document.getElementById( 'telefono' ).value;
	var campo4 = document.getElementById( 'email' ).value;
	var campo5 = document.getElementById( 'habitaciones' ).value;
	var campo6 = document.getElementById( 'adultos' ).value;
	var campo7 = document.getElementById( 'ninos' ).value;
	var campo8 = document.getElementById( 'fechaEntrada' ).value;
	var campo9 = document.getElementById( 'fechaSalida' ).value;
	var campo10 = document.getElementById( 'comentarios' ).value;
	
	

	if( campo1 == "" || campo2 == "" || campo3 == "" || campo4 == "" || campo5 == "" || campo6 == ""  || campo8 == "" || campo9 == "" )
	{
		alert( errorCampos );
		return false;
	}
	else if( campo4.length <  8 || campo4.indexOf('@',0)==-1 || campo4.indexOf('@',0)==0 || campo4.indexOf('.',0)==-1 || campo4.indexOf('.',0)==0 )
	{
		alert( errorMail );
		return false;
	}
	else
	{
		alert( mailOk );
		return true;
	}
}

function permite(elEvento, permitidos) {
  // Variables que definen los caracteres permitidos
  var numeros = "0123456789";
  var caracteres = " abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ";
  var numeros_caracteres = numeros + caracteres;
  var teclas_especiales = [8, 37, 39, 46];
  // 8 = BackSpace, 46 = Supr, 37 = flecha izquierda, 39 = flecha derecha
 
 
  // Seleccionar los caracteres a partir del parámetro de la función
  switch(permitidos) {
    case 'num':
      permitidos = numeros;
      break;
    case 'car':
      permitidos = caracteres;
      break;
    case 'num_car':
      permitidos = numeros_caracteres;
      break;
  }
 
  // Obtener la tecla pulsada 
  var evento = elEvento || window.event;
  var codigoCaracter = evento.charCode || evento.keyCode;
  var caracter = String.fromCharCode(codigoCaracter);
 
  // Comprobar si la tecla pulsada es alguna de las teclas especiales
  // (teclas de borrado y flechas horizontales)
  var tecla_especial = false;
  for(var i in teclas_especiales) {
    if(codigoCaracter == teclas_especiales[i]) {
      tecla_especial = true;
      break;
    }
  }
 
  // Comprobar si la tecla pulsada se encuentra en los caracteres permitidos
  // o si es una tecla especial
  return permitidos.indexOf(caracter) != -1 || tecla_especial;
}



function MuestraFoto() {
	$('#imgFondo').animate({
    opacity: 1,
    marginTop: '0px'
	}, 
	{
    duration: 2000,
    specialEasing: {
     marginTop: 'easeOutExpo'
    }
  });
}

function MueveSeguir(estado) 
{
	if( estado == "over" )
	{
		$("#btSeguir" ).stop().animate( { marginLeft: '20px' }, 'slow' );
	}
	else
	{
		$("#btSeguir" ).stop().animate( { marginLeft: '0px' }, 'slow' );
	}
}


function Inicia (ancho, alto, img, ver) {
    if (ver==0) {
        w = document.getElementById ('noFlash');
        w.innerHTML = "<img src=\""+img+"\" alt=\"logotipo\" border=\"0\"><br /><br />" +
            "Necesitas flash player para ver esta p&aacute;gina. " +
            "Desc&aacute;rgalo desde <a href=\"http://www.adobe.com/es/products/flashplayer/\" " +
            "target=\"_blank\">adobe.com</a>.<br>Need flash player to view this page. Please download it in " +
            "<a href=\"http://www.adobe.com/products/flashplayer/\" target=\"_blank\">" +
            "adobe.com</a>.";
    }
   
    minAncho = ancho;
    minAlto = alto;
}
