/*
** library.js - Library Javascript Library
** jgriffith
**
*/

//Core.log.email = true;

Core.settings({site:'entrepreneurship',
               plugins:'/entrepreneurship/js/plugins'
               });

(function($){

var Rock = {
  
    ondomready: function() {
        Rock.subnav();
        Rock.topnav();
        Rock.expandables();
        Core.email_obfuscation();
        Rock.printfriendly();
        Rock.links();
        //Rock.test();
        $("hr").replaceWith('<div class="hr"></div>');
        if (window.analytics) {analytics.save()}
        
    },

    expandables: function() {
        $("dl.expandable dt").wrapInner("<span></span>");
        $("dl.expandable dt:first").addClass("first");
        $("dl.expandable dd").addClass("closed");
        $("dl.expandable dt").click(function() {
          $(this).toggleClass("open");
          $(this).next().toggleClass("open");
          return false;
        });
        
        $("#resources #maincolumn ul li").each(function(){
          $spans = $("span",this);
          if ($spans.size() > 0) {
            $spans.hide();
            $spans.before('<div><a class="more" href="#">Summary</a></div>')
          }
        });
        $("#resources #maincolumn a.more").click(function(){
          $(this).parent().parent().find("span").toggle();
          $("li").toggleClass("show");
          return false;
        })

        $("#crc #sidebar ul#staff li").each(function(){
          $spans = $("div",this);
          if ($spans.size() > 0) {
            $spans.hide();
            $spans.before('<span><a class="more" href="#">biography</a></span>')
          }
        });
        $("#crc #sidebar a.more").click(function(){
          $(this).parent().parent().find("div").toggle();
          return false;
        })        
 
        // right sidebar on on this page 
        // http://webdev.hbs.edu/entrepreneurship/facresearch/
        
        $("#tenets>li>a").click(function(){
           $(this).next().toggle();
           return false;
        });
        $("#tenets>li>a").next().hide();

		
		  
        $("h3.expand,#facres.expand").each(function() {
            $toggler = $(this);
            $toggler.html("<div>"+$toggler.html()+"</div>")
            $toggler.next().toggle();
            $("div",$toggler).click(function() {
                $(this).parent().next().toggle();
                $(this).parent().toggleClass('open')
                return false;
            })
         });
 
    },
       
    printfriendly: function() {
       var header = $('<div id="print-header"><img id="shield" src="/entrepreneurship/images/site/print.shield.gif" height="50" width="43" alt="" /><img id="logo" src="/entrepreneurship/images/site/print.logo.gif" height="19" width="282" alt="" /></div>');
       $("#header").after(header);
       $("#print-header").append('<h1>Entrepreneurship</h1>');
    },
	
    links: function() {
       if ($("body").hasClass("home")) {return};
       // most sites use "content" but in this case the content block is usually "maincolumn"
       $("#content a,#maincolumn a").each(function() {
          // comment add .ext class 
          // also include hbsp.harvard.edu as internal?
          $a = $(this);

          if (this.href && !/mailto/.test(this.href)) {
             if (! /hbs.edu/.test(this.href)) {$a.addClass("ext");}
             if (/hbsp.harvard.edu/.test(this.href)) {$a.removeClass("ext");}
             if ( /.pdf$/.test(this.href)) {$a.addClass("pdf");}
             if ( /voylink/.test(this.href)) {$a.addClass("new_window");}
          }
          
          if (this.className.indexOf("new_window") > -1 ){
              $(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('/entrepreneurship/bplan/') > -1) { sethere('bplan'); } 
        else if (loc.indexOf('/entrepreneurship/mbacurriculum/') > -1) { sethere('mbacurriculum'); } 
        else if (loc.indexOf('/entrepreneurship/internshipsjobs/') > -1) { sethere('internshipsjobs'); } 
        else if (loc.indexOf('/entrepreneurship/execed/') > -1) { sethere('execed'); } 
        else if (loc.indexOf('/entrepreneurship/facresearch/') > -1) { sethere('facresearch'); } 
        else if (loc.indexOf('/entrepreneurship/resources/') > -1) { sethere('resources'); } 
        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");
    },
  
   last:''
  
}

window.Rock = Rock;

$(document).ready(function(){Rock.ondomready();});

})(jQuery);

