$(function() {
	var timer = 5000;
	var fade = 1000;

	$('.highlight').each(function() {
	
		if ($(this).find('img').size() > 1) {
		
			var images = $(this).find('img');
			var imageCount = images.size();
			var active = 0;
		
			images.hide()
				  .css({ 'position': 'absolute', 'z-index': '1', 'top': 0, 'left': 0 })
				  .eq(0)
				  .show()
				  .css('z-index', '2');
				  
			setTimeout(function() { cycleImages(images, imageCount, active); }, timer);
		
		}
	
	});
		
	
	function cycleImages(images, imageCount, active) {
		images.eq(active++).fadeOut(fade, function() { $(this).css('z-index', '1'); });
		
		if (active == imageCount)
			active = 0;
			
		images.eq(active).fadeIn(fade, function() { 
			$(this).css('z-index', '2'); 
		
			var url = $(this).data('href');
			
			if (url)
				$(this).closest('a').attr('href', url);
		});
		
		setTimeout(function() { cycleImages(images, imageCount, active); }, timer);
	}
	
	$('.highlight a').tooltip({
		'track': true,
		'delay': 0,
		'showURL': false
	});
});
