$(document).ready(function(){
			
  // slide para a index
  $("#slider").easySlider();
	
	/**
	 * Carrega fundos do menu
	*/
	
	var urlFundos2 = 'resps/get_fundos.php';
	$('.fundo_investimento').empty();
	$('.fundo_investimento').load(urlFundos2);	
	
	/**
	 * TRECHo para colocar efeito na newsletter
	 *
	*/
	$('#menu ul li#menu_topo_produtos').hover(
													function(){
														//$(this).parent().find('#childen').show('slow');
														$(this).parent().find('#childen').slideDown('slow');
														//$(this).parent().find('#childen').hover(function(){}, function(){$(this).slideUp('slow');})
													},
													function(){
														$(this).parent().find('#childen').slideUp('slow');
													}
													);
   // texto padrao para o nome e o email da newsletter
   var nomeDef = $("#news_right_name").val();
	 var emailDef = $("#news_right_email").val();
	 var news_home = $("#email").val();
	 
	 // altera newsletter somenta na home
	 //altera o texto quando recebe e perde o foco
   $("#email").focusin(function() {
			// verifica se eh o texto padrao e remove
			if ($(this).val()== news_home){
				
				$(this).val(function(index, value) {
					return '';
				});
				
			}
   }).focusout(function() {
			// se estive vazio retorna o texto padrao 
			if ($(this).val()=='' || $(this).val()== null || $(this).val() == ' '){
				
				$(this).val(function(index, value) {
					return news_home;
				});
				
			}
   });
	  
	 // altera newsletter em todas as paginas 	
   //altera o texto quando recebe e perde o foco
   $("#news_right_name").focusin(function() {
			// verifica se eh o texto padrao e remove
			if ($(this).val()== nomeDef){
				
				$(this).val(function(index, value) {
					return '';
				});
				
			}
   }).focusout(function() {
			// se estive vazio retorna o texto padrao 
			if ($(this).val()=='' || $(this).val()== null || $(this).val() == ' '){
				
				$(this).val(function(index, value) {
					return nomeDef;
				});
				
			}
   });
	
   //altera o texto quando recebe e perde o foco
   $("#news_right_email").focusin(function() {
			// verifica se eh o texto padrao e remove
			if ($(this).val()== emailDef){
				
				$(this).val(function(index, value) {
					return '';
				});
				
			}
   }).focusout(function() {
			// se estive vazio retorna o texto padrao 
			if ($(this).val()=='' || $(this).val()== null || $(this).val() == ' '){
				
				$(this).val(function(index, value) {
					return emailDef;
				});
				
			}
   });
	
  /**
    * Trecho para colocar o efeito de abas na pagina de fundos
    *
    */
	$("#conteudo_2").hide();
	$("#conteudo_3").hide();
	$('.bottom_box').hide(); // oculta a box de rodape
	
	// quando clicar na aba mudar o conteudo usando-se de efeitos
	$("li.tab").click(function () {
		
		// switch all tabs off
		$(".active").removeClass("active");
		
		// switch this tab on
		$(this).addClass("active");
		
		// slide all content up
		$(".conteudo").slideUp();
		
		// slide this content up
		var content_show = $(this).attr("title");
		$("#"+content_show).slideDown();
		
		return false;

	});
		
		/**
		 * Trecho para colocar o efeito no menu do topo
		 *
		 */
		// imagem padrao que sera carregada
						
    //$('#conteudo_1').load(urlFundo);
		
		// quando passar o mouse no primeiro item muda a imagem 
//		$("#afia01").mouseover(function(){
//				
//			$("#menu_image").css('background-image', 'url(images/atual_fia1.jpg)');
//			
//			var url = new String($("#afia01 a").attr('href'));
//			idFundo = url.split('#')[1];
//      var urlObj_Fundo = 'resps/objetivo.php?idFundo='+idFundo+'&c=200';
//			$("#menu_image_txt").load(urlObj_Fundo);
//			txtPadrao = $("#menu_image_txt").text();
//			
//		// quando tirar o mouse do primeiro item volta para a imagem padrao 
//		}).mouseout(function(){
//				
//			$("#menu_image").css('background-image',imgDef);
//			$("#menu_image_txt").text(txtPadrao);
//			
//		});
//						
//		// quando passar o mouse no segundo item muda a imagem 
//		$("#afia02").mouseover(function(){
//				
//			$("#menu_image").css('background-image','url(images/atual_fia2.jpg)');
//			var url = new String($("#afia02 a").attr('href'));
//			idFundo = url.split('#')[1];
//      var urlObj_Fundo = 'resps/objetivo.php?idFundo='+idFundo+'&c=20';
//			$("#menu_image_txt").load(urlObj_Fundo);
//			
//		// quando tirar o mouse do segundo item volta para a imagem padrao 
//		}).mouseout(function(){
//				
//			$("#menu_image").css('background-image',imgDef);
//			$("#menu_image_txt").text(txtPadrao);
//			
//		});
//    
//		// carrega o primeiro item por padrao
//    $("#afia01").mouseover();
//		
//    var imgDef = $("#menu_image").css('background-image');
//		var txtPadrao = $("#menu_image_txt").text();
		
    /**
		 * Trecho para puxar o fundo aberto
		 *
		 */
		function carregarFundo(){
				
				var idFundo = 0;
				var filtro_url = new RegExp("#");
		
				if(filtro_url.test(window.location.href)){
						
						idFundo = window.location.href.split('#')[1];
						var urlFundo = 'resps/fundoVisualizar.php?idFundo='+idFundo;
						var urlDoc = 'resps/fundoDocumentos.php?idFundo='+idFundo;
						//alert(urlFundo);
						$('#conteudo_1').load(urlFundo);
						$('#conteudo_3').load(urlDoc);
						
						//window.location.href='fundo_de_investimentos_resumo.html#'+idFundo;
						
				} else {
						
						// exibir mensagem de erro caso nao consiga exibir o fundo
						var conteudoErro = '<p>Nao foi possivel carregar o conteudo desse fundo</p>';
						
						$('#conteudo_1').html(conteudoErro);
						
				}
				
		}
		// ao abrir a pagina ja carrega o fundo
    var filtro_url2 = new RegExp("#");
		
		if(filtro_url2.test(window.location.href)){
				carregarFundo();
		}
		var url = window.location.href;
		// quando clicar no fundo carrega o fundo 
		$('#fundoinvest_link01').click(function(){
			
				window.location.href = '';
				window.location.href = $(this).attr('href');
				//setTimeout("window.location.reload(true)", 1000);
				carregarFundo();		
				
    });
		$('#fundoinvest_link02').click(function(){
			
				window.location.href = '';
				window.location.href = $(this).attr('href');
				//setTimeout("window.location.reload(true)", 1000);
				carregarFundo();
				
    });

		/**
		 * Trecho para exibir ultimo post do twitter na inicial
		 *
		 */
		// usado para exibir o twitter na pagina inicial
		
		if ($("#twitter")){
				
				$("#twitter").getTwitter({
					userName: "safiradigital",
					numTweets: 3,
					loaderText: "Carregando tweets...",
					slideIn: true,
					slideDuration: 750,
					showHeading: true,
					headingText: "",
					showProfileLink: true,
					showTimestamp: true
				});
				
		}


    /**
		 * PEGA CONTEUDO PARA PAGINA de fundos de investimentos, tabela comparativa
		 **/
		//$('#table_fundo_investimentos').ready(function(){
				
				// oculta div que exibe a tabela pra exibir com efeito 
				//$('#table_fundo_investimentos').hide();
				//$('#table_fundo_investimentos').empty();
				
        $.ajax({
            type: 'POST',
            url: 'resps/fundo_investimento.php',
            //data: params,
            beforeSend: function(){ },
            success: function(txt){
								
								//$('#table_fundo_investimentos').html(txt);
								$('#table_fundo_investimentos').show('slow');
								
            },
            error: function(txt){
								
				      //$('#table_fundo_investimentos').html('Ocorreu um erro ao tenter exibir a tabela com os fundos de investimentos');
							$('#table_fundo_investimentos').show('slow');
              return false;
				
            }
        });
				
		//});
				
    // ajax da home para enviar email da newsletter
		// envia por ajax e salva
    $('#frm_news_home').bind('submit', function(){

        var params = $(this.elements).serialize();

        var self = this;
				
				if (($(self).val()==null || $(self).val()=='') || ($(self).val()==' ' || $(self).val()==0)){
								
					alert('Preencha o email corretamente!');
					return false;
					
				}

        $.ajax({
            type: 'POST',
            url: this.action,
            data: params,
            beforeSend: function(){},
            success: function(txt){
								alert(txt);
            },
            error: function(txt){
								alert(txt);
              return false;
            }
        });
        return false;
    });

    // ajax da home para enviar email da newsletter
		// envia por ajax e salva
    $('.frm_right_news').bind('submit', function(){

        var self = this;
				
				function vazio(valor){
								
				  if ((valor==null || valor=='') || (valor==' ' || valor==0)){
								return true; 
				  }else{
								
					 return false;
				
				  }
					
				}
				
				if (
						( vazio($(self).children('#news_right_name').val()) ||
						  vazio($(self).children('#news_right_email').val()) ) ||
						($(self).children('#news_right_name').val()=='Nome' || $(self).children('#news_right_email').val()=='E-mail')){
								
					alert('Preencha o formulario corretamente!');
					return false;
					
				}
				
				// oculta trecho de mensagem de sucesso e erro
				$('.msg_news_right').hide();

        var params = $(this.elements).serialize();

        $.ajax({
            type: 'POST',
            url: this.action,
            data: params,
            beforeSend: function(){ },
            success: function(txt){
								
              //if (txt=='true'){
                
                //mensagem = '<p class="sucesso">E-Mail enviado com sucesso!</p>';
                //alert('E-Mail salvo com sucesso!');
                // Limpa o formulário
                //self.reset();
								//alert(txt);
								$('.msg_news_right').text(txt);
								$('.msg_news_right').slideDown('slow');
                
              //} else {
                
                //mensagem = '<p class="erros">N&atilde;o foi possivel enviar seu e-mail! Tente novamente!</p>';
								//alert('Nao foi possivel salvar seu e-mail! Tente novamente!');
                
              //} 

            },
            error: function(txt){
								
				      //alert('Nao foi possivel salvar seu e-mail! Tente novamente!');
							//alert(txt);
							$('.msg_news_right').text(txt);
							$('.msg_news_right').slideDown('slow');
              return false;
            }
        });
        return false;
    });

    // ajax da home para enviar email da pagina de contato
		// envia por ajax e salva
    $('#frm_contato').bind('submit', function(){

        var params = $(this.elements).serialize();

        var self = this;
				
				function vazio(valor){
								
				  if ((valor==null || valor=='') || (valor==' ' || valor==0)){
								return true; 
				  }else{
								
					 return false;
				
				  }
					
				}
				if ( vazio($(self).children('#contato_nome').val()) || vazio($(self).children('#contato_email').val()) || vazio($(self).children('#contato_msg').val()) ){
								
					alert('Preencha o formulario corretamente!');
					return false;
					
				}

        var params = $(this.elements).serialize();
				
				$('.msg_contato').hide();

        $.ajax({
            type: 'POST',
            url: this.action,
            data: params,
            beforeSend: function(){ },
            success: function(txt){
								
              if (txt=='true'){
                
                //mensagem = '<p class="sucesso">E-Mail enviado com sucesso!</p>';
                //alert('E-Mail enviado com sucesso!');
								$('.msg_contato').text('E-Mail enviado com sucesso!');
								$('.msg_contato').slideDown();
                // Limpa o formulário
                //self.reset();
                
              } else {
                
                //mensagem = '<p class="erros">N&atilde;o foi possivel enviar seu e-mail! Tente novamente!</p>';
								$('.msg_contato').text('Nao foi possivel enviar seu e-mail! Tente novamente!');
							  $('.msg_contato').slideDown();
                
              } 

            },
            error: function(txt){
								
				      //alert('Nao foi possivel enviar seu e-mail! Tente novamente!');
							
							$('.msg_contato').text('Nao foi possivel enviar seu e-mail! Tente novamente!');
							$('.msg_contato').slideDown();
							//alert(txt);
              return false;
            }
        });
        return false;
    });
		
		$('.item_slide2').show();
});	
