﻿/*!
* jQuery linear gradient effect plug-in.
* Requires jQuery UI.
* http://norimek.com/blog/page/jQuery-Plug-Ins.aspx
*
* Copyright 2011, Robert C. Barth
* Licensed under the MIT license.
* http://www.opensource.org/licenses/MIT
*
* Date: Sat Aug 27 13:00:00 2011 -0700
*/
(function ($, undefined) {

	$.effects.lineargradient = function (o) {

		return this.queue(function () {

			var $this = $(this),
			props = ['background-image'],
			times = o.options.times || 1,
			duration = o.duration || 1000,
			angle = o.options.angle || 0,
			stops = o.options.stops;

			$.effects.save($this, props);
			$this.css('percent', 0);

			for (var i = 0; i < times; i++) {

				$this.animate({ percent: 125 }, {
					queue: false,
					duration: duration,
					easing: o.options.easing,
					step: function (now, fx) {

						var gradientSpecifier = [ angle.toString() + 'deg, ' ]

						for (var ii = 0, l = stops.length; ii < l; ii++) {

							if ($.isArray(stops[ii])) {
								// Color
								gradientSpecifier.push(stops[ii][0].toString() + ' ');
								// Position
								gradientSpecifier.push(String(now + stops[ii][1]) + '%');
							} else {
								// Color only
								gradientSpecifier.push(stops[ii].toString());
							}

							if (ii < l - 1) {
								gradientSpecifier.push(', ');
							}
						}

						gradientSpecifier = gradientSpecifier.join('');

						$(fx.elem).css('background-image', '-webkit-linear-gradient(' + gradientSpecifier + ')');
						$(fx.elem).css('background-image', '-moz-linear-gradient(' + gradientSpecifier + ')');
						$(fx.elem).css('background-image', '-o-linear-gradient(' + gradientSpecifier + ')');
						$(fx.elem).css('background-image', 'linear-gradient(' + gradientSpecifier + ')');
					},
					complete: function () {

						$this.css('percent', 0);
						$.effects.restore($this, props);

						$this.dequeue();

						if (o.callback) {
							o.callback.apply(this, arguments);
						}
					}
				});
			}
		});
	};
})(jQuery);

