$(document).ready(function(){
	
	//GLOBAL STOP VARS
	var clearQueue = true;
	var gotoEnd = true;
	
	$('#mainNavbar li a').hover(
		function() { $(this).parent('li').children('div').fadeIn(300); },
		function() { $(this).parent('li').children('div').stop(gotoEnd,clearQueue).fadeOut(300); }
	);
	
	$('.headerTabs').hover(
		function() { $(this).children('li').children('ul').fadeIn(250); },
		function() { $(this).children('li').children('ul').stop(gotoEnd,clearQueue).fadeOut(250); }
	);
	
});


function cargarBannerPrincipal (){
//Set Default State of each portfolio piece
	$(".paging").show();
	$(".paging a:first").addClass("active");
		
	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidth = $(".window").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$(".image_reel").css({'width' : imageReelWidth});
	
	//Paging + Slider Function
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$(".paging a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		//alert(image_reelPosition)
		$(".image_reel").animate({ 
								 
			left: -image_reelPosition
		}, 500 );
		
	}; 
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = $('.paging a.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 6000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	
	//On Click
	$(".paging a").click(function() {	
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});	
}

function fVerDestinos(d){
	for(var i=1;i<=4;++i){
		$('#destinos-'+i).hide();
	}
	$('#destinos-'+d).show();
}

function cargarGaleriaProducto(){
	$('ul#portfolio').innerfade({
			speed: 1000,
			timeout: 2000,
			type: 'sequence',
			containerheight: '257px'
	});	
}


function enviarNewsletter(){

	d = document.formularioNewsletter;

	error = '';

	error += completo(d.newsletterEmail,'E-Mail');	
	error += emailvalido(d.newsletterEmail,'E-Mail');
	
	
	
	if(error!=''){

		alert("FORMULARIO INCOMPLETO:\n"+error);

	}else{
		
		$('#registroNewsletter').load('/newsletter_envio.php',{newsletterEmail: d.newsletterEmail.value});
		
		
		
	}
	d.newsletterEmail.value='E-mail';
}


function productoPrograma(codigo){
	//$('#cargadorSolapas').load('/detalle_programa.php',{codigo: codigo});
}
function productoItinerario(codigo){
	$('#btnConsultar').show();	
	$('#cargadorSolapas').load('/detalle_itinerario.php',{codigo: codigo});
}
function productoExcursiones(codigo){
	$('#btnConsultar').show();	
	$('#cargadorSolapas').load('/detalle_excursiones.php',{codigo: codigo});
}
function productoHoteles(codigo){
	$('#cargadorSolapas').load('/detalle_hoteles.php',{codigo: codigo});
	$('#btnConsultar').show();
}
function productoContacto(codigo){
	
	$('#btnConsultar').hide();
	$('#cargadorSolapas').load('/detalle_contacto.php',{codigo: codigo}, function() {
	  	$('#desde').datepicker();
		$('#hasta').datepicker()
	});
}




function mostrarExcursionItinerario(cual) {
$('#flotanteItinerario'+cual).show(500);
}

function cerrarExcursionItinerario(cual) {
$('#flotanteItinerario'+cual).hide(200);
}

function ampliarExcursion(cual) {
$('#bajadaExcursionCorta'+cual).hide();
$('#btnAmpliar'+cual).hide();
$('#bajadaExcursionLarga'+cual).show();
}
function ocultarExcursion(cual) {

$('#bajadaExcursionCorta'+cual).show();
$('#btnAmpliar'+cual).show();
$('#bajadaExcursionLarga'+cual).hide();
}

function cargaTabs(d){	
	for(var i=1;i<=3;++i){
		$('#tab-pack-'+i).hide(0);	
		$("#menuTabs").removeClass("tabs"+i);
		
		$("#tab-link-"+i).addClass("inactive");	
		
	}
	$("#tab-link-"+d).removeClass("inactive");
	
	$("#menuTabs").addClass("tabs"+d);
	$('#tab-pack-'+d).show(500);		
	$("#tab-link-"+d).addClass("activo");
}

function cambiarEstadoTabDetalle(d){
		
	for(var i=1;i<=5;++i){			
		$("#tabDetails"+i).removeClass("active");		
		$("#tabDetails"+i).addClass("inactive");		
		
	}
	$("#tabDetails"+d).addClass("active");	
}

function enviarConsultaDetalle(){

	d = document.formulario;

	error = '';

	error += completo(d.nombre,'Nombre y Apellido');
	error += completo(d.email,'E-Mail');
	error += emailvalido(d.email,'E-Mail');
	error += completo(d.desde,'Fecha probabla del viaje desde');
	error += completo(d.mayores,'Cantidad de pasajeros mayores');
	error += completo(d.menores,'Cantidad de pasajeros menores');
	error += completo(d.ciudad,'Ciudad');
	
	if(error!=''){

		alert("FORMULARIO INCOMPLETO:\n"+error);

	}else{
		d.submit();
	}
}

function selectInput(campo,texto){
 if(campo.value==texto){
  campo.value="";
  }
}

function deselectInput(campo,texto){
  if(campo.value==''){
	campo.value=texto;
  }
}


function validarContactenos(){
	d = document.formContactenos;
	error = '';
	error += completo(d.nombre,'NOMBRE Y APELLIDO');
	error += completo(d.email,'CORREO ELECTRONICO');
	error += emailvalido(d.email,'CORREO ELECTRONICO');
	error += completo(d.telefono,'TELEFONO');
	error += completo(d.desde,'FECHA DE VIAJE DESDE');
	error += completo(d.hasta,'FECHA DE VIAJE HASTA');
	error += completo(d.ciudad,'CIUDAD DE ORIGEN');
	error += completo(d.mensaje,'MENSAJE');
	
	if(error!=''){ alert("FORMULARIO INCOMPLETO:\n"+error); }else{ d.submit(); }
}

function fPaises(){
	var seleccionados = '0'
	var fld='paises[]';
	var f = document.formArmeViaje
	for (var i=0; i<f.length; i++){
		var obj = f.elements[i]
		var name = obj.name
		if (name==fld) {
			if(obj.checked){
				seleccionados = seleccionados+','+obj.value;
			}
		}
	}
	//alert(seleccionados)
	
	$('#arme_destinos').load('_arme_su_viaje_destinos.php',{paises: seleccionados});
	//$('#arme_hoteles').load('_arme_su_viaje_hoteles.php',{destinos: 0});
	//$('#arme_excursiones').load('_arme_su_viaje_excursiones.php',{destinos: 0});
	
}
function fDestinos(){
	var seleccionados = '0'
	var fld='destinos[]';
	var f = document.formArmeViaje
	for (var i=0; i<f.length; i++){
		var obj = f.elements[i]
		var name = obj.name
		if (name==fld) {
			if(obj.checked){
				seleccionados = seleccionados+','+obj.value;
			}
		}
	}
	//alert(seleccionados)
	
	$('#arme_hoteles').load('_arme_su_viaje_hoteles.php',{destinos: seleccionados});
	$('#arme_excursiones').load('_arme_su_viaje_excursiones.php',{destinos: seleccionados});
	
}

function fPaisesH(){
	var seleccionados = '0'
	var fld='paises[]';
	var f = document.formArmeViaje
	for (var i=0; i<f.length; i++){
		var obj = f.elements[i]
		var name = obj.name
		if (name==fld) {
			if(obj.checked){
				seleccionados = seleccionados+','+obj.value;
			}
		}
	}
	//alert(seleccionados)
	
	$('#arme_destinos').load('_hoteles_destinos.php',{paises: seleccionados});
	
}

function mostrarHoteles(cual) {
	$('#'+cual).show();
}
function validarArmeViaje(){
	d = document.formArmeViaje;
	error = '';
	error += completo(d.nombre,'NOMBRE Y APELLIDO');
	error += completo(d.email,'E-MAIL');
	error += emailvalido(d.email,'E-MAIL');
	error += completo(d.telefono,'TELEFONO');	
	error += completo(d.ciudad,'CIUDAD DE RESIDENCIA');
	error += completo(d.mensaje,'MENSAJE');
	
	if(error!=''){ alert("FORMULARIO INCOMPLETO:\n"+error); }else{ d.submit(); }
}

function mostrarMensajeGraciasNewsletter(){
	
	$.fancybox(
		'<h2>&iexcl;Gracias por suscribirte a nuestras novedades!</h2><p>En breve recibir&aacute;s noticias y nuevas en ofertas en tu correo.</p>',
		{
			'autoDimensions'	: false,
			'width'         		: 450,
			'height'        		: 'auto',
			'transitionIn'		: 'true',
			'transitionOut'		: 'none'
		}
	);
	
}

function mostrarMensajeGracias(){
	
	$.fancybox(
		'<h2>Gracias,</h2><p>su mensaje ha sido enviado.</p>',
		{
			'autoDimensions'	: false,
			'width'         		: 350,
			'height'        		: 'auto',
			'transitionIn'		: 'true',
			'transitionOut'		: 'none'
		}
	);
	
}


function enviarClientes(){

	d = document.formularioClientes;
	error = '';
	error += completo(d.email,'E-Mail','E-Mail');	
	error += emailvalido(d.email,'E-Mail','E-Mail');
	error += completo(d.propuesta,'Propuesta','Propuesta');
		
	if(error!=''){
		alert("FORMULARIO INCOMPLETO:\n"+error);
	}else{
		d.submit();
	}
}

function validarBuscar(){

	d = document.formularioBuscar;
	error = '';
	error += completo(d.buscar,'Palabra o frase a buscar');	
	
	if(error!=''){
		alert("FORMULARIO INCOMPLETO:\n"+error);
	}else{
		d.submit();
	}
}

function abrirOcultarExcursionBuscador(cual){

	
	if ($('#excursionBajada'+cual).is(":hidden")) {
		$('#excursionBajada'+cual).show(100);
			
	} else {
			$('#excursionBajada'+cual).hide(0);
	   }	
	
	
}
function abrirOcultarSeccionBuscador(cual){

	
	if ($('#seccion'+cual).is(":hidden")) {
		$('#seccion'+cual).show();
			
	} else {
			$('#seccion'+cual).hide();
	   }	
	
	
}
function popup(url,ancho,alto,id,extras){
	if(navigator.userAgent.indexOf("Mac")>0){ancho=parseInt(ancho)+15;alto=parseInt(alto)+15;}
	var left = (screen.availWidth-ancho)/2;
	var top = (screen.availHeight-alto)/2;
	if(extras!=""){extras=","+extras;};
	var ventana = window.open(url,id,'width='+ancho+',height='+alto+',left='+left+',top='+top+',screenX='+left+',screenY='+top+extras);
	var bloqueado = "AVISO:\n\nPara ver este contenido es necesario que desactive\nel Bloqueo de Ventanas para este Sitio."
	if(ventana==null || typeof(ventana.document)=="undefined"){ alert(bloqueado) }else{ return ventana; };
}

function cargarListado(codigo,orden,pagina){
	if(codigo==55){
		$('#tripListingContainer').load('/listados_argentina.php',{codigo: codigo,orden:orden,pagina:pagina});
		
	}else if (codigo==56){
		$('#tripListingContainer').load('/listados_patagonia.php',{codigo: codigo,orden:orden,pagina:pagina});
	}else{
	
	$('#tripListingContainer').load('/listados.php',{codigo: codigo,orden:orden,pagina:pagina});
	}
}
