function openVideo(url){
    $("body").append('<div id="js-popup-overlay"></div><div id="js-popup"><img class="close" src="images/close.gif" alt="" title="zatvori" /><div id="flashPopup"></div></div>');   

    var overlayEl = $("#js-popup-overlay");
    var popupEl = $("#js-popup");
    var closeButton = popupEl.find(".close");          
    var left = ($(window).width() - popupEl.width())/2;
    var top = ($(window).height() - popupEl.height())/2;
    
    $(window).resize(function(){ position_popup(overlayEl,popupEl); });
    overlayEl.click(function(){ close_popup(overlayEl,popupEl); });
    closeButton.click(function(){ close_popup(overlayEl,popupEl); });
    
    overlayEl.css({ height:$(window).height(), width:$(window).width(), opacity: "0.8" }).show();
    popupEl.css({ left: left, top: top });
    swfobject.embedSWF( "VideoPlayer.swf?file="+url+"&skin=VideoPlayer_skin.swf&controlbar=over&autostart=true", "flashPopup", "720", "405", "8", "", {} ,{allowFullScreen:"true"});
    popupEl.show();
}

function position_popup(overlayEl,popupEl){
        overlayEl.hide().css({ height:$(window).height(), width:$(window).width(), opacity: "0.8" }).show();
        var left = ($(window).width() - popupEl.width())/2;
        var top = ($(window).height() - popupEl.height())/2;
        popupEl.css({ left: left, top: top });
    }
    
function close_popup(overlayEl,popupEl){
    swfobject.removeSWF("flashPopup");
    popupEl.remove();
    overlayEl.remove();
    $(window).unbind("resize");
}
