(function($) {
	function TestimonialScenario(obj, opts) {
		var defaults = {
			sels: {
				img:         ".testimonial-content .icon",
				blockquote:  ".testimonial-content blockquote",
				username:    ".testimonial-username",
				text:		 ".testimonial-content blockquote p",
				quote_left:  ".testimonial-content .quote-left",
				quote_right: ".testimonial-content .quote-right"
			}
		};
		this.obj = obj;
		this.opts = $.extend(defaults, opts);
	}

	TestimonialScenario.prototype.extend = function(opts) {
		this.opts = $.extend(this.opts, opts);
	}

	TestimonialScenario.prototype.prev = function(testimonial, callback) {
		var instance = this;
		async.series([
			function(callback) {
				$(testimonial).find(instance.opts.sels.blockquote)
				.css({
					marginLeft: 0
				}).animate({
					marginLeft: "-10px"
				}, {
					duration: 500,
					easing:   "swing",
					complete: function() {
						callback();
					}
				});

				$(testimonial).find([
					instance.opts.sels.img,
					instance.opts.sels.username,
					instance.opts.sels.text,
					instance.opts.sels.quote_left,
					instance.opts.sels.quote_right
				].join(", "))
				.css({
					opacity: 1
				}).animate({
					opacity: 0
				}, {
					duration: 500,
					easing:   "swing"
				});
			}
			], function() {
				callback();
			});
	}

	TestimonialScenario.prototype.prev_after = function(testimonial, callback) {
		var instance = this;
		async.series([
			function(inner_callback) {
				$(testimonial).find(instance.opts.sels.blockquote)
				.css({
					marginLeft: "30px"
				}).animate({
					marginLeft: 0
				}, {
					duration: 500,
					easing:   "swing",
					complete: function() {
						inner_callback();
					}
				}
				);

				$(testimonial).find([
					instance.opts.sels.img,
					instance.opts.sels.username,
					instance.opts.sels.text,
					instance.opts.sels.quote_left,
					instance.opts.sels.quote_right
				].join(", "))
				.css({
					opacity: 0
				}).animate({
					opacity: 1
				}, {
					duration: 500,
					easing:   "swing"
				}
				);
			}
			], function() {
				callback();
			});
	}

	TestimonialScenario.prototype.next = function(testimonial, callback) {
		var instance = this;
		async.series([
			function(inner_callback) {
				$(testimonial).find(instance.opts.sels.blockquote)
				.css({
					marginLeft: 0
				}).animate({
					marginLeft: "10px"
				}, {
					duration: 500,
					easing:   "swing",
					complete: function() {
						inner_callback();
					}
				}
				);

				$(testimonial).find([
					instance.opts.sels.img,
					instance.opts.sels.username,
					instance.opts.sels.text,
					instance.opts.sels.quote_left,
					instance.opts.sels.quote_right
				].join(", "))
				.css({
					opacity: 1
				}).animate({
					opacity: 0
				}, {
					duration: 500,
					easing:   "swing"
				}
				);
			}
			], function() {
				callback();
			});
	}

	TestimonialScenario.prototype.next_after = function(testimonial, callback) {
		var instance = this;
		async.series([
			function(inner_callback) {
				$(testimonial).find(instance.opts.sels.blockquote)
				.css({
					marginLeft: "-30px"
				}).animate({
					marginLeft: 0
				}, {
					duration: 500,
					easing:   "swing",
					complete: function() {
						inner_callback();
					}
				}
				);

				$(testimonial).find([
					instance.opts.sels.img,
					instance.opts.sels.username,
					instance.opts.sels.text,
					instance.opts.sels.quote_left,
					instance.opts.sels.quote_right
				].join(", "))
				.css({
					opacity: 0
				}).animate({
					opacity: 1
				}, {
					duration: 500,
					easing:   "swing"
				}
				);
			}
			], function() {
				callback();
			});
	}

	$.fn.extend({
		TestimonialScenario: function(opts) {
			return this.each(
				function() {
					this.tsc = new TestimonialScenario(this, opts);
				});
		},
		TestimonialScenarioExtend: function(opts) {
			return this.each(
				function() {
					if(!this.tsc) {
						return;
					}
					this.tsc.extend(opts);
				});
		},
		TestimonialScenarioPrev: function(testimonial, callback) {
			return this.each(
				function() {
					if(!this.tsc) {
						return;
					}
					this.tsc.prev(testimonial, callback);
				});
		},
		TestimonialScenarioNext: function(testimonial, callback) {
			return this.each(
				function() {
					if(!this.tsc) {
						return;
					}
					this.tsc.next(testimonial, callback);
				});
		},
		TestimonialScenarioPrevAfter: function(testimonial, callback) {
			return this.each(
				function() {
					if(!this.tsc) {
						return;
					}
					this.tsc.prev_after(testimonial, callback);
				});
		},
		TestimonialScenarioNextAfter: function(testimonial, callback) {
			return this.each(
				function() {
					if(!this.tsc) {
						return;
					}
					this.tsc.next_after(testimonial, callback);
				});
		}
	});
})(jQuery);
