// 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(){
  
  // get the body class for the page we are on
  var thisPage = $("body").attr("class");
    
  // TEST: if we have an internal page anchor, load the scroller plugins.
  
  
  // If we want a colourbox images on our site
  if($("a.fancybox").length > 0) {
      $.requireJs('/assets/javascript/fancybox/jquery.fancybox-1.3.4.pack.js');
      $.requireCss('/assets/javascript/fancybox/jquery.fancybox-1.3.4.css');
  }
    
  
  //jQuery Alert Box
  $.requireJs('/assets/javascript/jquery.alerts.js');	

  
  
  //form stuff
  $.requireJs('/assets/javascript/jquery-ui/js/jquery-ui-1.8.14.custom.min.js');
  $.requireJs('/assets/javascript/jquery.tipsy.js');
  if($("body.members_area.cymraeg").length > 0) {
	 $.requireJs('/assets/javascript/jquery-ui/js/lang/jquery.ui.datepicker-cy.js');
  }
  
  if($("body.members_area.english").length > 0) {
	 $.requireJs('/assets/javascript/jquery-ui/js/lang/jquery.ui.datepicker-en.js');
  }
  
  $.requireCss('/assets/javascript/jquery-ui/css/smoothness/jquery-ui-1.8.14.custom.css');
  $.requireJs('/assets/javascript/formalize/jquery.formalize.min.js');
  $.requireCss('/assets/javascript/formalize/formalize.css'); 
 
  //splash image rotator
  $.requireJs('/assets/javascript/jquery.jshowoff.min.js');

  
  //we always want to load progressive enhancements at the end of the load queue
  $.requireJs('/assets/javascript/progressive-enhancement.js');
  
});
