/**
 * @author markus
 */
var thumbs_per_page = 5;
var thumbs = new Array();

$(function() {
	// show the first image
	$('#image').css({'background' : 'url("/uploads/pics/'+$('#content .textWithImage .textWithImageImg img:first').attr('title')+'")'});
	
	// generate menu of all items on page
	$('#content .textWithImage .textWithImageImg img').each (
		function() {
			thumbs.push($(this));
		}
	);	
});

// create the pager
$(document).ready(function(){
	$('#thumbMenu').pagination(thumbs.length, {
		items_per_page:thumbs_per_page, 
		callback:handlePaginationClick,
		num_display_entries:0,
		//next_text:'&rang;',
		next_text:'&gt;',
		next_show_always:false,
		//prev_text:'&lang;',
		prev_text:'&lt;',
		prev_show_always:false
	});
});

// handle the click on the pager
function handlePaginationClick(new_page_index, pagination_container) {
	var current = new_page_index*thumbs_per_page;
	$('#thumbnails').empty();
	
	for (var i=current;i<current+thumbs_per_page;i++) {
		if (thumbs[i] != undefined) {
			$('#thumbnails').append(thumbs[i]).css({'display' : 'block'});
			
			$('#thumbnails img:last').hover(function() {
				$('#image').css({'background' : 'url("/uploads/pics/'+$(this).attr('title')+'")'});
				$('#content').scrollTo($('#'+$(this).attr('name')));
			});
		}
	}
	
	$('#thumbnails img:last').css({'margin-right' : '0'});
	$('#thumbnails img').css({'display' : 'inline'});
	
	// if there is only one ce don't show the thumbnail menu
	if (thumbs.length <= 1) { $('#thumbnails').empty(); }
	
	return false;
}
