
Core.settings({site:'leadership',
               plugins:'/leadership/js/plugins'
               });

(function($){

var Leadership = {
    ondomready:function() {
         Leadership.expandables();   
         Leadership.links();
         Leadership.topnav();
         Leadership.subnav();
         //Leadership.rotate();        
         console.time("leaderdata");
         Leadership.leaderdata();
         console.timeEnd("leaderdata");
         Leadership.faclist();
         console.time("backtotop");
         Leadership.backtotop();      
         console.timeEnd("backtotop");
         Leadership.rotateVidQuotes();
         Leadership.conferenceNavSwitcher();
         Core.email_obfuscation();
         $("hr").replaceWith('<div class="hr"></div>');
    },
    
    expandables: function() {
        $("#content dl.expandable dd").addClass("closed");
        $("#content dl.expandable dt").click(function() {
          $(this).toggleClass("open");
          $(this).next().toggleClass("closed");
		  return false;
        });
        
        if (!document.getElementById("conference")) return; // skip if not conference page
        $("#content #main ul.expands li").each(function(){
          $spans = $("span",this);
          if ($spans.size() > 0) {
            $spans.hide();
            $spans.before('<div><a class="more" href="#">Biography</a></div>')
          }
        });
        $("ul.expands li a.more").click(function(){
          $(this).parent().parent().find("span").toggle();
          $("li").toggleClass("show");
          return false;
        })
    }, 
    
    links: function() {   
    	if(!/database/.test(location.href)) {
	       $("#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('/leadership/faculty/') > -1) { sethere('faculty'); } 
        else if (loc.indexOf('/leadership/mba/') > -1) { sethere('mbaexperience'); } 
        else if (loc.indexOf('/leadership/conferences/') > -1) { sethere('conferences'); }
        else if (loc.indexOf('/leadership/database/') > -1) { sethere('database'); }
        else if (loc.indexOf('/leadership/timeline/') > -1) { sethere('timeline'); }
        else if ($("body").hasClass("home")) { sethere('home'); } 
        
    },

    /*
     * Add an 'on' class to 'subnav'
     */

    subnav: function() {
         $("#subnav a:thisurl").addClass("on");
    },      
    
    
    conferenceNavSwitcher: function() {
      if (!document.getElementById("conference")) return; // leave if you're not in conferences
         $("#subnav ul.expandable li ul").hide();
         // when you select an item 
         $("#subnav ul.expandable li a[@class='on']").parent('li').addClass("selected"); // nav class selected
         $("#subnav ul.expandable li a[@class='on']").parent('li').children('ul').show(); // sub items
         // when you're on an inside page 
         $("#subnav ul.expandable li a[@class='on']").parent('li').parent('ul').parent('li').addClass("open"); 
         $("#subnav ul.expandable li[@class='open']").children('a').addClass("active");
         $("#subnav ul.expandable li ul li").each(function() {
         	if (($(this).children('a').attr('class')) == "on") {
         		$(this).parent('ul').show();
         	} 
         });
    },
   
    rotateVidQuotes: function() {
      if (!document.getElementById("faculty")) return;
      
      var low = 0;
      var high = $("ul.rotate>li").size() - 1;
      var r = Math.floor(Math.random() * ( 1 + high - low ) + low );

      function showli(num) {
        $("ul.rotate li").each(function(i) {
         i == num ? $(this).show() : $(this).hide();
         });
         
         $("#sidebar ul.rotate-nav li").each(function(i) {
	    i == num ? $(this).addClass('on') : $(this).removeClass('on');
         });
      }
    
     $("#sidebar ul.rotate-nav li").each(function(i) {
        $(this).click(function(){showli(i);return false;});
     });
    
     showli(r);
    
     },   

    leaderdata: function() {
    	 if(/\/leaders\//.test(location.href)) { return; }
         $('.leaderslist tr:even').addClass('even'); // even class for leadership database
         //$('#sorted-content tr').find('td:eq(3)').addClass('era');
         //$('#sorted-content tr').find('td:eq(2)').addClass('ind');         
         //$('#sorted-content tr').find('td:eq(1)').addClass('company');       
    },   
    
    backtotop: function() {
       var h = document.body.clientHeight;
       if (h < 2000) { $("div.backtotop").hide() }
       $("div.backtotop a").click(function() {
            $('html,body').animate({scrollTop: 0}, 100);
            console.info("bla");
            return false;
            }
       )
    },  
    
    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;});

		  });
	   });
    }
    
}

window.Leadership = Leadership;

$(document).ready(Leadership.ondomready);

})(jQuery)





