$(document).ready(function() {
    $("#navmenu li").hover(function() { $(this).addClass("iehover"); }, function() { $(this).removeClass("iehover") });

    var anima = true;
    $(".thumb").hover(function() {
        anima = false;
        $(".thumb").removeClass("imgSel")
        $("#fotoGrande").attr("src", $(this).attr("src"));
        $("#fotoGrande").attr("alt", $(this).attr("alt"));
        $("#fotoGrande").attr("title", $(this).attr("title"));
        $(this).addClass("imgSel")
    }, function() {
        anima = true;
    }
    );
    $("#fotoGrande").bind('click', function() {
        nextImg();
    });

    function nextImg() {

        if (anima) {
            var atual;

            $(".thumb").each(function(index) {
                if ($(this).attr("src") == $("#fotoGrande").attr("src")) {
                    atual = index;
                }
            });

            atual++;

            if (atual == $(".thumb").length) {
                atual = 0;
            }
            $(".thumb").each(function(index) {
                if (index == atual) {
                    $(".thumb").removeClass("imgSel")
                    $("#fotoGrande").attr("src", $(this).attr("src"));
                    $("#fotoGrande").attr("alt", $(this).attr("alt"));
                    $("#fotoGrande").attr("title", $(this).attr("title"));
                    $(this).addClass("imgSel")
                }
            });
            var timerID = window.setTimeout(nextImg, 5000);
        } else {
            timerID = window.setTimeout(nextImg, 1000);
        }
    }
    var timerID = window.setTimeout(nextImg, 5000);
    $(".vd").each(function() {
        $(this).css("background-image", "url(" + $.jYoutube($(this).attr("href"), 'small') + ")");
    });
});