(function($) {
	$.fn.bsminitools = function(settings) {
		settings = jQuery.extend({
			did: 0,
			position: 2,
			formlinkadd: "",
			pagelinkadd: ""
		}, settings);

		var position = settings.position >= 0 && settings.position <= 9 ? settings.position : 2;
		var classadd = position % 5 == 2 ? "float" : "full"

		$(this).each(function() {

			var attr = $(this).attr("id").split("_bid");
			var oid = parseInt( attr[0].substr(9) );
			var bid = parseInt( attr[1] );

			var html = '<div class="bsminitools bsmt_'+classadd+'">';
			html += '<a '+settings.formlinkadd+' title="Link zum Inhalt per E-Mail senden" class="bsmt_maillink" href="plugin/bsminitools/files/maillink.php?oid='+oid+'&amp;bid='+bid+'"></a>';
			html += '<a '+settings.pagelinkadd+' title="Inhalt drucken" class="bsmt_print" href="?did='+settings.did+'&amp;oid='+oid+'&amp;bid='+bid+'&amp;print=1"></a>';
			html += '<a '+settings.pagelinkadd+' title="Inhalt als PDF" class="bsmt_pdf" href="plugin/bsminitools/files/pdf.php?oid='+oid+'&amp;bid='+bid+'"></a>';
			html += '<a '+settings.formlinkadd+' title="Inhalt per E-Mail senden" class="bsmt_mailbox" href="plugin/bsminitools/files/mailbox.php?oid='+oid+'&amp;bid='+bid+'"></a>';
			html += '</div>';

			switch (position) {
				case 0:
					$(this).find(".b3box_head").before(html);
					break;
				case 1:
				case 2:
					$(this).find(".b3box_head").prepend(html);
					break;
				case 3:
					$(this).find(".b3box_head").append(html);
					break;
				case 4:
					$(this).find(".b3box_head").after(html);
					break;
				case 5:
					$(this).find(".b3box_foot").before(html);
					break;
				case 6:
				case 7:
					$(this).find(".b3box_foot").prepend(html);
					break;
				case 8:
					$(this).find(".b3box_foot").append(html);
					break;
				case 9:
					$(this).find(".b3box_foot").after(html);
					break;
				default:
					break;
			}
		});
	};
})(jQuery);
