$.fn.gallerize = function() {
	
	/*
	
	home page gallery: 
	
	1. create a shuffled array of imagery
	2. randomly cross-fade to different images at different times
	3. At the messageDelayTime mark, cross-fade the center 8 shuffled, cross-fading images for the first message
	4. Start the messageDisplayTime timer
	5. At the messageDisplayTime mark, cross-fade the first message for the center 8 shuffled, cross-fading images
	6. Repeat steps 3 through 5 until all messages are displayed
	
	*/
	
	// loop through all images and push into the gallery array
	for (var i=0; i<this.length; i++) gallery.push($(this[i]).children("img").attr("src"));
		
	// increment to the 20th position (first invisible image)
	curGalleryPos = 20;
	
	// loop through all the *visible* images and set up timers (leave the others untouched; they are just for loading a cache of images)
	for (i=0; i<20; i++) {
		
		// add first run flag
		$(this[i]).attr("firstRun","true");
		
		// add function gallery fade
		$(this[i]).galleryFade();
		
	}
	
}

$.fn.galleryFade = function() {
	
	// pointers
	var e = this;
	var firstImage = $(this).children("img:first");
	var myDelay = randRange(picMinDelay * 10,picMaxDelay * 10) * 100;
		
	// random time
	if ($(this).attr("firstRun") == "true") {
		$(this).attr("firstRun","false");
		myDelay = randRange(picStartMinDelay * 10,picStartMaxDelay * 10) * 100;
	}
	
	// increment gallery position
	curGalleryPos++;
	
	// fix if we're at the end
	if (curGalleryPos >= gallery.length) curGalleryPos = 0;
	
	// add another image to the div, using first image in new gallery
	$(this).append('<img style="display:none" src="' + gallery[curGalleryPos] + '" />');
	
	// fade out old image
	$(this).children("img:first").delay(myDelay).fadeOut(fadeTime,function() {
		$(firstImage).remove();
	});
	
	// fade in new image, repeat gallery fade function
	$(this).children("img:last").delay(myDelay).fadeIn(fadeTime,function() {
		$(e).galleryFade();
	});
	
	
}

$.fn.messaging = function() {
	
	$(this[curMessage++]).fadeIn(fadeTime).delay(messagePauseDelay).fadeOut(fadeTime,function() {
		$("#message-gallery img").delay(messageBetweenDelay).messaging();
	});

	if (curMessage >= this.length) curMessage = 0;
	
	
}
