function on_load() {
	$(document).ready(function() {
		if ($('.thumbs > a').length > 1) {
			$('.thumbs').attr('selected', $('.thumbs > a').length);
			$('.thumbs > a:eq(' + ($('.thumbs > a').length - 1) + ') > img').toggleClass('imgselected');
			$('.thumbs').attr('whatisnext', 'img');
			$('.thumbs').attr('timeoutID', setTimeout(function() { rotatePics();}, 9000));
		}
	});
	function rotatePics() {
		var numberOfPhotos = $('.thumbs > a').length;
		var selected = $('.thumbs').attr('selected');
		var nextphoto = Number(selected) + 1;
		if (nextphoto >= numberOfPhotos) nextphoto = 0;
		var whatisnext = $('.thumbs').attr('whatisnext');
		$('.thumbs img.imgselected').removeClass('imgselected');
		$('.thumbs > a:eq(' + ((nextphoto > 0) ? nextphoto - 1 : numberOfPhotos - 1) + ') > img').addClass('imgselected');
		if (whatisnext == 'img')  {
			$('.thumbs').prev().children('img').animate({ 'opacity': 1 }, 'fast', function(){
				$('.thumbs').prev().css({ 'backgroundImage': 'url(' + $('.thumbs > a:eq(' + nextphoto + ')').attr('photosrc') + ')' });
				$('.thumbs').attr('whatisnext', '');
				$('.thumbs').attr('selected', nextphoto);
				$('.thumbs').attr('timeoutID', setTimeout(function() { rotatePics();}, 9000));
			});
		}
		else {
			$('.thumbs').prev().children('img').animate({ 'opacity': 0 }, 'fast', function(){
				$('.thumbs').attr('whatisnext', 'img');
				$('.thumbs').attr('selected', nextphoto);
				$('.thumbs').prev().children('img').attr('src', $('.thumbs > a:eq(' + nextphoto + ')').attr('photosrc'));
				$('.thumbs').attr('timeoutID', setTimeout(function() { rotatePics();}, 9000));
			});
		}
	}
	$('.thumbs > a').click(function(event){
		clearTimeout($('.thumbs').attr('timeoutID'));
		var selected = $(this).index();
		var numberOfPhotos = $('.thumbs > a').length;
		var nextphoto = selected + 1;
		if (nextphoto >= numberOfPhotos) nextphoto = 0;
		var whatisnext = $('.thumbs').attr('whatisnext');
		$('.thumbs img.imgselected').removeClass('imgselected');
		$('.thumbs > a:eq(' + (nextphoto - 1) + ') > img').addClass('imgselected');
		if (whatisnext == 'img')  {
			$('.thumbs').prev().css({ 'backgroundImage': 'url(' + $('.thumbs > a:eq(' + selected + ')').attr('photosrc') + ')' });
			$('.thumbs').prev().children('img').attr('src', $('.thumbs > a:eq(' + nextphoto + ')').attr('photosrc'));
			$('.thumbs').attr('selected', nextphoto);
			$('.thumbs').attr('timeoutID', setTimeout(function() { rotatePics();}, 9000));
		}
		else {
			$('.thumbs').prev().children('img').attr('src', $('.thumbs > a:eq(' + selected + ')').attr('photosrc'));
			$('.thumbs').prev().css({ 'backgroundImage': 'url(' + $('.thumbs > a:eq(' + nextphoto + ')').attr('photosrc') + ')' });
			$('.thumbs').attr('selected', nextphoto);
			$('.thumbs').attr('timeoutID', setTimeout(function() { rotatePics();}, 9000));
		}
	});
}

