﻿/*
* TouchCarousel  v1.0
*
* Copyright 2011, Dmitry Semenov, http://dimsemenov.com
* 
*/

(function ($) {
	function TouchCarousel(g, h) {
		this.carouselRoot = $(g);
		var j = this;
		this._az = false;
		this._by = false;
		this._cx = "";
		this._dw = "";
		this._ev = "";
		this._fu;
		this._gt;
		this._hs;
		this._ir;
		this._jq;
		this._kp = 0;
		this.settings = $.extend({}, $.fn.touchCarousel.defaults, h);
		this._lo = this.carouselRoot.find(".touchcarousel-container");
		this._loStyle = this._lo[0].style;
		this._az1 = this._lo.wrap($('<div class="touchcarousel-wrapper" />')).parent();
		var k = this._lo.find(".touchcarousel-item");
		this.items = [];
		this.numItems = k.length;
		this._by1;
		this._cx1 = false;
		this._dw1 = 0;
		this._ev1 = 0;
		this._fu1 = 0;
		this._gt1 = false;
		this._hs1 = false;
		this._ir1 = false;
		if ('ontouchstart' in window) {
			this.hasTouch = true;
			this._cx = 'touchstart.rs';
			this._dw = 'touchmove.rs';
			this._ev = 'touchend.rs';
			this._jq1 = this.settings.baseTouchFriction
		} else {
			this.hasTouch = false;
			this._jq1 = this.settings.baseMouseFriction;
			if (this.settings.dragUsingMouse) {
				this._cx = 'mousedown.rs';
				this._dw = 'mousemove.rs';
				this._ev = 'mouseup.rs';
				this._kp1;
				this._lo1;
				var l = $.browser;
				if (l.msie || l.opera) {
					this._kp1 = this._lo1 = "move"
				} else if (l.mozilla) {
					this._kp1 = "-moz-grab";
					this._lo1 = "-moz-grabbing"
				}
				this._mn1()
			} else {
				this._az1.addClass('auto-cursor')
			}
		}
		if (this.hasTouch || this.settings.useWebkit3d) {
			if (('WebKitCSSMatrix' in window && 'm11' in new WebKitCSSMatrix())) {
				this._lo.css({
					'-webkit-transform-origin': '0 0',
					'-webkit-transform': 'translateZ(0)'
				});
				this._ir1 = true
			}
		}
		if (this._ir1) {
			this._az2 = '-webkit-transform';
			this._by2 = 'translate3d(';
			this._cx2 = 'px, 0, 0)'
		} else {
			this._az2 = 'left';
			this._by2 = '';
			this._cx2 = 'px'
		}
		if (this.hasTouch) {
			this.settings.directionNavAutoHide = false
		}
		if (!this.settings.directionNav) {
			if (this.settings.loopItems) {
				this._dw2 = true;
				this._ev2 = true
			} else {
				this._dw2 = false;
				this._ev2 = false
			}
			this.settings.loopItems = true
		}
		var m, jqItem, dataSRC, slideImg, currPosX = 0;
		k.eq(this.numItems - 1).addClass('lastci');
		k.each(function (c) {
			jqItem = $(this);
			m = {};
			m.item = jqItem;
			m.index = c;
			m.posX = currPosX;
			m.width = (jqItem.outerWidth(true) || j.settings.itemFallbackWidth);
			currPosX += m.width;
			if (!this.hasTouch) {
				jqItem.find('a').bind('click.touchcarousel', function (e) {
					if (j._cx1) {
						e.preventDefault();
						return false
					}
				})
			} else {
				var d = jqItem.find('a');
				var f;
				d.each(function () {
					f = $(this);
					f.data('tc-href', f.attr('href'));
					f.data('tc-target', f.attr('target'));
					f.attr('href', '#');
					f.bind('click', function (e) {
						e.preventDefault();
						if (j._cx1) {
							return false
						} else {
							var a = $(this).data('tc-href');
							var b = $(this).data('tc-target');
							if (!b || b.toLowerCase() === '_fu2') {
								window.location.href = a
							} else {
								window.open(a)
							}
						}
					})
				})
			}
			jqItem.find('.non-draggable').bind(j._cx, function (e) {
				j._cx1 = false;
				e.stopImmediatePropagation()
			});
			j.items.push(m)
		});
		this._gt2 = this._fu = currPosX;
		if (this.settings.itemsPerMove > 0) {
			this._hs2 = this.settings.itemsPerMove
		} else {
			this._hs2 = 1
		}
		if (this.settings.pagingNav) {
			this.settings.snapToItems = true;
			this._ir2 = true;
			this._jq2 = Math.ceil(this.numItems / this._hs2);
			this._kp2 = 0;
			if (this.settings.pagingNavControls) {
				this._lo2 = $('<div class="tc-paging-container"><div class="tc-paging-centerer"><div class="tc-paging-centerer-inside"></div></div></div>');
				var n = this._lo2.find('.tc-paging-centerer-inside');
				var o;
				for (var i = 1; i <= this._jq2; i++) {
					o = $('<a class="tc-paging-item" href="#">' + i + '</a>').data('tc-id', i);
					if (i === this._kp2 + 1) {
						o.addClass('current')
					}
					n.append(o)
				}
				this._mn2 = n.find(".tc-paging-item").click(function (e) {
					e.preventDefault();
					j.goTo(($(e.currentTarget).data('tc-id') - 1) * j._hs2)
				});
				this._az1.after(this._lo2)
			}
		} else {
			this._ir2 = false
		}
		this._lo.css({
			width: currPosX
		});
		if (this.settings.directionNav) {
			this._az1.after("<a href='#' class='arrow-holder left'><span class='arrow-icon left'></span></a> <a href='#' class='arrow-holder right'><span class='arrow-icon right'></span></a>");
			this.arrowLeft = this.carouselRoot.find(".arrow-holder.left");
			this.arrowRight = this.carouselRoot.find(".arrow-holder.right");
			if (this.arrowLeft.length < 1 || this.arrowRight.length < 1) {
				this.settings.directionNav = false
			} else if (this.settings.directionNavAutoHide) {
				this.arrowLeft.hide();
				this.arrowRight.hide();
				this.carouselRoot.one("mousemove.arrowshover", function () {
					j.arrowLeft.fadeIn("fast");
					j.arrowRight.fadeIn("fast")
				});
				this.carouselRoot.hover(function () {
					j.arrowLeft.fadeIn("fast");
					j.arrowRight.fadeIn("fast")
				}, function () {
					j.arrowLeft.fadeOut("fast");
					j.arrowRight.fadeOut("fast")
				})
			}
			this._by3(0);
			if (this.settings.directionNav) {
				this.arrowRight.click(function (e) {
					e.preventDefault();
					if (j.settings.loopItems && !j._gt1 || !j._ev2) j.next()
				});
				this.arrowLeft.click(function (e) {
					e.preventDefault();
					if (j.settings.loopItems && !j._gt1 || !j._dw2) j.prev()
				})
			}
		}
		this.carouselWidth;
		this._cx3 = 'onorientationchange' in window ? 'orientationchange.touchcarousel' : 'resize.touchcarousel';
		var p;
		$(window).bind(this._cx3, function () {
			if (p) clearTimeout(p);
			p = setTimeout(function () {
				j.updateCarouselSize(false)
			}, 100)
		});
		if (this.settings.scrollbar) {
			this._dw3 = $("<div class='scrollbar-holder'><div class='scrollbar" + (this.settings.scrollbarTheme.toLowerCase() === "light" ? " light" : " dark") + "'></div></div>");
			this._dw3.appendTo(this.carouselRoot);
			this.scrollbarJQ = this._dw3.find('.scrollbar');
			this._ev3 = "";
			this._fu3 = this.scrollbarJQ[0].style;
			this._gt3 = 0;
			if (this.settings.scrollbarAutoHide) {
				this._hs3 = false;
				this.scrollbarJQ.css("opacity", 0)
			} else {
				this._hs3 = true
			}
		} else {
			this.settings.scrollbarAutoHide = false
		}
		this.updateCarouselSize(true);
		this._az1.bind(this._cx, function (e) {
			j._ir3(e)
		});
		if (this.settings.autoplay && this.settings.autoplayDelay > 0) {
			this._jq3 = false;
			this.autoplayTimer = '';
			this.wasAutoplayRunning = true;
			if (!this.hasTouch) {
				this.carouselRoot.hover(function () {
					j._jq3 = true;
					j._kp3()
				}, function () {
					j._jq3 = false;
					j._lo3()
				})
			}
			this.autoplay = true;
			this._mn3()
		} else {
			this.autoplay = false
		}
		if (this.settings.keyboardNav) {
			$(document).bind("keydown.touchcarousel", function (e) {
				if (!j._gt1) {
					if (e.keyCode === 37) {
						j.prev()
					} else if (e.keyCode === 39) {
						j.next()
					}
				}
			})
		}
		this.carouselRoot.css("overflow", "visible")
	}
	TouchCarousel.prototype = {
		goTo: function (a, b) {
			var c = this.items[a];
			if (c) {
				if (!b && this.autoplay && this.settings.autoplayStopAtAction) {
					this.stopAutoplay()
				}
				this._az4(a);
				this.endPos = this._by4();
				var d = -c.posX;
				if (d > 0) {
					d = 0
				} else if (d < this.carouselWidth - this._gt2) {
					d = this.carouselWidth - this._gt2
				}
				this.animateTo(d, this.settings.transitionSpeed, "easeInOutSine")
			}
		},
		next: function (a) {
			var b = this._by4();
			var c = this._cx4(b).index;
			if (!this._ir2) {
				c = c + this._hs2;
				if (this.settings.loopItems) {
					if (b <= this.carouselWidth - this._gt2) {
						c = 0
					}
				}
				if (c > this.numItems - 1) {
					c = this.numItems - 1
				}
			} else {
				var d = this._kp2 + 1;
				if (d > this._jq2 - 1) {
					if (this.settings.loopItems) {
						c = 0
					} else {
						c = (this._jq2 - 1) * this._hs2
					}
				} else {
					c = d * this._hs2
				}
			}
			this.goTo(c, a)
		},
		prev: function (a) {
			var b = this._by4();
			var c = this._cx4(b).index;
			if (!this._ir2) {
				c = c - this._hs2;
				if (c < 0) {
					if (this.settings.loopItems) {
						if (b < 0) {
							c = 0
						} else {
							c = this.numItems - 1
						}
					} else {
						c = 0
					}
				}
			} else {
				var d = this._kp2 - 1;
				if (d < 0) {
					if (this.settings.loopItems) {
						c = (this._jq2 - 1) * this._hs2
					} else {
						c = 0
					}
				} else {
					c = d * this._hs2
				}
			}
			this.goTo(c, a)
		},
		getCurrentId: function () {
			var a = this._cx4(this._by4()).index;
			return a
		},
		setXPos: function (a, b) {
			if (!b) {
				this._loStyle[this._az2] = (this._by2 + a + this._cx2)
			} else {
				this._fu3[this._az2] = (this._by2 + a + this._cx2)
			}
		},
		stopAutoplay: function () {
			this._kp3();
			this.autoplay = false;
			this.wasAutoplayRunning = false
		},
		resumeAutoplay: function () {
			this.autoplay = true;
			if (!this.wasAutoplayRunning) {
				this._lo3()
			}
		},
		updateCarouselSize: function (a) {
			var b = this;
			this.carouselWidth = this.carouselRoot.width();
			if (this.settings.scrollToLast) {
				var c = 0;
				if (this._ir2) {
					var d = (this.numItems % this._hs2);
					if (d > 0) {
						for (var i = this.numItems - d; i < this.numItems; i++) {
							c += this.items[i].width
						}
					} else {
						c = this.carouselWidth
					}
				} else {
					c = this.items[this.numItems - 1].width
				}
				this._gt2 = this._fu + this.carouselWidth - c
			} else {
				this._gt2 = this._fu
			}
			if (this.settings.scrollbar) {
				var e = Math.round(this._dw3.width() / (this._gt2 / this.carouselWidth));
				this.scrollbarJQ.css('width', e);
				this._gt3 = this._dw3.width() - e
			}
			if (!this.settings.scrollToLast) {
				if (this.carouselWidth >= this._fu) {
					this._hs1 = true;
					if (!this.settings.loopItems) {
						this._ev2 = true;
						this.arrowRight.addClass("disabled");
						this._dw2 = true;
						this.arrowLeft.addClass("disabled")
					}
					this.setXPos(0);
					return
				} else if (this._hs1) {
					this._hs1 = false;
					this._ev2 = false;
					this._dw2 = false;
					this.arrowRight.removeClass("disabled");
					this.arrowLeft.removeClass("disabled")
				}
			}
			if (!a) {
				var f = this.endPos = this._by4();
				if (f > 0) {
					f = 0
				} else if (f < this.carouselWidth - this._gt2) {
					f = this.carouselWidth - this._gt2
				}
				this.animateTo(f, 300, "easeInOutSine")
			}
		},
		animateTo: function (a, b, c, d, e, f, g) {
			if (this.settings.onAnimStart !== null) {
				this.settings.onAnimStart.call(this)
			}
			if (this.autoplay && this.autoplayTimer) {
				this.wasAutoplayRunning = true;
				this._kp3()
			}
			this._dw4();
			var h = this;
			var i = this.settings.scrollbar,
                prop = h._az2,
                pref = h._by2,
                suf = h._cx2,
                from = {
                	containerPos: this.endPos
                },
                to = {
                	containerPos: a
                },
                to2 = {
                	containerPos: e
                },
                e = d ? e : a,
                dContainer = h._loStyle;
			h._by = true;
			if (i) {
				var j = this._fu3;
				var k = h._gt2 - h.carouselWidth;
				if (this.settings.scrollbarAutoHide) {
					if (!this._hs3) {
						this._ev4()
					}
				}
			}
			this._by3(e);

			function animationComplete() {
				h._by = false;
				h._mn3();
				if (h.settings.scrollbarAutoHide) {
					h._fu4()
				}
				if (h.settings.onAnimComplete !== null) {
					h.settings.onAnimComplete.call(h)
				}
			}
			this._by1 = $(from).animate(to, {
				duration: b,
				easing: c,
				step: function () {
					if (i) {
						j[prop] = (pref + Math.round((h._gt3) * (-this.containerPos / k)) + suf)
					}
					dContainer[prop] = (pref + Math.round(this.containerPos) + suf)
				},
				complete: function () {
					if (d) {
						h._by1 = $(to).animate(to2, {
							duration: f,
							easing: g,
							step: function () {
								if (i) {
									j[prop] = (pref + Math.round((h._gt3) * (-this.containerPos / k)) + suf)
								}
								dContainer[prop] = (pref + Math.round(this.containerPos) + suf)
							},
							complete: function () {
								if (i) {
									j[prop] = (pref + Math.round((h._gt3) * (-to2.containerPos / k)) + suf)
								}
								dContainer[prop] = (pref + Math.round(to2.containerPos) + suf);
								animationComplete()
							}
						})
					} else {
						if (i) {
							j[prop] = (pref + Math.round((h._gt3) * (-to.containerPos / k)) + suf)
						}
						dContainer[prop] = (pref + Math.round(to.containerPos) + suf);
						animationComplete()
					}
				}
			})
		},
		destroy: function () {
			this.stopAutoplay();
			this._az1.unbind(this._cx);
			$(document).unbind(this._dw).unbind(this._ev);
			$(window).unbind(this._cx3);
			if (this.settings.keyboardNav) {
				$(document).unbind("keydown.touchcarousel")
			}
			this.carouselRoot.remove()
		},
		_az4: function (a) {
			if (this._ir2) {
				var b = this._gt4(a);
				this._kp2 = b;
				if (this.settings.pagingNavControls) {
					this._mn2.removeClass('current');
					this._mn2.eq(b).addClass('current')
				}
			}
		},
		_gt4: function (a) {
			var b = this._hs2;
			for (var i = 0; i < this._jq2; i++) {
				if (a >= i * b && a < i * b + b) {
					return i
				}
			}
			if (a < 0) {
				return 0
			} else if (a >= this._jq2) {
				return this._jq2 - 1
			}
			return false
		},
		_hs4: function () {
			if (!this.settings.loopItems) {
				if (this._dw2) {
					this._dw2 = false;
					this.arrowLeft.removeClass("disabled")
				} else if (this._ev2) {
					this._ev2 = false;
					this.arrowRight.removeClass("disabled")
				}
			}
		},
		_az3: function () {
			if (!this._dw2 && !this.settings.loopItems) {
				this._dw2 = true;
				this.arrowLeft.addClass("disabled");
				if (this._ev2) {
					this._ev2 = false;
					this.arrowRight.removeClass("disabled")
				}
			}
		},
		_ir4: function () {
			if (!this._ev2 && !this.settings.loopItems) {
				this._ev2 = true;
				this.arrowRight.addClass("disabled");
				if (this._dw2) {
					this._dw2 = false;
					this.arrowLeft.removeClass("disabled")
				}
			}
		},
		_cx4: function (a) {
			var b = this;
			a = -a;
			var c;
			for (var i = 0; i < b.numItems; i++) {
				c = b.items[i];
				if (a >= c.posX && a < c.posX + c.width) {
					return c
				}
			}
			return -1
		},
		_mn3: function () {
			if (this.autoplay) {
				if (this.wasAutoplayRunning) {
					if (!this._jq3) {
						this._lo3()
					}
					this.wasAutoplayRunning = false
				}
			}
		},
		_fu4: function () {
			var a = this;
			this._hs3 = false;
			if (this._ev3) {
				clearTimeout(this._ev3)
			}
			this._ev3 = setTimeout(function () {
				a.scrollbarJQ.animate({
					opacity: 0
				}, 150, "linear")
			}, 450)
		},
		_ev4: function () {
			this._hs3 = true;
			if (this._ev3) {
				clearTimeout(this._ev3)
			}
			this.scrollbarJQ.stop().animate({
				opacity: 1
			}, 150, "linear")
		},
		_dw4: function () {
			if (this._by1) {
				this._by1.stop()
			}
		},
		_lo3: function () {
			if (this.autoplay) {
				var a = this;
				if (!this.autoplayTimer) {
					this.autoplayTimer = setInterval(function () {
						if (!a._jq4 && !a._by) {
							a.next(true)
						}
					}, this.settings.autoplayDelay)
				}
			}
		},
		_kp3: function () {
			if (this.autoplayTimer) {
				clearInterval(this.autoplayTimer);
				this.autoplayTimer = ''
			}
		},
		_by4: function (a) {
			var b = !a ? this._lo : this.scrollbarJQ;
			if (!this._ir1) {
				return Math.round(b.position().left)
			} else {
				var c = b.css("-webkit-transform");
				var d = c.replace(/^matrix\(/i, '').split(/, |\)$/g);
				return parseInt(d[4], 10)
			}
		},
		_ir3: function (e) {
			if (!this._jq4) {
				if (this.autoplay && this.settings.autoplayStopAtAction) {
					this.stopAutoplay()
				}
				this._dw4();
				if (this.settings.scrollbarAutoHide) {
					this._ev4()
				}
				var a;
				if (this.hasTouch) {
					this._az = false;
					var b = e.originalEvent.touches;
					if (b && b.length > 0) {
						a = b[0]
					} else {
						return false
					}
				} else {
					a = e;
					e.preventDefault()
				}
				this._kp4();
				this._jq4 = true;
				var c = this;
				if (this._ir1) {
					c._lo.css({
						'-webkit-transition-duration': '0',
						'-webkit-transition-property': 'none'
					})
				}
				$(document).bind(this._dw, function (e) {
					c._lo4(e)
				});
				$(document).bind(this._ev, function (e) {
					c._mn4(e)
				});
				this._az5 = this._by4();
				this._ir = a.clientX;
				this._cx1 = false;
				this._kp = e.timeStamp || Date.now();
				this._fu1 = 0;
				this._ev1 = this._dw1 = a.clientX;
				this._by5 = a.clientY
			}
		},
		_lo4: function (e) {
			var a = (e.timeStamp || Date.now());
			var b;
			if (this.hasTouch) {
				if (this._az) {
					return false
				}
				var c = e.originalEvent.touches;
				if (c.length > 1) {
					return false
				}
				b = c[0];
				if (Math.abs(b.clientY - this._by5) > Math.abs(b.clientX - this._dw1) + 3) {
					if (this.settings.lockAxis) {
						this._az = true
					}
					return false
				}
				e.preventDefault()
			} else {
				b = e;
				e.preventDefault()
			}
			this._jq = b.clientX;
			this._cx5 = this._dw5;
			var d = b.clientX - this._ev1;
			if (this._cx5 != d) {
				this._dw5 = d
			}
			if (d != 0) {
				var f = this._az5 + this._fu1;
				if (f >= 0) {
					d = d / 4;
					this._az3()
				} else if (f <= this.carouselWidth - this._gt2) {
					this._ir4();
					d = d / 4
				} else {
					this._hs4()
				}
				this._fu1 += d;
				this.setXPos(f);
				if (this.settings.scrollbar) {
					this.setXPos((this._gt3) * (-f / (this._gt2 - this.carouselWidth)), true)
				}
			}
			this._ev1 = b.clientX;
			if (a - this._kp > 350) {
				this._kp = a;
				this._ir = b.clientX
			}
			if (this.settings.onDragStart !== null) {
				this.settings.onDragStart.call(this)
			}
			return false
		},
		_mn4: function (e) {
			if (this._jq4) {
				var b = this;
				this._jq4 = false;
				this._mn1();
				this.endPos = this._by4();
				this.isdrag = false;
				$(document).unbind(this._dw).unbind(this._ev);
				if (this.endPos == this._az5) {
					this._cx1 = false;
					if (this.settings.scrollbarAutoHide) {
						this._fu4()
					}
					return
				} else {
					this._cx1 = true
				}
				var c = (this._jq - this._ir);
				var d = Math.max(40, (e.timeStamp || Date.now()) - this._kp);
				var f = 0.5,
                    mass = 2,
                    v0 = Math.abs(c) / d;

				function getCorrectXPos(a) {
					if (a > 0) {
						a = 0
					} else if (a < b.carouselWidth - b._gt2) {
						a = b.carouselWidth - b._gt2
					}
					return a
				}
				if (!this.settings.snapToItems) {
					var g = 0;
					if (v0 <= 2) {
						f = this._jq1 * 3.5;
						g = 0
					} else if (v0 > 2 && v0 <= 3) {
						f = this._jq1 * 4;
						g = 200
					} else if (v0 > 3) {
						g = 300;
						if (v0 > 4) {
							v0 = 4;
							g = 400;
							f = this._jq1 * 6
						}
						f = this._jq1 * 5
					}
					var S = (v0 * v0 * mass) / (2 * f);
					S = S * (c < 0 ? -1 : 1);
					var t = v0 * mass / f + g;
					if (this.endPos + S > 0) {
						if (this.endPos > 0) {
							this.animateTo(0, 800, "easeOutCubic")
						} else {
							this.animateTo((this.carouselWidth / 10) * ((g + 200) / 1000), (Math.abs(this.endPos) * 1.1) / v0, "easeOutSine", true, 0, 400, "easeOutCubic")
						}
					} else if (this.endPos + S < this.carouselWidth - this._gt2) {
						if (this.endPos < this.carouselWidth - this._gt2) {
							this.animateTo(this.carouselWidth - this._gt2, 800, "easeOutCubic")
						} else {
							this.animateTo(this.carouselWidth - this._gt2 - (this.carouselWidth / 10) * ((g + 200) / 1000), (Math.abs(this.carouselWidth - this._gt2 - this.endPos) * 1.1) / v0, "easeOutSine", true, this.carouselWidth - this._gt2, 400, "easeOutCubic")
						}
					} else {
						this.animateTo(this.endPos + S, t, "easeOutCubic")
					}
				} else {
					if (this.autoplay && this.settings.autoplayStopAtAction) {
						this.stopAutoplay()
					}
					var h = Boolean(this._dw1 - this._ev1 > 0);
					var i = getCorrectXPos(this._by4());
					var j = this._cx4(i).index;
					if (!this._ir2) {
						j = j + (h ? this._hs2 : (-this._hs2 + 1))
					} else {
						if (h) {
							i = Math.max(i - this.carouselWidth - 1, 1 - b._gt2);
							j = this._cx4(i).index;
							if (j === undefined) {
								j = this.numItems - 1
							}
						}
						var k = this._gt4(j);
						j = k * this._hs2
					}
					if (h) {
						j = Math.min(j, this.numItems - 1)
					} else {
						j = Math.max(j, 0)
					}
					var l = this.items[j];
					this._az4(j);
					if (l) {
						i = getCorrectXPos(-l.posX);
						var m = Math.abs(this.endPos - i);
						var n = Math.max((m * 1.08) / v0, 150);
						var o = Boolean(n < 180);
						var p = m * 0.08;
						if (h) {
							p = p * -1
						}
						this.animateTo(o ? (i + p) : i, Math.min(n, 400), "easeOutSine", o, i, 300, "easeOutCubic")
					}
				}
				if (this.settings.onDragRelease !== null) {
					this.settings.onDragRelease.call(this)
				}
			}
			return false
		},
		_by3: function (a) {
			if (a === undefined) {
				a = this._by4()
			}
			if (!this.settings.loopItems) {
				if (a >= 0) {
					this._az3()
				} else if (a <= this.carouselWidth - this._gt2) {
					this._ir4()
				} else {
					this._hs4()
				}
			}
		},
		_mn1: function () {
			if (this._kp1) {
				this._az1.css('cursor', this._kp1)
			} else {
				this._az1.removeClass('grabbing-cursor');
				this._az1.addClass('grab-cursor')
			}
		},
		_kp4: function () {
			if (this._lo1) {
				this._az1.css('cursor', this._lo1)
			} else {
				this._az1.removeClass('grab-cursor');
				this._az1.addClass('grabbing-cursor')
			}
		}
	};
	$.fn.touchCarousel = function (b) {
		return this.each(function () {
			var a = new TouchCarousel($(this), b);
			$(this).data("touchCarousel", a)
		})
	};
	$.fn.touchCarousel.defaults = {
		itemsPerMove: 1,
		snapToItems: false,
		pagingNav: false,
		pagingNavControls: true,
		autoplay: false,
		autoplayDelay: 3000,
		autoplayStopAtAction: true,
		scrollbar: true,
		scrollbarAutoHide: false,
		scrollbarTheme: "dark",
		transitionSpeed: 600,
		directionNav: true,
		directionNavAutoHide: false,
		loopItems: false,
		keyboardNav: false,
		dragUsingMouse: true,
		scrollToLast: false,
		itemFallbackWidth: 500,
		baseMouseFriction: 0.0012,
		baseTouchFriction: 0.0008,
		lockAxis: true,
		useWebkit3d: false,
		onAnimStart: null,
		onAnimComplete: null,
		onDragStart: null,
		onDragRelease: null
	};
	$.fn.touchCarousel.settings = {};
	$.extend(jQuery.easing, {
		easeInOutSine: function (x, t, b, c, d) {
			return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b
		},
		easeOutSine: function (x, t, b, c, d) {
			return c * Math.sin(t / d * (Math.PI / 2)) + b
		},
		easeOutCubic: function (x, t, b, c, d) {
			return c * ((t = t / d - 1) * t * t + 1) + b
		}
	})
})(jQuery);
