(function () {
	$.fn.callouts = function (list_of_callouts) {

		var callouts = list_of_callouts;
		var $callout = $("#callout");

		if ( callouts.length == 0 ) {
			return;
		}

		// The workhorse of justice
		var cur_index = -1;
		$.fn.callouts.advance = function() {
			cur_index = (cur_index+1)%callouts.length;
			var c = callouts[cur_index];
	
			$callout
				.removeAttr('style')			// Reset CSS
				.css('visibility','hidden')		// hide it while we mess with it
				.children('img').attr('src', c.src).end()
				.css(c.css)
				.css('visibility', 'visible');	// show it when it's done


			
			// Do the generic stuff that every callout needs done:

			// If this shit is clickable, make it look like it:
			$callout.css('cursor', $.isFunction(c.click) ? 'pointer' : 'auto');


			// Now, also do whatever special stuff this callout wants, like maybe some animation.
			c.load();

			// Schedule the next one.
			setTimeout(
				function(){
					c.unload();
				},
				c.duration
			);

		}


		// Give each callout a chance to get itself set up before we dive in.
		$.each(callouts, function(k,v){
			if ($.isFunction(v['init'])) {
				v['init']();
			}
		});

		// Here's where it all begins!
		setTimeout(function(){$.fn.callouts.advance();},900);

		// Compute the click event routing at the time of the event, instead of repeatedly binding/unbinding handlers when the callout
		// changes:
		$callout.click(function(){
			(callouts[cur_index].click)();
		});
	}
})(jQuery);

