(function (a) {
	a.fn.contentSlider = function (c) {
		var b = {
			wrapperId: "sliderControls",
			active: null,
			navId: "sliderNav",
			prevId: "sliderPrev",
			prevText: "<",
			nextId: "sliderNext",
			nextText: ">",
			controlsShow: true,
			controlsBefore: "",
			controlsAfter: "",
			controlsFade: true,
			firstId: "firstBtn",
			firstText: "First",
			firstShow: false,
			lastId: "lastBtn",
			lastText: "Last",
			lastShow: false,
			vertical: false,
			speed: 2200,
			auto: false,
			pause: 2000,
			continuous: true,
			numeric: false,
			totalId: "sliderCount",
			current: "sliderCurrent",
			separator: "sliderSeparator",
			navigationOn: "#banner_container",
			separatorText: "/",
			total: "sliderTotal",
			showTotal: true,
			numericId: "sliderPagination",
			hideSingle: true,
			before: function () {},
			after: function () {}
		};
		var c = a.extend(b, c);
		this.each(function () {
			var v = a(this);
			var C = a("li", v).length;
			var A = a("li", v).width();
			var u = a("li", v).height();
			var x;
			var q;
			var o = true;
			v.width(A);
			v.height(u);
			v.css("overflow", "hidden");
			var n = C - 1;
			var B = 0;
			if (c.continuous) {
				a("ul", v).prepend(a("ul li:last-child", v).clone().css("margin-left", "-" + A + "px"));
				a("ul", v).append(a("ul li:nth-child(2)", v).clone());
				a("ul", v).css("width", (C + 1) * A)
			}
			if (!c.vertical) {
				a("li", v).css("float", "left")
			}
			if (c.controlsShow && (C > 1 || (C <= 1 || c.hideSingle))) {
				q = '<div id="' + c.wrapperId + '" class="sliderControls">';
				q += c.controlsBefore;
				if (c.numeric) {
					q += '<ul id="' + c.numericId + '"></ul>'
				}
				if (c.showTotal) {
					q += '<p id="' + c.totalId + '" class="sliderCount';
					if (C <= 1) {
						q += ' singleCount'
					}
					q += '">';
					q += '<span id="' + c.current + '" class="sliderCurrent">1</span>';
					q += '<span id="' + c.separator + '" class="sliderSeparator">' + c.separatorText + "</span>";
					q += '<span id="' + c.total + '" class="sliderTotal">' + C + "</span>";
					q += "</p>"
				}
				if (C > 1) {
					q += '<ul id="' + c.navId + '">';
					if (c.firstShow) {
						q += '<li id="' + c.firstId + '"><a href="javascript:void(0);">' + c.firstText + "</a></li>"
					}
					q += ' <li id="' + c.prevId + '"><a href="javascript:void(0);">' + c.prevText + "</a></li>";
					q += ' <li id="' + c.nextId + '"><a href="javascript:void(0);">' + c.nextText + "</a></li>";
					if (c.lastShow) {
						q += ' <li id="' + c.lastId + '"><a href="javascript:void(0);">' + c.lastText + "</a></li>"
					}
					q += "</ul>"
				}
				q += c.controlsAfter;
				q += "</div>";
				if (!c.navigationOn) {
					a(v).after(q)
				} else {
					a(c.navigationOn).after(q)
				}
				if (c.numeric) {
					for (var r = 0; r < C; r++) {
						a(document.createElement("li")).attr("id", c.numericId + (r + 1)).html("<a rel=" + r + ' href="javascript:void(0);">' + (r + 1) + "</a>").appendTo(a("#" + c.numericId)).click(function () {
							c.before.call();
							d(a("a", a(this)).attr("rel"), true)
						})
					}
				} else {
					a("a", "#" + c.nextId).click(function () {
						c.before.call();
						d("next", true)
					});
					a("a", "#" + c.prevId).click(function () {
						c.before.call();
						d("prev", true)
					});
					a("a", "#" + c.firstId).click(function () {
						c.before.call();
						d("first", true)
					});
					a("a", "#" + c.lastId).click(function () {
						c.before.call();
						d("last", true)
					})
				}
			}
			function f(g) {
				g = parseInt(g) + 1;
				a("li", "#" + c.numericId).removeClass("current");
				a("li#" + c.numericId + g).addClass("current");
				a("#" + c.current).html(g)
			}
			function z() {
				if (B > n) {
					B = 0
				}
				if (B < 0) {
					B = n
				}
				if (!c.vertical) {
					a("ul", v).css("margin-left", (B * A * -1))
				} else {
					a("ul", v).css("margin-left", (B * u * -1))
				}
				o = true;
				if (c.numeric) {
					f(B)
				}
			}
			function y(g) {
				var j = B;
				B = g;
				var i = Math.abs(j - B);
				var h = i * c.speed;
				if (!c.vertical) {
					p = (B * A * -1);
					v.children("ul:first").animate({
						marginLeft: p
					}, {
						queue: false,
						complete: z
					})
				} else {
					p = (B * u * -1);
					v.children("ul:first").animate({
						marginTop: p
					}, {
						queue: false,
						complete: z
					})
				}
				if (B + 1 <= 0) {
					x = C
				} else {
					if (B + 1 > C) {
						x = 1
					} else {
						x = B + 1
					}
				}
				a("#" + c.current).html(x)
			}
			function d(h, g) {
				if (o) {
					o = false;
					var k = B;
					switch (h) {
					case "next":
						B = (k >= n) ? (c.continuous ? B + 1 : n) : B + 1;
						break;
					case "prev":
						B = (B <= 0) ? (c.continuous ? B - 1 : 0) : B - 1;
						break;
					case "first":
						B = 0;
						break;
					case "last":
						B = n;
						break;
					default:
						B = h;
						break
					}
					var j = Math.abs(k - B);
					var i = j * c.speed;
					if (!c.vertical) {
						p = (B * A * -1);
						a("ul", v).animate({
							marginLeft: p
						}, {
							queue: false,
							duration: i,
							complete: function () {
								z();
								c.after.call(v)
							}
						})
					} else {
						p = (B * u * -1);
						a("ul", v).animate({
							marginTop: p
						}, {
							queue: false,
							duration: i,
							complete: function () {
								z();
								c.after.call(v)
							}
						})
					}
					if (!c.continuous && c.controlsFade) {
						if (B == n) {
							a("a", "#" + c.nextId).hide();
							a("a", "#" + c.lastId).hide()
						} else {
							a("a", "#" + c.nextId).show();
							a("a", "#" + c.lastId).show()
						}
						if (B == 0) {
							a("a", "#" + c.prevId).hide();
							a("a", "#" + c.firstId).hide()
						} else {
							a("a", "#" + c.prevId).show();
							a("a", "#" + c.firstId).show()
						}
					}
					if (g) {
						clearTimeout(e)
					}
					if (c.auto && h == "next" && !g) {
						e = setTimeout(function () {
							d("next", false)
						}, j * c.speed + c.pause)
					}
					if (B + 1 <= 0) {
						x = C
					} else {
						if (B + 1 > C) {
							x = 1
						} else {
							x = B + 1
						}
					}
					a("#" + c.current).html(x)
				}
			}
			var e;
			if (a(".current", v).length) {
				y(a("li", v).index(a(".current")) - 1);
				c.after.call()
			}
			if (c.auto) {
				e = setTimeout(function () {
					d("next", false)
				}, c.pause)
			}
			if (c.numeric) {
				f(0)
			}
			if (!c.continuous && c.controlsFade) {
				a("a", "#" + c.prevId).hide();
				a("a", "#" + c.firstId).hide()
			}
		})
	}
})(jQuery);
