/*
Author: Jaime Cifuentes P (Cardumen.cl)
Date: Apr 2010
*/
function abreIndexAjax(){
	
		$("#aleatorio").click();
	}
$(function(){
	$("#enlaceMundoViajes").click(function(){
		$("#aleatorio").click();
		return false;
	})

			/* JCIFPA */
	//injecta flash superior de reproduccion de musica.
	$('#musica').flash({
                    'src':'medios/swf/reproaudio.swf',
                    'width':'90',
                    'height':'56',
                    'allowfullscreen':'false',
                    'allowscriptaccess':'always',
					'wmode':'transparent',
					'swliveconnect':'true'
                });
	/*$('#flash_container_azafata').flash({
                    'src':'medios/swf/videocentral.swf',
                    'width':'480',
                    'height':'580',
                    'allowfullscreen':'false',
                    'allowscriptaccess':'always',
					'wmode':'transparent',
					'swliveconnect':'true'
				});
	$('#flash_mundo_viajes').flash({
                    'src':'medios/swf/video_mundo_viajes.swf',
                    'width':'480',
                    'height':'580',
                    'allowfullscreen':'false',
                    'allowscriptaccess':'always',
					'wmode':'transparent',
					'swliveconnect':'true'
				});*/
/* end JCIFPA */
	
	
	
	// muestra/esconde submenu
/*	$("#submenu").hide();
	$("#submenu_terminos").hide();
	$(".btn_menu").click(function(){
		$("#submenu_terminos").slideUp("fast");
		$("#submenu").slideDown("fast");
	},function(){
		$("#submenu").slideUp("fast");
	});
	$(".btn_condiciones").click(function(){
		$("#submenu").slideUp("fast");
		$("#submenu_terminos").slideDown("fast");
	},function(){
		$("#submenu_terminos").slideUp("fast");
	});	
	
	//abrir enlace en un ventana nueva
	$(".tblank").click( function() {
		window.open( $(this).attr('href') );
		return false;
	});


	// customizar select
	$('#bdestinos,#bproductos').selectmenu({
		style:'dropdown',
		width: 247,
		menuWidth: 193
	});
	$('#blinks').selectmenu({
		style:'popup',
		width: 150,
		menuWidth: 140
	});
	$('#ndestinos').selectmenu({
		style:'popup',
		width: 150,
		menuWidth: 140
	});

	 //foco de imputs de búsqueda
    $('input[type="text"]').focus(function() {  
        if (this.value == this.defaultValue){  
			this.value = '';  
        }  
         if(this.value != this.defaultValue){  
             this.select();  
         }  
     });  
     $('input[type="text"]').blur(function() {  
         if ($.trim(this.value) == ''){  
             this.value = (this.defaultValue ? this.defaultValue : '');  
         }  
     }); 
	
	// muestra esconde
	$("#info .btn_abre").toggle(function(){
		$('#info').animate({'right':0});
		$(this).addClass('selected');
	},function(){
		$('#info').animate({'right':-136});
		$(this).removeClass('selected');
	});
	
	$("#promos .btn_abre").toggle(function(){
		$('#promos').animate({'left':0});
		$(this).addClass('selected');
	},function(){
		$('#promos').animate({'left':-136});
		$(this).removeClass('selected');
	});
	
	$("#nav_viajes .btn_more").toggle(function(){
		$('#nav_viajes').animate({'bottom':0});
		$(this).addClass('selected');
	},function(){
		$('#nav_viajes').animate({'bottom':-54});
		$(this).removeClass('selected');
	});

	//Fancybox
	$(".btn_consulta_puntos, .btn_convierte_puntos, .btn_contacto, .btn_busca_corpuntos, .btn_condiciones").fancybox({
		'titleShow'		    : false,
		'width'				: 500,
		'height'			: 402,
		'autoScale'			: false,
		'type'				: 'iframe',
		'overlayOpacity'	: 0.8,
		'overlayColor'		: '#000'
	});
	$(".btn_programa, .btn_faqs, .btn_facturacion").fancybox({
		'titleShow'		    : false,
		'width'				: 760,
		'height'			: 434,
		'autoScale'			: false,
		'type'				: 'iframe',
		'overlayOpacity'	: 0.8,
		'overlayColor'		: '#000'
	});
	
	//carousel viajes
	/*$('#carrusel') 
	.after('<div id="nav_carrusel">') 
	.cycle({ 
		fx:     'scrollLeft',
		speed:  'fast', 
		timeout: 5000,
		pager:  '#nav_carrusel' 
	});
	$("#pack").click();
	$("#infoweather").click();
	$("#more").click();*/

										
										 $("#submenu").hide();
											$(".btn_menu").toggle(function(){
												$("#submenu").slideDown("fast");
											},function(){
												$("#submenu").slideUp("fast");
											});
										
											// customizar select
											$('#bdestinos,#bproductos').selectmenu({
												style:'dropdown',
												width: 247,
												menuWidth: 193
											});
											$('#blinks').selectmenu({
												style:'popup',
												width: 150,
												menuWidth: 140
											});
											$('#ndestinos').selectmenu({
												style:'popup',
												width: 150,
												menuWidth: 140
											});
										
											// foco de imputs de búsqueda
											$('input[type="text"]').focus(function() {  
												if (this.value == this.defaultValue){  
												   this.value = '';  
												}  
												if(this.value != this.defaultValue){  
													this.select();  
												}  
											});  
											$('input[type="text"]').blur(function() {  
												if ($.trim(this.value == '')){  
													this.value = (this.defaultValue ? this.defaultValue : '');  
												}  
											}); 
	
											// muestra esconde
											$("#info .btn_abre").toggle(function(){
												$('#info').animate({'right':0});
												$(this).addClass('selected');
											},function(){
												$('#info').animate({'right':-136});
												$(this).removeClass('selected');
											});
											
											$("#promos .btn_abre").toggle(function(){
												$('#promos').animate({'left':0});
												$(this).addClass('selected');
											},function(){
												$('#promos').animate({'left':-136});
												$(this).removeClass('selected');
											});
											
											$("#nav_viajes .btn_more").toggle(function(){
												$('#nav_viajes').animate({'bottom':0});
												$(this).addClass('selected');
											},function(){
												if ($('#stack').hasClass('openStack') ){ 
													$('.stack>img').click();
												}
												$('#nav_viajes').animate({'bottom':-54});
												$(this).removeClass('selected');
											});
											
											//carousel viajes
											
											
											$(".btn_links").fancybox({
												'titleShow'		    : false,
												'width'				: 760,
												'height'			: 434,
												'autoScale'			: false,
												'type'				: 'iframe',
												'overlayOpacity'	: 0.8,
												'overlayColor'		: '#000'
												
											});
											
										   $(".btn_consulta_puntos, .btn_convierte_puntos").fancybox({
												'titleShow'		    : false,
												'width'				: 760,
												'height'			: 322,
												'autoScale'			: false,
												'type'				: 'iframe',
												'overlayOpacity'	: 0.8,
												'overlayColor'		: '#000'
											});
										   
											//Fancybox
	$(".btn_contacto, .btn_busca_corpuntos, .btn_condiciones").fancybox({
		'titleShow'		    : false,
		'width'				: 500,
		'height'			: 402,
		'autoScale'			: false,
		'type'				: 'iframe',
		'overlayOpacity'	: 0.8,
		'overlayColor'		: '#000'
	});
	$(".btn_programa, .btn_faqs, .btn_facturacion").fancybox({
		'titleShow'		    : false,
		'width'				: 760,
		'height'			: 434,
		'autoScale'			: false,
		'type'				: 'iframe',
		'overlayOpacity'	: 0.8,
		'overlayColor'		: '#000'
	});
	
		$(".twitter").fancybox({
		'titleShow'		    : false,
		'width'				: 280,
		'height'			: 310,
		'autoScale'			: false,
		'type'				: 'iframe',
		'overlayOpacity'	: 0.8,
		'overlayColor'		: '#000'
	});
										//	tooltip(); 

/*											$('#carrusel') 
											.after('<div id="nav_carrusel">') 
											.cycle({ 
												fx:     'scrollLeft',
												speed:  'fast', 
												timeout: 5000,
												pager:  '#nav_carrusel' 
											});*/
											
											/**********************************************/
												var openspeed = 300;
												var closespeed = 300;
												$('.stack>img').toggle(function(){
													var vertical = 0;
													var horizontal = 0;
													var $el=$(this);
													$el.next().children().each(function(){
														$(this).animate({top: '-' + vertical + 'px', left: horizontal + 'px'}, openspeed);
														vertical = vertical + 45;
														horizontal = (horizontal+.75)*2;
													});
													$el.next().animate({top: '-50px', left: '0px'}, openspeed).addClass('openStack')
													   .find('li a>img').animate({width: '50px', marginLeft: '9px'}, openspeed);
													$el.animate({paddingTop: '0'});
												}, function(){
													//reverse above
													var $el=$(this);
													$el.next().removeClass('openStack').children('li').animate({top: '50px', left: '0px'}, closespeed);
													$el.next().find('li a>img').animate({width: '55px', marginLeft: '0'}, closespeed);
													$el.animate({paddingTop: '0px'});
												});
												
												// Stacks additional animation
												$('.stack li a').hover(function(){
													$("img",this).animate({width: '56px'}, 100);
												},function(){
													$("img",this).animate({width: '50px'}, 100);
												});

											$('#dock').Fisheye(
													{
														maxWidth: 30,
														items: 'a',
														itemsText: 'span',
														container: '.dock-container',
														itemWidth: 50,
														proximity: 60,
														alignment : 'left',
														valign: 'bottom',
														halign : 'center'
													}
												);

											/**********************************************/
										
										
										
											$("#pack").click();
											$("#infoweather").click();
											$("#more").click();
											carrusel();
										 //ajaxDestino();
										 
									   

ajaxDestino();
});

function ajaxDestino(){
	$(".zeta").click(function(){
							 
							$("#tooltip").remove();
									clearInterval();
									
							$("#pack").click();
							$("#infoweather").click();
							$("#more").click();		
						
							/*$("#enlaceMundoViajes").unbind.click(function(){
							alert($("#aleatorio").attr("href"));
								$("#aleatorio").click();
								return false;
							})  */
							  
							  
							  
						//alert($(this).attr("href").split("=")[1]+"/"+$(this).attr("rel"))	  
							  $.ajax({
									   type: "POST",
									   url: $(this).attr("href"),
									   data: "destino="+$(this).attr("rel"),
									   success: function(html){
										
										
										
										
										
										$("#contenedor").html(html);
										//alert( "Data Saved: " + html );
										 $("#submenu").hide();
											$(".btn_menu").toggle(function(){
												$("#submenu").slideDown("fast");
											},function(){
												$("#submenu").slideUp("fast");
											});
										
											// customizar select
											$('#bdestinos,#bproductos').selectmenu({
												style:'dropdown',
												width: 247,
												menuWidth: 193
											});
											$('#blinks').selectmenu({
												style:'popup',
												width: 150,
												menuWidth: 140
											});
											$('#ndestinos').selectmenu({
												style:'popup',
												width: 150,
												menuWidth: 140
											});
										
											// foco de imputs de búsqueda
											$('input[type="text"]').focus(function() {  
												if (this.value == this.defaultValue){  
												   this.value = '';  
												}  
												if(this.value != this.defaultValue){  
													this.select();  
												}  
											});  
											$('input[type="text"]').blur(function() {  
												if ($.trim(this.value == '')){  
													this.value = (this.defaultValue ? this.defaultValue : '');  
												}  
											}); 
	
											// muestra esconde
											$("#info .btn_abre").toggle(function(){
												$('#info').animate({'right':0});
												$(this).addClass('selected');
											},function(){
												$('#info').animate({'right':-136});
												$(this).removeClass('selected');
											});
											
											$("#promos .btn_abre").toggle(function(){
												$('#promos').animate({'left':0});
												$(this).addClass('selected');
											},function(){
												$('#promos').animate({'left':-269});
												$(this).removeClass('selected');
											});
											
											$("#nav_viajes .btn_more").toggle(function(){
												$('#nav_viajes').animate({'bottom':0});
												$(this).addClass('selected');
											},function(){
												if ($('#stack').hasClass('openStack') ){ 
													$('.stack>img').click();
												}
												$('#nav_viajes').animate({'bottom':-54});
												$(this).removeClass('selected');
											});
											
											//carousel viajes
											
											
											$(".btn_links, .mas_detalle").fancybox({
												'titleShow'		    : false,
												'width'				: 760,
												'height'			: 480,
												'autoScale'			: false,
												'type'				: 'iframe',
												'overlayOpacity'	: 0.8,
												'overlayColor'		: '#000'
												
											});
											
										$(".btn_consulta_puntos, .btn_convierte_puntos").fancybox({
												'titleShow'		    : false,
												'width'				: 760,
												'height'			: 322,
												'autoScale'			: false,
												'type'				: 'iframe',
												'overlayOpacity'	: 0.8,
												'overlayColor'		: '#000'
											});
											
											tooltip(); 

/*											$('#carrusel') 
											.after('<div id="nav_carrusel">') 
											.cycle({ 
												fx:     'scrollLeft',
												speed:  'fast', 
												timeout: 5000,
												pager:  '#nav_carrusel' 
											});*/
											
											/**********************************************/
												var openspeed = 300;
												var closespeed = 300;
												$('.stack>img').toggle(function(){
													var vertical = 0;
													var horizontal = 0;
													var $el=$(this);
													$el.next().children().each(function(){
														$(this).animate({top: '-' + vertical + 'px', left: horizontal + 'px'}, openspeed);
														vertical = vertical + 45;
														horizontal = (horizontal+.75)*2;
													});
													$el.next().animate({top: '-50px', left: '0px'}, openspeed).addClass('openStack')
													   .find('li a>img').animate({width: '50px', marginLeft: '9px'}, openspeed);
													$el.animate({paddingTop: '0'});
												}, function(){
													//reverse above
													var $el=$(this);
													$el.next().removeClass('openStack').children('li').animate({top: '50px', left: '0px'}, closespeed);
													$el.next().find('li a>img').animate({width: '55px', marginLeft: '0'}, closespeed);
													$el.animate({paddingTop: '0px'});
												});
												
												// Stacks additional animation
												$('.stack li a').hover(function(){
													$("img",this).animate({width: '56px'}, 100);
												},function(){
													$("img",this).animate({width: '50px'}, 100);
												});

											$('#dock').Fisheye(
													{
														maxWidth: 30,
														items: 'a',
														itemsText: 'span',
														container: '.dock-container',
														itemWidth: 50,
														proximity: 60,
														alignment : 'left',
														valign: 'bottom',
														halign : 'center'
													}
												);

											/**********************************************/
										
										
										
											$("#pack").click();
											$("#infoweather").click();
											$("#more").click();
											carrusel();
										 ajaxDestino();
										 
									   }
									 });
							  return false;
							  
							  
							  });
} // end ajaxDestino
