$(document).ready(function(){
	$('.pagin2 li').addClass('second');
	$(".menuebottom.last .listmenue").append('<div id="paginationtwo" class="paginationk"><div id="page_navigationk"><a class="page_link" id="firstk" href="#"></a><a class="page_link" id="secondk" href="#"></a></div></div>');
	
	
	$('#page_navigationk a:first').addClass('active');
	
	$('#firstk').click(function() {
		$('#firstk').addClass('active');
		$('#secondk').removeClass('active');
		$('.pagin2 .second').hide();
  		$('.pagin2 .first.second').show();
  		
  		return false
	});
	$('#secondk').click(function() {
		$('#firstk').removeClass('active');
		$('#secondk').addClass('active');
		$('.pagin2 .second').show();
  		$('.pagin2 .first.second').hide();
  		
  		return false
	});

	
	
	//wieviele einträge pro seite
	var show_per_page = 15; 
	//zählen der childrens inerhalb und der seiten...
	var number_of_items = $('.pagin2').children().size();
	var number_of_pages = Math.ceil(number_of_items/show_per_page);

	$('#current_pagek').val(0);
	$('#show_per_pagek').val(show_per_page);
	
	var navigation_html = '<div id="prev"><a class="previous_linkk" href="javascript:previous();">« zurück</a></div><div id="pageinatork">';
	var current_link = 0;
	while(number_of_pages > current_link){
		navigation_html += '<a class="page_linkk" href="javascript:go_to_page(' + current_link +')" longdesc="' + current_link +'">'+ (current_link + 1) +'</a>';
		current_link++;
	}
	navigation_html += '</div><div id="next"><a class="next_linkk" href="javascript:next();">vor »</a></div>';
	
	
	
	//erst verstecken aller elemente / Childrens
	$('.pagin2').children().css('display', 'none');
	//und dann die zeigen die da sein müssen
	$('.pagin2').children().slice(0, show_per_page).addClass('first');
	
	
	
});


function previous(){
	new_page = parseInt($('#current_page').val()) - 1;
	if($('.active').prev('.page_link').length==true){
		go_to_page(new_page);
	} 
}
function next(){
	new_page = parseInt($('#current_page').val()) + 1;
	if($('.active').next('.page_link').length==true){
		go_to_page(new_page);
	}	
}
function go_to_page(page_num){
	var show_per_page = parseInt($('#show_per_page').val());
	start_from = page_num * show_per_page;
	end_on = start_from + show_per_page;
	$('.pagin1').children().css('display', 'none').slice(start_from, end_on).css('display', 'block');
	/*get the page link that has longdesc attribute of the current page and add active class to it
	and remove that class from previously active page link*/
	$('.page_link[longdesc=' + page_num +']').addClass('active').removeClass('page_link').siblings('.active').removeClass('active').addClass('page_link');
	//update von der seitennr
	$('#current_page').val(page_num);
}
