
if (typeof Widgets == 'undefined') { Widgets = {}; } 

/*
 *
 * ShareBar Widget
 *
 */

(function($){

var ShareBar = {

    libsLoaded: false,
    assetHost: "http://www.hbs.edu",

    ondomready: function() {
    
    },
    
    loadLibs: function(){
      if (ShareBar.libsLoaded) return;
      
      if ($("link[href$='sharebar.css']").size() == 0) {
          $("head").append("<link>");
          css = $("head").children(":last");
          css.attr({
            rel:  "stylesheet",
            type: "text/css",
            href: ShareBar.assetHost+"/js/widgets/sharebar/sharebar.css"
          });
      }
      
      ShareBar.libsLoaded = true;
    },
    
    create: function(options){
       ShareBar.loadLibs();
      
       var title = escape(document.title);
       var url = escape(document.location.href);
      
       var html = '';
       html += '<div class="w-sharebar">\n';
       html += '<table><tr>\n';
       
       if (options && options.commentCount) {
         html += ' <td class="w-sharebar-comments"><a href="#commentform">Comments <span class="count">'+options.commentCount+'</span></a></td>';
       }
       html += ' <td class="w-sharebar-email"><a href="mailto:?subject=You have received a shared article&amp;body='+title+'%0A'+url+'">E-Mail</a></td>\n'
       html += ' <td class="w-sharebar-print"><a href="#">Print</a></td>\n'
       html += ' <td class="w-sharebar-share"><div class="container"></div></td>\n'
       html += ' <td class="w-sharebar-facebook"><iframe src="http://www.facebook.com/plugins/like.php?href='+url+'&amp;send=false&amp;layout=button_count&amp;width=120&amp;show_faces=false&amp;action=recommend&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:120px; height:20px;" allowTransparency="true"></iframe></td>';
       html += '</tr></table>\n';
       html += '</div>';
       var bar = $(html);
       bar.data('title',title);
       bar.data('url',url);
       ShareBar.addEvents(bar);
       return bar;
    },
    
    addEvents: function(bar) {
       $(".w-sharebar-print > a",bar).click(function(){
          window.print();
          return false;
       })
       
       $(".w-sharebar-share > div.container",bar).each(function(){ ShareBar.shareThis(this);}  );
       
    },
    
    sharethis_count : 0,
    shareThis: function(node,options) {
    
        ShareBar.loadLibs();
        var $container = $(node);
        if ($container.hasClass("w-rendered")) return;
        $container.addClass("w-rendered");

        var defaults = {url:document.location.href,
                        title:document.title,
                        label:"Share This",
                        openStyle: "click",
                        sites:['facebook','linkedin','twitter'],
                        extraSites: {}
                        };
                        
        options = $.extend(defaults,options)

        var html = "";
        var li = new Array();
        li['facebook'] ='<li class="facebook"><a href="http://www.facebook.com/share.php?u=$URL">Add to Facebook</a></li>';
        li['linkedin'] ='<li class="linkedin"><a href="http://www.linkedin.com/shareArticle?mini=true&url=$URL&amp;title=$TITLE&summary=&source=">LinkedIn</a></li>';
        li['reddit'] ='<li class="reddit"><a href="http://reddit.com/submit?url=$URL&amp;title=$TITLE">Add to Reddit</a></li>';
        li['stumbleupon'] ='<li class="stumbelupon"><a href="http://www.stumbleupon.com/submit?url=$URL">Stumble It!</a></li>';
        li['twitter'] ='<li class="twitter"><a href="http://twitter.com/home?status=$TITLE+$URL">Twitter</a></li>';
        li = $.extend(options.extraSites,li)

        for (var x=0;x<options.sites.length;x++){
           var site = options.sites[x];
           var h = li[site];
           h = h.replace("$URL",options.url);
           h = h.replace("$TITLE",options.title);
           html += h
        }
        
        var toggle = '<a href="#" class="toggle">' + options.label + '</a>';
        $container.html('<div class="w-sharethis-container" id="sharethis-'+ShareBar.sharethis_count+'">' + toggle + '<ul class="menu">'+html+"</ul></div>");
        ShareBar.sharethis_count = ShareBar.sharethis_count + 1;
        
        if (options.openStyle == "click") {
           $("a.toggle",$container).click(function() {
                                             $("ul.menu",$(this).parent()).toggle("fast").toggleClass("shareThisOpen");
                                             return false;
                                          });
           $("body").click(function() {
               $(".shareThisOpen").removeClass("shareThisOpen").hide();
           });
        }

        $("ul li a",$container).click(function(){   
                                          analytics.view(this.href);
                                 })

    
    },
    
    
    
    
    last:''
}

$(document).ready(function(){ShareBar.ondomready();});

window.Widgets.ShareBar = ShareBar;

})(jQuery);



/*
 *
 * Video Embed Widget
 *
 */

(function($){

var Videos = {

    dataMode: 'embed',  // what type of action
    dataNode: null,     // where the action should occur
    modalWidth: 640,
    modalHeight: 360,
    assetHost: "http://www.hbs.edu",
    
    ondomready: function() {
      
       if (document.location.host == 'webstage.hbs.edu') {
          Videos.assetHost = "http://webstage.hbs.edu";
       }
  
       $('a.widget-video-popup').click(function() {
           Videos.popup(this);
           return false;
       });
       
       $('a.widget-video-inline').click(function() {
           Videos.inline(this);
           return false;
       });
       
       Videos.recursiveEmbed();
    },
    
    recursiveEmbed: function() {
       $('a.widget-video-embed:first').each(function() {
               Videos.embed(this);
       });
    },
    
    getDataURL: function(link) {
       return link.href.replace(".html",".js").replace("/videos/","/videos/data/");
    },

    embed: function(link) {
       Videos.dataMode = 'embed';
       Videos.dataNode = link;
       var jsdataurl = Videos.getDataURL(link);
       $.getScript(jsdataurl);
    },
    
    inline: function(link) {
       Videos.dataMode = 'inline';
       Videos.dataNode = link;
       var jsdataurl = Videos.getDataURL(link);
       $.getScript(jsdataurl);
    },
    
    popup: function(link){
       Videos.dataMode = 'popup';
       Videos.dataNode = link;
       Videos.loadLibs();
       var jsdataurl = Videos.getDataURL(link);
       if ($.fancybox) {
             $.getScript(jsdataurl);

               
       } else {
            $.ajax({
                 type: 'GET',
                 url: Videos.assetHost+'/videos/js/plugins/fancybox/jquery.fancybox-1.3.1.js',
                 cache: true,
                 success: function() {
                    $.getScript(jsdataurl);
                 },
                 dataType: 'script',
                 data: null
             });
       }
    },
    
    /* allows a totally video popup where fed the raw data */
    popupData: function(data,link) {
       Videos.dataMode = 'popup';
       Videos.dataNode = link;
       Videos.loadLibs();
       if ($.fancybox) {
            Videos.dataCallback(data);
       } else {
           $.ajax({
            type: 'GET',
            url: Videos.assetHost+'/videos/js/plugins/fancybox/jquery.fancybox-1.3.1.js',
            cache: true,
            success: function() {
                Videos.dataCallback(data);
            },
            dataType: 'script',
            data: null
           });
       }

    },
    
    loadLibs: function(){
      // ALL HBS Fonts project
      if ($("link[href$='04c7bf70d998.css']").size() == 0) {
          $("head").append("<link>");
          css = $("head").children(":last");
          css.attr({
            rel:  "stylesheet",
            type: "text/css",
            href: "http://fast.fonts.com/cssapi/340b86ed-e421-467f-9adf-04c7bf70d998.css"
          });
      }
      if ($("link[href$='fancybox-hbs.css']").size() == 0) {
          $("head").append("<link>");
          css = $("head").children(":last");
          css.attr({
            rel:  "stylesheet",
            type: "text/css",
            href: Videos.assetHost+"/videos/js/plugins/fancybox/jquery.fancybox-hbs.css"
          });
      }
    },
    
    dataCallback: function(data) {
       
       Videos.num += 1;

       
       if (Videos.dataMode == 'popup') {
          if (Videos.isFallback() &! data.youtube) {
             document.location.href = data.vidly;
             return;
          }
          
          var html = Videos.renderPopup(data);
          var options = {width:Videos.modalWidth};
          var defaults = {width:'auto',height:'auto',onComplete:function(){Videos.popupComplete(data)}, autoDimensions:false,autoScale:false,padding:0,scrolling:'no',transitionIn:'none',transitionOut:'none',overlayColor:'#000'};
          options = $.extend(defaults,options)
          $.fancybox(html,options);
       }
       
       if (Videos.dataMode == 'inline') {
          var html = Videos.renderInline(data);
          $(Videos.dataNode).replaceWith(html);
          Videos.renderVideos(data,{autoplay:true});
       }
       
       if (Videos.dataMode == 'embed') {
          
          var html = Videos.renderInline(data);
          $(Videos.dataNode).replaceWith(html);
          if ($(Videos.dataNode).hasClass('autoplay')) {
              Videos.renderVideos(data,{autoplay:true});
          } else {
              Videos.renderVideos(data);
          }
          Videos.recursiveEmbed();
       }
       
    },
    
    popupComplete: function(data){ 
       Videos.sharethisEvents();
       Videos.renderVideos(data,{autoplay:true,modalsize:true});
    },
    
    num: 0,
    
    renderInline: function(data) {
       html = '<div id="video-embed-'+Videos.num+'" class="video" style="height:'+(data.height+30)+'px;width:'+data.width+'px"></div>';
       return html;
    },
    
    renderPopup: function(data) {
    
       var html = '<div class="video-container"><div class="lightbox-video"><div class="video-border">';
       html += '<div id="video-embed-'+Videos.num+'" class="video" style="height:'+(data.height+30)+'px;width:'+data.width+'px"></div>';
      
       html += '<div class="lightbox-text">';
       var subhead = data.subhead ? ' <span>'+data.subhead+'</span>' : '';
       html += '<h4 class="title">'+data.title+subhead+'</h4>';
       if (data.blurb) {
         html += '<p>'+data.blurb+'</p>';
       }
       html += '</div>';
       

       html += '<div class="wrapper socialToolBar">'
       html += '<ul class="share-extras">'
       html += '<li class="email"><a href="mailto:?subject=You have received a shared article&body='+escape(data.title)+'%0A'+escape(Videos.dataNode.href)+'" id="emailthis">E-Mail</a></li>'
      
       html += '</ul>'
       
       var pageurl = escape(Videos.dataNode.href);
       var doctitle = escape(data.title);
       var facebook ='<li class="facebook"><a href="http:\/\/www.facebook.com\/share.php?u='+ pageurl +'">Add to Facebook<\/a><\/li>';
       var linkedin ='<li class="linkedin"><a href="http:\/\/www.linkedin.com\/shareArticle?mini=true&url='+ pageurl +'&amp;title='+doctitle+'&summary=&source=">LinkedIn<\/a><\/li>';
       var twitter ='<li class="twitter"><a href="http:\/\/twitter.com\/home?status='+doctitle+'+'+ pageurl +'">Twitter<\/a><\/li>';
       var menu = facebook + linkedin + twitter;
       
       html += '<div class="sharebox"><div class="sharethis"><ul>'+menu+'</ul><a href="#" class="trigger">Share This</a></div></div>'
       html += '<div class="fbrecommends"><iframe src="http://www.facebook.com/plugins/like.php?href='+pageurl+'&amp;send=false&amp;layout=button_count&amp;width=200&amp;show_faces=false&amp;action=recommend&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:118px; height:21px;" allowTransparency="true"></iframe></div>';
       html += '</div><div class="clear"></div>';

       html += '</div></div></div>';
       
       return html;
    
    },
    
    sharethisEvents: function() {
       $(".sharebox a.trigger").click(function(){
          $(".sharebox ul").toggle();
          return false;
       });
       $("body").bind("BodyClick",function() {
          $(".sharebox ul").hide();
       });
    },
    
    renderVideos: function(data,options) {
      if (!options) options = {};
      if (data.source) {
      
          if (Videos.isFallback()) {
             if (data.vidly) {
                var vid = data.vidly.split('/').pop();
                if (vid) {
                   $("#video-embed-"+Videos.num).replaceWith('<iframe frameborder="0" width="'+data.width+'" height="'+data.height+'" src="http://vid.ly/embeded.html?link='+vid+'&autoplay=false"><a target=\'_blank\' href=\'http://vid.ly/'+vid+'\'><img src=\'http://cf.cdn.vid.ly/'+vid+'/poster.jpg\' /></a></iframe>');
                   return;
                }
             } 
             $("#video-embed-"+Videos.num).replaceWith('<p>Video is not supported on this device.</p>');
             return;
          }
      
          fo = new SWFObject(Videos.assetHost+"/videos/flash/player.swf", "flash"+Videos.num, data.width, (data.height+30), "8", "#000000");
          if (options.modalsize && options.modalsize == true) {
              fo = new SWFObject(Videos.assetHost+"/videos/flash/player.swf", "flash"+Videos.num, Videos.modalWidth, (data.height+30), "8", "#000000");
          } 

          fo.addVariable("source",data.source);
          fo.addVariable("allowFullScreen", "true");
          fo.addVariable("analytics", "true");
          if (data.resize) fo.addVariable("autoscale", "true");
          if (data.image) fo.addVariable("image",data.image);
          if (options.autoplay) {
             fo.addVariable("autoplay",true);
          }
          fo.addParam("allowFullScreen", "true");
          fo.addParam("wmode", "opaque");       
          //alert(document.getElementById("video-embed-"+Videos.num));
          fo.write("video-embed-"+Videos.num);
          //$("body").append("<span id=v1></span>");
          //fo.write("search");
      } else if (data.youtube && Videos.dataMode == 'popup') { /* YouTube in PopUp */
          $("#video-embed-"+Videos.num).html('<iframe width="'+Videos.modalWidth+'" height="'+(data.height+30)+'" src="http://www.youtube.com/embed/'+data.youtube+'?autoplay=1&wmode=Opaque" frameborder="0" allowfullscreen></iframe>');
      
      } else if (data.youtube) { /* YouTube Elsewhere */
          $("#video-embed-"+Videos.num).html('<iframe width="'+data.width+'" height="'+(data.height+30)+'" src="http://www.youtube.com/embed/'+data.youtube+'?wmode=Opaque" frameborder="0" allowfullscreen></iframe>');
      }
    },
    
    isFallback: function(){
       fo = new SWFObject(Videos.assetHost+"/videos/flash/player.swf", "flash"+Videos.num, 1, 1, "8", "#000000");
       return !fo.installedVer.versionIsValid(fo.getAttribute('version'))
    },
    
    
    
    last:''
}

window.Videos = Videos;

$(document).ready(function(){Videos.ondomready();});


/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;

})(jQuery);


// movie analytics
function flashEvent(msg) {
  analytics.view(msg);
}



