

$(document).ready(function() {
var link ='<a href="portraits.html"></a>';

$('.thumbs').each(function(i) {
	$(this).append(link);
});

	$('.hoch').each(function(i) {
		var name = $(this).attr('id');
		var neuname = $(this).attr('id') + '_container';
		$(this).clone().attr('id', neuname).addClass('container').appendTo('#thumbnails');
		//$('#'+neuname).wrap('a href="portraits.html" /');
		var anz_hf = $('#hochformate').children().length;
		var sel_hf = $('#hochformate img:eq('+getRnd(anz_hf)+')');
		//sel_hf.removeClass('hf');
		$('a', this).append(sel_hf);
		
		$(this).everyTime(getTimerRnd(), function() {
				var neuTn = $('#hochformate img:eq('+getRnd($('#hochformate').children().length)+')');
				$('#'+neuname).append(neuTn);
				$('#'+neuname).fadeIn('slow', function(){
					$('#hochformate').append($('#'+name+'>a').children());
					$('#'+name+'>a').append(neuTn);
					$(this).hide();
					$(this).empty();
				});
		});
		
	});
	
	$('.quer').each(function(i) {
		var name = $(this).attr('id');
		var neuname = $(this).attr('id') + '_container';
		$(this).clone().attr('id', neuname).addClass('container').appendTo('#thumbnails');
		var anz_hf = $('#querformate').children().length;
		var sel_hf = $('#querformate img:eq('+getRnd(anz_hf)+')');
		//sel_hf.removeClass('hf');
		$('a', this).append(sel_hf);
		
		$(this).everyTime(getTimerRnd(), function() {
				var neuTn = $('#querformate img:eq('+getRnd($('#querformate').children().length)+')');
				$('#'+neuname).append(neuTn);
				$('#'+neuname).fadeIn('slow', function(){
					$('#querformate').append($('#'+name+'>a').children());
					$('#'+name+'>a').append(neuTn);
					$(this).hide();
					$(this).empty();
				});
		});
	});
	
	/*
	hfTimer = $('.hoch').everyTime(5000, function() {
		$(this).stop(true,true).fadeOut(500);
		//galId++; 
		//if(galId >= galEle.length) {galId = 0;}
		//galEle.eq(galId).stop(true,false).fadeTo(500,1);
		//alert('hallo');
	});
*/
});

function getRnd(zahl) {
	return Math.floor(Math.random()*zahl);
}

function getTimerRnd() {
	return Math.floor(Math.random()*5000)+5000;
}


