

(function($){

var EC = {
    ondomready:function() {
         EC.links();
         EC.topnav();
         EC.subnav();
         EC.videonav();         
         EC.faclist();
         EC.loggedin();
		 Core.email_obfuscation();
    },
    
    links: function() {
       $("#content a").each(function() {
          // comment add .ext class
          $a = $(this);
          if (this.href && !/mailto/.test(this.href)) {
             if (! /hbs.edu/.test(this.href)) {$a.addClass("ext");}
             if (/video2.harvard.edu/.test(this.href)) {$a.removeClass("ext");}
             if (/hbsp.harvard.edu/.test(this.href)) {$a.removeClass("ext");}
             if ( /.pdf$/.test(this.href)) {$a.addClass('pdf')}
          }
          if ($a.hasClass("new_window")){
              $(this).click(function(){
                 Core.new_window(this);
                 return false;
              });
           }
       });
    },
    
    /*
     * Add an 'on' class to the top nav
     */
     
    topnav: function() {
        function sethere(id) {
            var a = document.getElementById(id+'-nav');
            if (!a){return};
            a.parentNode.className += ' on';
            a.className += ' on';
        }
        var loc = document.location.href;
        if (loc.indexOf('/economic-crisis/faculty/') > -1) { sethere('faculty'); } 
        else if (loc.indexOf('/economic-crisis/research/') > -1) { sethere('research'); } 
        else if (loc.indexOf('/economic-crisis/education/') > -1) { sethere('education'); }
        else if (loc.indexOf('/economic-crisis/in-the-news/') > -1) { sethere('in-the-news'); }
        else if (loc.indexOf('/economic-crisis/protected/insidehbs/') > -1) { sethere('insidehbs'); }
        else if ($("body").hasClass("home")) { sethere('home'); } 
        
    },

    /*
     * Add an 'on' class to 'subnav'
     */

    subnav: function() {
         var nav = document.getElementById('subnav');
         if (!nav) return
         $("#subnav a:thisurl").addClass("on");
         // using body class and css for discussion videos
    },      
    
     videonav: function() {
         var videonav = document.getElementById('discussionVideos');
         if (!videonav) return
         $("#discussionVideos a:thisurl").addClass("active"); /* add active to a */
         $("#discussionVideos li a[@class='active']").parent('li').addClass("on");  /* add on to any active */
    },    
    
    faclist: function() {
        $("#facInterestsList li.slider").each(function() {
          var slider = $(this);
          $("div",slider).hide();
          $(">a",slider).each(function() {
             var div = $("div:first",$(this).parent());
             $(this).click(function() {
                     div.slideToggle();
                     slider.toggleClass('open');
                     return false });
             $("a.close",slider).click(function() {
                     div.slideToggle();
                     slider.toggleClass('open');
                     return false;});

          });
       });
    },
     
     
    loggedin: function() {
       if(Core.cookie("HBSCOOKIE")) {
         $("#insidehbs-nav").show();
       }
    
    }
     
}


$(document).ready(EC.ondomready);

})(jQuery)





