
$(document).ready(function () {

       //preload images
       var preload = new Array();

       $('.roll').each(function (i) {
               //let's preload
               var img = new Image();
               img.src = this.src.replace(/_off([._])/, '_on$1');
               preload.push(img);

               $(this).hover(
                       function () { // over
                               $(this).attr('src',this.src.replace(/_off([._])/, '_on$1'));
                       },
                       function () { // out
                               $(this).attr('src',this.src.replace(/_on([._])/, '_off$1'));
                       }
               );
       });
});

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

jQuery.preLoadImages("_images/bt-features-viewgallery-en_on.gif", 
					 "_images/bt-features-buypaypal-en_on.gif",
					 "_images/bt-features-more-en_on.gif",
					 "_images/bt-features-readblog-en_on.gif",
					 "_images/bt-learn-conferences-en_on.gif",
					 "_images/bt-follow-my-adventures-en_on.gif",
					 "_images/bt-learnmore-aboutme-en_on.gif",
					 "_images/bt-atschool-en_on.gif",
					 "_images/bt-foryourbusiness-en_on.gif",
					 "_images/bt-acticmountainsrivers-en_on.gif"
					 );
					 
					 

// Slideshow
// ---------------------------------------------------------------------------------					 
$(document).ready(function() {

	//Get size of images, how many there are, then determin the size of the image reel.
	var images = $(".slideshow img");
	var imageSum = images.size();
	var currentImage = $(images[0]);
	var slideId = 0;
	
	images.css({position: 'absolute', display: 'none'});
	currentImage.fadeIn();
	
	//Adjust the image reel to its new size

	//Paging + Slider Function
	rotate = function() {
		currentImage.fadeOut();
		
		if (++slideId >= imageSum) slideId = 0;
		
		currentImage = $(images[slideId]);
		currentImage.fadeIn();
	}; 
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			rotate(); //Trigger the paging and slider function
		}, 5000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$(".slideshow a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	

});				