
/**
 * 
 * Плагин jquery.bgcolor.js
 * Перемигивание двумя цветами фона элемента.
 * 
 * Требуются плагины:
 * jquery.color.js
 * jquery.timers.js
 * 
 * Использование:
 * $("td.blink").bgblink("white", "yellow", 100);
 * $("td.blink").bgblink(); Запуск без аргументов останавливает анимацию.
 * 
 */

jQuery.fn.bgblink = function(fromcolor, tocolor, duration) {
	if (fromcolor) {
		$(this).data("fromcolor", fromcolor);
		$(this).data("stop", false);
		$(this)
			.animate({ backgroundColor: tocolor }, duration, function(){ $(this).data("color", tocolor); })
			.everyTime(duration, function(){
				var color = ($(this).data("color") == tocolor) ? fromcolor : tocolor ;
				$(this).animate({ backgroundColor: color }, duration, function(){ 
					$(this).data("color", color); 
					
					if ($(this).data("stop"))
						$(this).css({ backgroundColor: $(this).data("fromcolor") });
					
				});
			});
	} else {
		$(this).stopTime();
		$(this).data("stop", true);
		
	}
	return $(this);
};