$(document).ready(function() {
  $('#content .content_text .box_container .box:even').css('padding-left', '1px');
  
$("#sidebar_content").load("/_lazy_load/sidebar");
$(".content_context").load("/_lazy_load/content_context", function() {
	var physician_box = $('#content .content_text .box:first');
  var next_box = $('#content .content_text .box:eq(1)');
  if (next_box.height() > physician_box.height()) {
    physician_box.height(next_box.height() - 1);
  }

  $('#content .content_text .box_container').append('<div class="line"></div>');
  $('#content .content_text .box_container div.line').each(function() {
    var parent_height = $(this).parent().height();
    $(this).height(parent_height);
  });



  // doctor excerpt rotator
  var doctor_excerpts = $('#doctor_excerpt li'); // .sort(function() {return 0.5 - Math.random()});
  doctor_excerpts.css('display', 'none');
  doctor_excerpts.eq(Math.floor(Math.random() * doctor_excerpts.length)).show();

  doctor_excerpts_max_height = 0;
  doctor_excerpts.each(function(i) {
    $(this).css('left', '0');
    if ($(this).height() > doctor_excerpts_max_height) {
      doctor_excerpts_max_height = $(this).height();
    }
  });
  doctor_excerpts.parent().height(doctor_excerpts_max_height);
  rotate_doctors = true;
  doctor_excerpts.parent().bind("mouseenter", function(e) {
    rotate_doctors = false;
  });
  doctor_excerpts.parent().parent().parent().bind("mouseleave", function(e) {
    rotate_doctors = true;
  });

  function doctor_rotator() {
    if (rotate_doctors != false) {
      var current_doctor = $('#doctor_excerpt li:visible');
      current_doctor.fadeOut('slow');
      if (current_doctor.nextAll().length != 0) {
        next_doctor = current_doctor.next();
      } else {
        next_doctor = current_doctor.parent().children(":first");
      }
      next_doctor.fadeIn('slow');
      return false;
    }
  }

  setInterval(function() {
      doctor_rotator();
  }, 5000);

  Cufon.replace('.content_text h3, .content_context h4');


});


  
  
  $('.print').click(function() {
    window.print();
  });
  
  // Home page boxes                                                                                          
  $(".overview li").click(function() {
    link = $(this).find("a:first").attr('href');
    window.location = link;
  });
  
  // $("fb\\:like a").click(function() {
  //   alert('boo');
  // });

  // window.fbAsyncInit = function() {
  //  FB.init({appId: '178584998822579', status: true, cookie: true, xfbml: true});
  //  FB.Event.subscribe('edge.create', function(href, widget) {
  //  // Do something, e.g. track the click on the "Like" button here
  //  alert('You just liked '+href);
  //  });
  // };
  // (function() {
  //  var e = document.createElement('script');
  //  e.type = 'text/javascript';
  //  e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
  //  e.async = true;
  //  document.getElementById('fb-root').appendChild(e);
  //  }());  
  
  window.fbAsyncInit = function() {
   FB.init({appId: '178584998822579', status: true, cookie: true, xfbml: true});
      FB.Event.subscribe('edge.create', function(response) {
        console.log('like');
        // do something with response.session
      });
   };
});

