/*
 * Some custom jQuery effects
 */

/*
 * FadeOut then SlideUp
 */
(function(jQuery){
  jQuery.fn.fadeOutAndSlideUp = function(speed) {
  	return this.fadeTo(speed, 0.01, function() { 	// fade
  	  jQuery(this).slideUp(speed, function() {		// slide up
  	    jQuery(this).remove();						// remove from DOM
  	  });
  	});
  };
})(jQuery);


/*
 * change color of element to param @color
 * and go back to original color. Useful
 * to make a change noticed by user.
 */
(function(jQuery){
  jQuery.fn.colorFlash = function(goto_color, speed1, speed2) {
	var original = this.css('color');
	return this.animate({
	  color: goto_color
	}, speed1).animate({
	  color: original
	}, speed2);
  };
})(jQuery);


/*
 * This function toggle visibility of the given element by slideUp or down
 */

(function(jQuery){
	jQuery.fn.toggleUpAndDown = function(height, duration) {

		if(this.is(':visible')) {
			// element is visible, so hide it
			return this.animate({ height: 0}, { duration: duration, complete: function() {
				jQuery(this).hide();
			}});
		}
		else {
			// element is not visible, so show it
			return this.show().animate({ height: height }, { duration: duration });
		}
	};
})(jQuery);