(function( $ ){
	$.fn.folioarrows = function(back, next, options) {
	
		if ( !this || !this.length )	return;
		var settings = { marginBottom: 0, zIndex: 1500, topAmp: -1 };
		$.extend( settings, options );
		var target = this;
		$('#folioarrows-container').remove();
		var initArrows = function () {
			if ( target.width() && target.height() > 20 ) {
				target.after('<div id="folioarrows-container"><div id="folioarrows-left"></div><div id="folioarrows-right"></div></div>');
				$('#folioarrows-container').css({
					'padding': 1,
					'width': target.width(),
					'margin': '0 auto ' + (settings.marginBottom-target.height()) + 'px auto',
					'position': 'relative',
					'height': target.height() - settings.marginBottom,
					'top': target.height() * settings.topAmp,
					'z-index': settings.zIndex
				});
				$('#folioarrows-left, #folioarrows-right').css({ 'width': 100, 'height': '100%', 'background-color': 'rgba(0,0,0,0.2)' });
				$('#folioarrows-left').css({ 'position': 'absolute', 'top': 0, 'left': 0 }).click(back);
				$('#folioarrows-right').css({ 'position': 'absolute', 'top': 0, 'right': 0 }).click(next);
			} else { 
				setTimeout(initArrows, 100);
			}
		}
		initArrows();
	};
})( jQuery );
