/*
* jQuery OnDemand Image Loader
*
* Developed by
* Copyright 2011 - Anthony McLin
* http://anthonymclin.com
* Version 1.0
* Licensed under GPLv2
* Customized by Daniel Miller
*/
(function(jQuery){
  jQuery.fn.onDemandLoader = function(options) {
 
    // Configuration
    options = jQuery.extend({
      selector: null,
      callback : jQuery.noop
    }, options);
 
    //Change the source of all the images to point to the loading image
    jQuery(options.selector).each( function() {
      //Write the original source to a temporary location
      jQuery(this).attr('_src', jQuery(this).attr('src'));
      jQuery(this).attr('_alt', jQuery(this).attr('alt'));
      //Change the image source to the loading image
      jQuery(this).attr('src','');
      jQuery(this).attr('alt','');
    });
  };
 
  //Load a specific image by changing the source back
  jQuery.fn.onDemandLoader.loadImage = function(img) {
    jQuery(img).each( function() {
		jQuery(this).attr('src', jQuery(this).attr('_src'));
		jQuery(this).attr('alt', jQuery(this).attr('_alt'));
	})
  };
})(jQuery);

jQuery(document).ready(function(){
	jQuery('#block-system-main div.ms_gallery-slides li:gt(0) img').addClass('postload');
	jQuery('#block-system-main div.ms_gallery-thumbs li.slide-0:not(.cloned)').prevAll().find("img").addClass('postload');
	jQuery('#block-system-main div.ms_gallery-thumbs li.slide-4:not(.cloned)').nextAll().find("img").addClass('postload');
	//Swap out the images for on-demand loading
	jQuery('slideshow').onDemandLoader({
      selector:  '#block-system-main img.postload'
    });	
	
	jQuery("#team a.hidden").removeClass("hidden");
	jQuery("#team a.back").click(function(){
		if (jQuery("#team div.team-wrapper").css("top")!=0+"px") {
			jQuery("#team div.team-wrapper").animate({"top": "+=384px"}, "fast");
		}
	});
	jQuery("#team a.forward").click(function(){
		if (!(jQuery("#team div.team-wrapper").css("top")==(-384*(jQuery("#team div.team-wrapper").children().size()-1)+"px"))) {
			jQuery("#team div.team-wrapper").animate({"top": "-=384px"}, "fast");
		}
	});
});

jQuery(window).load(function(){
	jQuery('slideshow').onDemandLoader.loadImage("#block-system-main img.postload");
	jQuery('#content img').not('.postload').addClass('border');
	jQuery('#content img.postload').load(function(){
		jQuery(this).addClass('border');
	});
});;

