$(document).ready(function(){

    /* avocado */
    $(".mnu_avocado").mouseover(function(){

        $("#submnu_avocado").show();

    });

    $(".mnu_avocado").mouseout(function(){

        $("#submnu_avocado").hide();

    });

    $("#submnu_avocado").mouseover(function(){

        $("#submnu_avocado").show();

    });

    $("#submnu_avocado").mouseout(function(){

        $("#submnu_avocado").hide();

    });

    /* receitas */
    $(".mnu_receitas").mouseover(function(){

        $("#submnu_receitas").show();

    });

    $(".mnu_receitas").mouseout(function(){

        $("#submnu_receitas").hide();

    });

    $("#submnu_receitas").mouseover(function(){

        $("#submnu_receitas").show();

    });

    $("#submnu_receitas").mouseout(function(){

        $("#submnu_receitas").hide();

    });
    
    /* producao */
    $(".mnu_producao").mouseover(function(){

        $("#submnu_producao").show();

    });

    $(".mnu_producao").mouseout(function(){

        $("#submnu_producao").hide();

    });

    $("#submnu_producao").mouseover(function(){

        $("#submnu_producao").show();

    });

    $("#submnu_producao").mouseout(function(){

        $("#submnu_producao").hide();

    });
    
    /* comercio */
    $(".mnu_comercio").mouseover(function(){

        $("#submnu_comercio").show();

    });

    $(".mnu_comercio").mouseout(function(){

        $("#submnu_comercio").hide();

    });

    $("#submnu_comercio").mouseover(function(){

        $("#submnu_comercio").show();

    });

    $("#submnu_comercio").mouseout(function(){

        $("#submnu_comercio").hide();

    });
    
    /* foodservice */
    $(".mnu_foodservice").mouseover(function(){

        $("#submnu_foodservice").show();

    });

    $(".mnu_foodservice").mouseout(function(){

        $("#submnu_foodservice").hide();

    });

    $("#submnu_foodservice").mouseover(function(){

        $("#submnu_foodservice").show();

    });

    $("#submnu_foodservice").mouseout(function(){

        $("#submnu_foodservice").hide();

    });
    
    $("#frmEnviarAmigo").submit(function(){
        
        var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
        
        if ($("#nomede").val()==""){
            alert("Favor preencher o campo De.");
            $("#nomede").focus();
            return false;
        }
        
        if ($("#emailde").val()==""){
            alert("Favor preencher o campo E-mail.");
            $("#emailde").focus();
            return false;
        } else {
            if(er.test($("#emailde").val())!=true){
                alert("Você precisa digitar um e-mail válido.");
                $("#emailde").focus();
                return false;
            }
        }
        
        if ($("#nomepara").val()==""){
            alert("Favor preencher o campo Para.");
            $("#nomepara").focus();
            return false;
        }
        
        if ($("#emailpara").val()==""){
            alert("Favor preencher o campo E-mail.");
            $("#emailpara").focus();
            return false;
        } else {
            if(er.test($("#emailpara").val())!=true){
                alert("Você precisa digitar um e-mail válido.");
                $("#emailpara").focus();
                return false;
            }
        }
        
        if ($("#mensagem").val().length==0){
            alert("Favor preencher o campo Mensagem.");
            $("#mensagem").focus();
            return false;
        }
        
    });
    
    $("#faleconosco_form").submit(function(){
        
        var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
        
        if ($("#nome").val()==""){
            alert("Favor preencher o campo Nome.");
            $("#nome").focus();
            return false;
        }
        
        if ($("#email").val()==""){
            alert("Favor preencher o campo E-mail.");
            $("#email").focus();
            return false;
        } else {
            if(er.test($("#email").val())!=true){
                alert("Você precisa digitar um e-mail válido.");
                $("#email").focus();
                return false;
            }
        }
        
        if ($("#mensagem").val().length==0){
            alert("Favor preencher o campo Mensagem");
            $("#mensagem").focus();
            return false;
        }
        
    });
    
    $("#frmNews").submit(function(){
        
        var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);

        if ($("#news_email").val()==""){
            alert("Favor preencher o campo E-mail.");
            $("#news_email").focus();
            return false;
        } else {
            if(er.test($("#news_email").val())!=true){
                alert("Você precisa digitar um e-mail válido.");
                $("#news_email").focus();
                return false;
            }
        }
        
    });
    
    $("#estado").change(function(){
        
        $(".estados").hide();
        
        if ($(this).val()!=""){
        
            $("#estado_"+$(this).val()).show("slow");
        
        }
        
    });

    //Execute the slideShow
    slideShow();

});

function slideShow() {

	//Set the opacity of all images to 0
	$('#galeria_slider a').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#galeria_slider a:first').css({opacity: 1.0});
	
	//Set the caption background to semi-transparent
	$('#galeria_slider .caption').css({opacity: 0.7});

	//Resize the width of the caption according to the image width
	$('#galeria_slider .caption').css({width: $('#galeria_slider a').find('img').css('width')});
	
	//Get the caption of the first image from REL attribute and display it
	$('#galeria_slider .content').html($('#galeria_slider a:first').find('img').attr('rel'))
	.animate({opacity: 0.7}, 400);
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('gallery()',6000);
	
}

function gallery() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#galeria_slider a.show')?  $('#galeria_slider a.show') : $('#gallery a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#galeria_slider a:first') :current.next()) : $('#galeria_slider a:first'));	
	
	//Get next image caption
	var caption = next.find('img').attr('rel');	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	$('#galeria_slider .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#galeria_slider .caption').animate({opacity: 0.7},100 ).animate({height: '50px'},500 );
	
	//Display the content
	$('#galeria_slider .content').html(caption);
	
	
}


function fnEnviarParaAmigo(sis_rec_id){
    
    $("#enviar_para_amigo").toggle();
    
}

function fnGravarNews(){
    
    $("#frmNews").submit();
    
    
}
