jQuery.fn.Exists = function() { return jQuery(this).length > 0; }

$(function() {
	setInterval(
		function() {
			var image = $('#magazine div.magazine_slideshow img:visible');
			var parent = image.parent();
			if (parent.hasClass('magazine_slideshow')) {
				if (image.siblings().Exists()) {
					image.fadeOut(2000);
					if (image.next().Exists()) image.next().fadeIn(2000);
					else image.siblings(':first').fadeIn(2000);
				}
			}
			else {
				if (parent.siblings().Exists()) {
					image.fadeOut(2000);
					if (parent.next().Exists()) parent.next().find('img').fadeIn(2000);
					else parent.siblings(':first').find('img').fadeIn(2000);
				}
			}
		},
		5000
	);
});
