jQuery(function($) {
	if (typeof realurl2Dbg === 'undefined') return;

	// create ID columns for categories and articles

	var addDetails = function(table, details, addSkipInfo) {
		var rows = $('tbody .sly-sprite', table).closest('tr');

		if (addSkipInfo) {
			// add th
			$('th.sly-icon', table).after('<th class="realurl2dbg-skipicon">&nbsp;</th>');

			// add empty TDs
			$('td.sly-icon', table).after('<td class="realurl2dbg-skipicon">&nbsp;</td>');
		}

		for (var i = 0, len = rows.length; i < len; ++i) {
			var
				row    = rows[i],
				link   = $('a:first', row).attr('href'),
				id     = link ? link.match(/(category|article)_id=([0-9]+)/)[2] : null,
				infos  = id ? (details[id] || null) : null,
				icontd = $('.realurl2dbg-skipicon', row),
				prefix = '../data/dyn/public/realurl2/debugger/';

			if (infos !== null) {
				var span = $('<span class="realurl2dbg-info"></span>').text(infos.url);

				if (infos.fragment !== '') {
					span.attr('title', 'Fragment: '+infos.fragment);
					span.addClass('with-fragment');
				}

				if (!$(row).is('.sly-active')) {
					$('.sly-col-name', row).append(span);
				}

				if (addSkipInfo) {
					if (infos.skipped) {
						icontd.append('<img src="'+prefix+'skipped.png" alt="" title="versteckt" />');
					}
					else {
						icontd.append('<img src="'+prefix+'visible.png" alt="" title="sichtbar" />');
					}
				}
			}
			else {
				icontd.append('<img src="'+prefix+'visible.png" alt="" title="sichtbar" />');
			}
		}
	};

	addDetails($('#sly-structure-categories'), realurl2Dbg.lists.categories, true);
	addDetails($('#sly-structure-articles'), realurl2Dbg.lists.articles, false);
});
