/**
 * @author dirk v Nuess
 */

$(document).ready( function(){ 
	initJQuery();
	table_style();
});

function pageselectCallback(page_index, jq){
	items_per_page = 16;
	$('#Searchresult').empty();
	for (i=page_index*items_per_page;i<(page_index+1)*items_per_page;i++)
	{
		var new_content = $('#gallery ul li:eq('+i+')').clone();
		$('#Searchresult').append(new_content);
	}
	$('#Searchresult').prepend('<ul>');
	$('#Searchresult').append('</ul>');
	$('#Searchresult a').lightBox();
    return false;
}

function initPagination() {
    var num_entries = $('#gallery ul li').length;
    if(num_entries<17)$("#Pagination").addClass('hiddi');
    $("#Pagination").pagination(num_entries, {
        num_edge_entries: 0,
        num_display_entries: 6,
        callback: pageselectCallback,
        items_per_page:16
    });
 }

function initJQuery(){
	// FIRST LAST
	$('#footer a:first').addClass('first');
	initPagination();
	$("a[href^='http://']").attr('target', '_blank');
	$('a.popup').lightBox();
}

function table_style(){
	$('#content table').each(function(){
	var $table = $(this);
		first = 0;
		$('tr', $table).each(function(row) {
			var $row = $(this);
				//erste td breite
				td=0;
				$('td', $row).each(function(td) {
					if(td==0)$(this).addClass('breite_fest');
					td = 1;					
				});
			//erste tr
			if (row == 0) $row.addClass('topper');
			
			if(first==1){
				var counting = row % 2;
				if (counting === 1) $row.addClass('first');
				else $row.addClass('second');
			}
			
			/*
			$row.hover(function() {
					$row.addClass('row_hover');
				},
					function(){
					$row.removeClass('row_hover');
					}
			);
			*/
			
			//erster Durchlauf beendet
			first = 1;
		});
	});
}
