
(function($) {
	$.fn.tables = function(options) {
		return this.each(function() {
			$this = $(this);
			$("th:last", $this).addClass("last");
			$("th:first", $this).addClass("first");
			if ($("th", $this).length == 1) {
				var th = $("th", $this);
				th.html("<div>" +  th.html() + "</div>");
				th.css("padding",0);
				$("div", th).eq(0).css("padding","10px 14px 14px").css("border-right","1px solid white")
			}
			$("th", $this).eq(0).parent().next().addClass("first");
			$("tr:even", $this).addClass("alt");
			$("th br", $this).parent().addClass("twolines");
			
			
		});
	};
	
	$.fn.imageDescriptions = function(options) {
		return this.each(function() {
			$this = $(this);
			if ($this.attr("alt") == '') return;
			var imgwidth = $this.width();
			if (imgwidth == 0) {
				 imgwidth = $this.attr("width");
			}
			var tabletowrap = $('<table class="wrapimg"><tr><td class="wrapimgsub"></td></tr><tr><td class="wraptxtsub"></td></tr></table>');
			tabletowrap.insertBefore($this);
			tabletowrap.find('td.wrapimgsub').append($this);
			tabletowrap.eq(0).css("width", imgwidth + "px");

			var s = $this.attr("alt");
			s = s.replace(/\{link to=([^\}]+)\}([^\{]+)\{\/link\}/g, '<a target="_blank" href="$1">$2</a>');
			//$this.after("<p>" + s + "</p>");
			tabletowrap.find('td.wraptxtsub').append(s);
			if($this.css("float") != "none") {
				tabletowrap.css("float", $this.css("float"));
				$this.css("float","none");	
			}
			try {
				if ($this.css("margin") != ''){
					tabletowrap.css("margin", $this.css("margin"));
					$this.css("margin","0");	
				}
			} catch(e){}
			if ($this.hasClass("imagehasfooterright")){
				tabletowrap.addClass("imagehasfooterright");
				$this.removeClass("imagehasfooterright");
			}
			if ($this.hasClass("imagehasfooterleft")){
				tabletowrap.addClass("imagehasfooterleft");
				$this.removeClass("imagehasfooterleft");
			}
		});
	};
})(jQuery);