$(document).ready(function(){
    $('.close-popup, #video_overlay').click(function(){
        $("#video_overlay").hide();
        $("#video_iframe").hide();
        $('#video_iframe').attr('src','');
    });
    
    $('.video_overlay_show_link').click(function(e){
        e.preventDefault();
        e.stopPropagation();
        e.stopImmediatePropagation();
        var new_src = $(this).attr("href");
        $('#video_iframe').attr('src',new_src);
        $('#video_iframe').show();
        $("#video_overlay").fadeIn("fast", function(){
            var popup = $('.popup');
            var wH = $(window).height();
            var pH = popup.outerHeight();
            var sT = $(window).scrollTop()
            var mT = ( (wH - pH) /2 ) + sT;
            //console.log(mT, wH, pH, sT, popup.css("margin-top"));
            popup.css('margin-top', mT);
            
            if($(this).height() < document.body.scrollHeight)
                $(this).height(document.body.scrollHeight);
            $(this).children('.popup').animate()
        })
        return false;
    })
})
