$(document).ready(
	function()
	{
		var table_counter = 0;
		var TMPCNT = 0;
		
		$('table').each(
			function()
			{				
				if(!$(this).parents('body').hasClass('we-news-details') && !$(this).parents('#webenchcategory2').length>0)
				{			
					if( ($(this).find('tr:first-child td').length > 5 || $(this).hasClass('we-table-popup')) && !$(this).hasClass('we-table-no-popup') )
					{
						var caption = $(this).find('caption').text();
						$(this).attr({'id': 'we-table-popup-' + table_counter});
						//$('#we-table-popup-' + table_counter).css({width: 'auto'});			
						
						if (typeof window.transTableBig == 'undefined') window.transTableBig = 'vollständige Tabelle anzeigen';		
            $('#we-table-popup-' + table_counter).after('<div class="we-table-popup-button"><a href="#we-table-popup-' + table_counter + '" id="we-table-popup-button-' + table_counter + '">' + window.transTableBig + '</a></div>');

						var html_data = '<table style="width: auto; margin: 0;">' + $('#we-table-popup-' + table_counter).html() + '</table>';
						
						$('#we-table-popup-button-' + table_counter +', #we-table-popup-' + table_counter).fancybox(
							{
								'transitionIn'	:	'elastic',
								'transitionOut'	:	'elastic',
								'speedIn'		:	150, 
								'speedOut'		:	150, 
								'overlayShow'	:	true,
								'content' : html_data,
								'padding': 10
							}
						);
						
						//$(this).css({display: 'none'});
						$(this).find('tr').each(function() {
              if ($(this).parents('thead').length==0) {
                $(this).find('td:gt(4)').remove();
                $(this).append('<td>&hellip;</td>');
							}
						});
						$(this).find('thead tr').each(function() {
							$(this).find('th:gt(4)').remove();
							$(this).append('<th>&hellip;</th>');
						});
						$(this).css('cursor','pointer');
						//$(this).parent().css({display: 'none'});
						table_counter ++;
					}
				}
				
				if($(this).parents('body').hasClass('we-news-details'))
				{			
					if( ($(this).find('tr:first-child td').length > 8 || $(this).hasClass('we-table-popup')) && !$(this).hasClass('we-table-no-popup'))
					{
						
						$(this).attr({'id': 'we-table-popup-' + table_counter});
						$('#we-table-popup-' + table_counter).css({width: 'auto'});					
						$('#we-table-popup-' + table_counter).parent('').after('<div class="we-table-popup-button"><a href="#we-table-popup-' + table_counter + '" id="we-table-popup-button-' + table_counter + '">' + transTableBig + '</a></div>');
						
						var html_data = '<table style="width: auto; margin: 0;">' + $('#we-table-popup-' + table_counter).html() + '</table>';
						
						$('#we-table-popup-button-' + table_counter).fancybox(
							{
								'transitionIn'	:	'elastic',
								'transitionOut'	:	'elastic',
								'speedIn'		:	150, 
								'speedOut'		:	150, 
								'overlayShow'	:	true,
								'content' : html_data,
								'padding': 10
							}
						);
						
						//$(this).css({display: 'none'});
						$(this).parent().css({display: 'none'});
						table_counter ++;
					}
				}
			}
		);
		
		
	}
);
