(function($) {
	
    $.fn.hbImagePopout = function(o) {

        var options = $.extend({}, $.fn.hbImagePopout.defaults, o);

        return this.each(function() {
			var parent = $(this), box;

			if (options.image.length && options.url.length) {
				
				box = $(options.markup);
				box.css(options.css).hide();
				
				box.find('a').click(function(e){
					e.preventDefault();
					box.fadeOut('fast', options.onDisappear);
				});
				
				if (options.title.length) {
					box.prepend('<p>' + options.title + '</p>');
				}
				box.append('<a href="' + options.url + '"><img style="display:block;" src="' + options.image + '" /></a>');
				
				parent.append(box);
			
				function boxReveal() {
					setTimeout(function(){
						box.fadeIn('fast', boxDisappear);
					}, options.timeBefore);
				}
				
				function boxDisappear() {
					if (options.timeAfter > 0) {
						setTimeout(function(){
							box.fadeOut('fast', options.onDisappear);
						}, options.timeAfter);
					}
				}
				
				boxReveal();
				
			} else {
				alert("Don't call hbImagePopout without an image and/or a URL!");
			}
        });
    };
	
    $.fn.hbImagePopout.defaults = {
		timeBefore : 1000,
		timeAfter  : 5000,
		markup : '<div class="hb-popout-box"><a class="close" href="#">Close</a></div>',
		onDisappear : function();
    
})(jQuery);
