﻿var bp_popup = {
    
    from: null,
    csid: null,
    
    /* display the case study popup */
    showCaseStudy: function(id) {
        
        // set the overall casestudy id
        bp_popup.csid = id;
        TopUp.display("/CaseStudy_iFrame.aspx?vid=" + id, { shaded: 1, width: 780, height: 510, type: "iframe", effect: "fade", resizable: 0, overlayClose: 1 });
        
    },
    
    /* display the video popup */
    showVideo: function(id, from, type) {
        
        // set where we have popped up from, then display the popup
        bp_popup.from = from;
        TopUp.display("/Video_iFrame.aspx?vid=" + id + "&type=" + type, { onclose: function() { setTimeout(bp_popup.popupClose, 100) }, shaded: 1, width: 780, height: 510, type: "iframe", effect: "fade", resizable: 0, overlayClose: 1 });
        
    },
    
    setVideo: function(path, id) {
    
        // remove the swf, (which removes the video div aswell unfortunately) then put the video div back.
        swfobject.removeSWF("videoPlayer");
        $("#mainVideo").html("<div id='video'><!-- js generated flash video --></div>");
        
        // swf params
        var params = { };
            params.menu = "false";
            params.wmode = "transparent";
            params.allowscriptaccess = "always";
            params.scale = "noScale";
            params.salign = "tc";
            params.allowFullScreen ="true";
        
        // swf atts
        var attributes = { };
            attributes.id = "videoPlayer";
            attributes.name = "videoPlayer";
        		  
        flashvars = { path: path + id + ".flv" };
        
        swfobject.embedSWF("/Flash/videoplayer/video.swf", "video", "440", "246", "9.0.0", false, flashvars, params, attributes);
    },
    
    popupClose: function() {
  
        swfobject.removeSWF("videoPlayer");
        $("#mainVideo").html("<div id='video'><!-- js generated flash video --></div>");
        
        if (bp_popup.from !== null && bp_popup.csid !== null) {
            bp_popup.showCaseStudy(bp_popup.csid);
        }
        
    },
    
    downloadAdded: function() {
        
        var $me = $(".downloadbtn");
        
        $(".dlPopup").css({ top: $me.offset().top - $(".dlPopup").height() - (10 + 20 + 10), left: $me.offset().left });
        $(".dlPopup").fadeIn(200);
        
        $(".dlPopup img").bind("click", function() {
            
            $(".dlPopup").fadeOut(200);
            
            $(".dlPopup img").unbind("click");
        });
        
    }
    
};

// set topup paths
TopUp.images_path = "/Scripts/TopUp_Latest/1.7.2/images/top_up/";
TopUp.players_path = "/Scripts/TopUp_Latest/1.7.2/players/";

