function rotateLeft (image, stopRotation) {
	if (!stopRotation) {
		$(image).rotate( {
			animateTo: -7,
			duration: 150,
			callback: function() { rotateRight(image, stopRotation); }
		});
	} else {
		rotateDefault(image);
	}
}

function rotateRight (image, stopRotation) {
	$(image).rotate( {
		animateTo: 4,
		duration: 150,
		callback: function() { rotateLeft(image, !stopRotation); }
	});
}

function rotateDefault(image) {
	$(image).rotate( {
		animateTo: 0,
		duration: 300
	});
}

function getRandomAngle() {
	//	at least 3, maximum 8
	var randomAngle = Math.round(Math.random() * 3) + 5;
	//	positive or negative?
	return (Math.round(Math.random() * 2) % 2 == 0) ? (-1) * randomAngle : randomAngle;
}

$(document).ready(function() {

	//	rotate linked image
	$('a.foto').hover(function() {
		rotateLeft($(this).children('img'), false);
	}, function() {
		rotateDefault($(this).children('img'));
	});

	//	rotate navigation entry
	$('#navigation span').hover(function() {
		$(this).rotate( {
			animateTo: getRandomAngle(),
			duration: 150,
			callback: function() {
				$(this).rotate( {
					animateTo: 0,
					duration: 200
				});
			}
		});
	}, function() {
		$(this).rotate( {
			animateTo: 0,
			duration: 100
		});
	});

});

