// Begin Lazy Loading.
// 
// Lazy Loading allows us to load JS & CSS files only when the page requires them, saving bandwidth and decreasing load times.
// We get the option to inspect the mark-up and see if it's appropriate to include a particular plug-in or not automatically at runtime.
// For more detail on this technique, it's pros and cons, see: http://ajaxpatterns.org/On-Demand_Javascript#In_A_Blink
//
// NOTES:
// This file relies upon jQuery & the jquery.ondemand plugin. jQuery and the ondemand plugin MUST be included before this file.

$(document).ready(function(){
  // TEST: if we have a form on a page then we want to load a number of form enhancement plugins.
  if($("form").length > 0) {
    $.requireJs('assets/javascript/jquery.InputHelper.js'); // jQuery form validation
  }
  
  //TEST: if we're on the homepage we need the cycle plugin
  if($("body.home").length > 0){
    $.requireJs('assets/javascript/jquery.cycle.all.min.js');
    $.requireJs('assets/javascript/jquery.easing.1.3.js');
    $.requireJs('assets/javascript/jquery.easing.compatibility.js');
  }
  
  // TEST: if we have media on the page
  if($("a.media")){
    $.requireJs('assets/javascript/jquery.media.js');
  }
  
  // TEST: we need the jcarousel and fancybox plugins on the press page
  if($("body.press")){
    $.requireJs('assets/javascript/jcarousellite_1.0.1.min.js');
    $.requireJs('assets/javascript/fancybox/jquery.fancybox-1.0.0.js');
    $.requireCss('assets/javascript/fancybox/fancy.css');
  }
  
  // we always want to load progressive enhancements at the end of the load queue
  $.requireJs('assets/javascript/progressive-enhancement.js');
  
});
