function replaceAll(str, de, para){
    var pos = str.indexOf(de);
    while (pos > -1){
		str = str.replace(de, para);
		pos = str.indexOf(de);
	}
    return (str);
}


// -------------- Funções Diversas ------------------

function open_window(url) {
	NovaJanela = window.open(url,"NovaJanela","toolbar=0,status=0,width=520,height=200");
	NovaJanela.focus();
}


function buscarVoos(){
	
	$("#resultadoBusca").html("<Br/><Br/>Buscando...");
    $("#formBuscaVoos").ajaxSubmit({
 	   		
        target: '',
        url: './includes/buscarVoos.php', 
        type: 'post', 
        success: function(resposta) {
    		$("#resultadoBusca").html("");
    		$("#resultadoBusca").append("<h3>Resultado da Busca</h3>");
    		$("#resultadoBusca").append(resposta);
        }
    		
    });
	
}


$(function() {
	
	// -------------- MENU ------------------
	
	
	$("#menu ul.sub li a").each(function(index) {
		$(this).css('width',($(this).parent().parent().parent().width()-9)+"px")
	});
	$("#menu ul.sub").css("display",'none');
	$("#menu ul > li a").not(".sub a").mouseover(function() {
		$("ul.sub").css("display",'none');
		$(this).next("ul.sub").css("display",'block');
	});
	$("div#menu").mouseleave(function() {
		$("ul.sub").css("display",'none');
	});
	
	
	
	
	// -------------- BACK MENU ------------------

	$("#topo #back").fadeTo(0,1);
	$("#backMenu").fadeTo(0,0.9);

	
	
	
	// -------------- SLIDESHOW ------------------
	
	if($("#slideshow .item").length>1){
		
		$("#slideshow .item").hide(0);
		$($("#slideshow .item")[0]).show(0);
		
		$('#slideshow #imagens').jqFancyTransitions({ 
			
			
			effect: 'wave', // wave, zipper, curtain
			width: 480, // width of panel
			height: 215, // height of panel
			strips: 20, // number of strips
			delay: 8000, // delay between images in ms
			stripDelay: 50, // delay beetwen strips in ms
			titleOpacity: 0.7, // opacity of title
			titleSpeed: 1000, // speed of title appereance in ms
			position: 'top', // top, bottom, alternate, curtain
			direction: 'left', // left, right, alternate, random, fountain, fountainAlternate
			navigation: false, // prev and next navigation buttons
			links: true // show images as links
		
		});
	
	}

	
	// -------------- BACKGROUND ------------------
	
	
	$($("#imgs img")[0]).attr("src","redimensiona.php?imagem=imgs/img1.jpg&a=0&max=0&l="+($("body").width()));
	$($("#imgs img")[1]).attr("src","redimensiona.php?imagem=imgs/img2.jpg&a=0&max=0&l="+($("body").width()));
	$($("#imgs img")[2]).attr("src","redimensiona.php?imagem=imgs/img3.jpg&a=0&max=0&l="+($("body").width()));
	$($("#imgs img")[3]).attr("src","redimensiona.php?imagem=imgs/img4.jpg&a=0&max=0&l="+($("body").width()));
	$($("#imgs img")[4]).attr("src","redimensiona.php?imagem=imgs/img5.jpg&a=0&max=0&l="+($("body").width()));
	$($("#imgs img")[5]).attr("src","redimensiona.php?imagem=imgs/img6.jpg&a=0&max=0&l="+($("body").width()));

	q=$("#imgs img").length;
	atual=$("#imgs img").length-1;
	$("#imgs img").fadeTo(0,0);
	
	setInterval(function(){

		//$("#imgs img").css("z-index",1);

		$($("#imgs img")[atual]).css("z-index",2);
		
		ant=atual;
		
		if((atual+1)==q){
			atual=0;
		}else{
			atual=atual+1;
		}
		
		
		$($("#imgs img")[atual]).css("z-index",3);
		$($("#imgs img")[atual]).fadeTo(1000,1,function(){$($("#imgs img")[ant]).fadeTo(0,0);});

	},17000);

	$($("#imgs img")[atual]).css("z-index",3);
	$($("#imgs img")[atual]).fadeTo(3000,1);
	
	
	
	// ---------- Imagens do Pacote ------------
	
	$(function() {
		$('#pacote #fotos a').lightBox({fixedNavigation:true});
	});
	
	
	
});



