$(document).ready(function() {
	var animated_flower = function(e) {
		var original_top = parseInt(e.css('top'));
		var visible = false;
		
		e.hover(
			function() { // On-mouse-over
				
				visible = true;
				e.animate({'top': 0}, 400); // Slide down the stem (takes 400 msecs)
				
				// 300 msecs into the sliding, start fading in the sign
				setTimeout(function() {
					if(visible) { // If it's still slid down, fade in the sign (200 msecs)
						e.children('.sign').fadeIn(200);
					}
				}, 300);
				
			},
			function() { // On-mouse-out
				
				visible = false;
				
				// Immediately fade out the sign very quickly
				e.children('.sign').fadeOut(200);
				
				// Slide up the stem to its original top position
				e.animate({'top': original_top}, 400, function() {
					// After it's done sliding up, check to make sure the sign isn't visible
					if(e.children('.sign').is(':visible')) {
						e.children('.sign').fadeOut(200); // ...and fade it out if it is.
					}
				});
				
			}
		);
	}
	
	$('#home-flowers .flower').each(function(i, v) {
		new animated_flower($(v));
	});
	
});
