var bigImage = 0;
var smallLeftImage = 0;
var allImagesSize;
var thumb_list = new Array();
var mini_list = new Array();
var normal_list = new Array();

function changeBigImage(i) {
	
	$('#lb_'+bigImage).css('display', 'none');
	bigImage = (smallLeftImage+i)%allImagesSize;
	$('#lb_'+bigImage).css('display', 'block');
	//document.getElementById('bigImage').src = mini_list[bigImage];
	//document.getElementById('bigImageLink').href = normal_list[bigImage];
	
	//if(normal_list.length > 0){
	//	lightbox_liste = '';
	//	for(n=0;n<normal_list.length;n++){
	//		if (n == bigImage) {
	//			lightbox_liste += '<a rel="lightbox[lb001]" href="' + normal_list[n] + '"><img height="193" id="bigImage" alt="Titelbild" src="'+mini_list[n]+'" /></a>';
	//		}
	//		else {
	//			lightbox_liste += '<a rel="lightbox[lb001]" href="' + normal_list[n] + '"></a>';
	//		}
	//	}
	//}
}

function moveLeft() {
	smallLeftImage -= 1;
	
	if(smallLeftImage < 0) smallLeftImage += allImagesSize;
	setImageSources()
}

function moveRight() {
	smallLeftImage += 1;
	smallLeftImage %= allImagesSize;
	setImageSources()
}

function setImageSources() {
	if(thumb_list.length > 1)document.getElementById('smallImage1').src = thumb_list[smallLeftImage];
	if(thumb_list.length > 1)document.getElementById('smallImage2').src = thumb_list[(smallLeftImage+1)%allImagesSize];	
	if(thumb_list.length > 2)document.getElementById('smallImage3').src = thumb_list[(smallLeftImage+2)%allImagesSize];
}

function initSmallGallery() {
	allImagesSize = thumb_list.length;
	setImageSources();
	
	if(normal_list.length > 0){
		lightbox_liste = '';
		for(n=0;n<normal_list.length;n++){
			lightbox_liste += '<a id="lb_'+n+'" rel="lightbox[lb001]" href="' + normal_list[n] + '" style="display:none;"><img height="193" id="bigImage" alt="Titelbild" src="'+mini_list[n]+'" /></a>';
		}
		$('div#hauptbild').html(lightbox_liste);
	}
	
	changeBigImage(0);
}
