/**
 * jQuery plugin for wide tables.
 * @author Alex Jilkin
 */
(function($)
{
	$.fn.widetables = function(options)
	{
		options = $.extend({}, {
			showText: "Click the table to view it in full size",
			closeText: "Click the table to close"
		}, options);

		return this.each(function(){
			var maxWidth = $(this).closest("div,body").width(), curWidth = $(this).width();

			if(curWidth > maxWidth)
			{
				$(this).data("_original", $("<table></table>").html($(this).html()))
					.addClass('wide-table')
					.before("<div class='wide-table-tip'>" + options.showText + "</div>");
				$("*", this).css({fontSize: ((maxWidth / curWidth) * 80) + "%"});
				$(this).css({width:"100%"});
				$(this).click(function(){
					var html = $("<div class='wide-table-view'></div>").css({display:"none"}).html($(this).data("_original")).append("<div class='wide-table-view-foot'>" + options.closeText + "</div>").click(function(){
						$(this).fadeOut(function(){$(this).remove();});
						$("body").css({overflow:"auto"})
					});
					$("body").css({overflow:"hidden"}).append(html);
					$(html).fadeIn();
				});
			}
		});
	};
})(jQuery);
