function getWindowHeight(){
    if(window.innerHeight){
        return window.innerHeight;
    }else if(document.documentElement.clientHeight){
        if(document.documentElement.clientHeight==0){
            return document.body.clientHeight;
        }
        else{
            return document.documentElement.clientHeight;
        }
    }
}
function vid_popup(o){
        if(o.attr("id") == "background_popup" ||
           o.attr("id") == "popup_cont_close"){
                swfobject.removeSWF("popup_flash");
                jQuery("#background_popup").hide();
                jQuery("#popup_cont").hide();
                jQuery("#popup_flash_wrap").html('<div id="popup_flash"></div>');
        } else {
                center_popup();
                jQuery("#background_popup").css({"opacity": "0.7"});
                jQuery("#background_popup").fadeIn(300);
                jQuery("#popup_cont").fadeIn(300, function(){vid_content_load(o.attr("href"));});
        }
}
function center_popup(){
        if(window.XMLHttpRequest) {
                jQuery("#popup_cont").css({
                        "top": getWindowHeight()/2 - jQuery("#popup_cont").height()/2,
                        "left": document.documentElement.clientWidth/2 - jQuery("#popup_cont").width()/2
                });
        } else {
                jQuery("#background_popup").css({
                        "height": getWindowHeight()*1.5,
                        "width": document.documentElement.clientWidth,
                        "top": jQuery().scrollTop()
                });
                jQuery("#popup_cont").css({
                        "top": jQuery().scrollTop() + getWindowHeight()/2 - jQuery("#popup_cont").height()/2,
                        "left": document.documentElement.clientWidth/2 - jQuery("#popup_cont").width()/2
                });
        }
}

function vid_content_load(file_id) {
        var flashvars = {};
        flashvars.videoSource = "http://www.productsandservices.bt.com/consumer/consumerProducts/flash/entertainment/videos/bolly.flv";
        var params = {allowScriptAccess:"sameDomain"};
        swfobject.embedSWF(
                "http://www.productsandservices.bt.com/consumer/consumerProducts/flash/entertainment/BTVideoPlayer.swf",
                "popup_flash",
                "640", "360", "9.0.0","",
                flashvars, params);
}

jQuery(function(){
    jQuery('#bt_video_popup, #popup_cont_close').click(function(){
        vid_popup(jQuery(this));
        return false;
    });
});