
// $Author: cmoreland $
// $Date: 11/3/2008 $
// $Revision: 1.0 $

(function($){

var Environment = {
  
    ondomready: function() {
        Environment.subnav();
        Environment.rotate();
        Environment.links();
        Environment.home();
        Core.email_obfuscation();
        //Environment.test();
        $("hr").replaceWith('<div class="hr"></div>');
        if (window.analytics) {analytics.save()}
        
    },


    // homepage 
    
    home: function() {
      if (!document.getElementById("home")) return;
      
      var low = 0;
      var high = $("#profiles > div").size() - 1;
      var r = Math.floor(Math.random() * ( 1 + high - low ) + low );

      
      function showdiv(num) {
         $("#profiles>div").each(function(i) {
            i == num ? $(this).show() : $(this).hide()
         });
         
         $("#profiles ul.leaders li").each(function(i) {
	    i == num ? $(this).addClass('on') : $(this).removeClass('on')
         });
      }
    
     $("#profiles ul.leaders li").each(function(i) {
        $(this).click(function(){showdiv(i);return false;});
        
     });
    
      showdiv(r);
    
    },



    /* Quote Rotatio Script*/
    
    rotate: function() {

         function showli(num,ul) {
            $("li", ul).each(function(i) {
                i==num ? $(this).show() : $(this).hide()
            })
         } 

         $("ul.rotate").each(function() {
            var size = $(">li",this).size()
            var num = Core.cookie("rotatenum") || 0;
            num = (parseInt(num)+1) % size 
            showli(num,this);
            Core.cookie("rotatenum", num, {path:document.location.pathname,expires:30})
        })
    
    },
    
    
   
    /*
     * Add an 'on' class to 'subnav'
     */

    subnav: function() {
         var nav = document.getElementById('subnav');
         if (!nav) return
         $("#subnav a:thisurl").addClass("on");
    },
   

    links: function() {
       $("#content a,#home div.col-right a,div.resources a").each(function() {
          // comment add .ext and .pdf class anywhere in content block
          $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 (/harvardbusiness/.test(this.href)) {$a.removeClass("ext");}
             if ( /.pdf$/.test(this.href)) {$a.addClass('pdf')}
             if ($a.hasClass("ext")) {$a.removeClass("pdf");} 
          }
          if ($a.hasClass("new_window")){
              $(this).click(function(){
                 Core.new_window(this);
                 return false;
              });
           }
       });
    },  
  
   last:''
  
}

window.Environment = Environment;

$(document).ready(function(){Environment.ondomready();});

})(jQuery);

