var heightAtual;
var heightContent;
var tmtSlalow;
$(document).ready(function() {
    //$("#main #top ul li").lavaLamp({fx: "backout", speed: 700 });

    $("#galeriaprodutos ul li").hover(function() {
        $(this).parent().addClass("bgHover");
        $(".modal", this).show();
        $(this).addClass("liBGHover");
    }, function() {
        $(".modal", this).hide();
        $(this).parent().removeClass("bgHover");
        $(this).removeClass("liBGHover");
    });

    $(".maisinformacoes").click(function() {
        heightAtual = $("#conteudoProduto").css("height");
        heightContent = $("#conteudoProduto").css("height", "auto").height();
        $("#conteudoProduto").css("height", heightAtual);
        if(parseInt(heightAtual)<heightContent) {
            heightAtual = $("#conteudoProduto").css("height");
            heightContent = $("#conteudoProduto").css("height", "auto").height();
            $("#conteudoProduto").css("height", heightAtual);

            ajustaTamanho();
        } else {
            ajustaTamanhoEsconde();
        }

        return false;
        
    });
    height = 0;
    $("#conteudoProduto *").each(function() {
        height+= $(this).height();
    });
    if(height<=180) {
        $(".maisinformacoes").parent().remove();
        if(height>130) {
            $("#conteudoProduto").height(height+10);
        }
    }

    $("#menuprodutos ul li").hover(function() {
        $("#imgs img").hide();
        CodigoLinha = $(this).attr("rel");
        $("#imgs img[rel="+CodigoLinha+"]").show();
    //$(".fotoproduto").attr("src", "/original/"+);
    }, function() {
        $("#imgs img").hide();
        CodigoLinha = $(this).attr("rel");
        $("#imgs img[rel=none]").show();
    });

    $(".facebox").facebox({
        opacity: 0.6
    });
});

function ajustaTamanho() {
    clearTimeout(tmtSlalow);
    tmtSlalow = setTimeout(function() {
        if(parseInt(heightAtual)<heightContent) {
            novoHeight = parseInt(heightAtual)+5;
            $("#conteudoProduto").height(novoHeight);

            heightAtual = $("#conteudoProduto").css("height");
            ajustaTamanho();
        }
    }, 20);
}

function ajustaTamanhoEsconde() {
    clearTimeout(tmtSlalow);
    tmtSlalow = setTimeout(function() {
        if(parseInt(heightAtual)>137) {
            novoHeight = parseInt(heightAtual)-5;
            $("#conteudoProduto").height(novoHeight);

            heightAtual = $("#conteudoProduto").css("height");
            ajustaTamanhoEsconde();
        }
    }, 20);
}
