/*!
* jquery cxscroll 1.2.1
* http://code.ciaoca.com/
* https://github.com/ciaoca/cxscroll
* e-mail: ciaoca@gmail.com
* released under the mit license
* date: 2014-03-10
*/
!
function(a) {
a.fn.cxscroll = function(b) {
var c, d;
this.length && (b = a.extend({},
a.cxscroll.defaults, b), c = this, d = {
lock: !1,
dom: {}
},
d.init = function() {
if (d.dom.box = c.find(".box"), d.dom.list = d.dom.box.find(".list"), d.dom.items = d.dom.list.find("li"), d.itemsum = d.dom.items.length, !(d.itemsum <= 1)) {
if (d.dom.prevbtn = c.find(".prev"), d.dom.nextbtn = c.find(".next"), d.itemwidth = d.dom.items.outerwidth(), d.itemheight = d.dom.items.outerheight(), "left" == b.direction || "right" == b.direction) {
if (d.itemwidth * d.itemsum <= d.dom.box.outerwidth()) return;
d.prevval = "left",
d.nextval = "right",
d.moveval = d.itemwidth
} else {
if (d.itemheight * d.itemsum <= d.dom.box.outerheight()) return;
d.prevval = "top",
d.nextval = "bottom",
d.moveval = d.itemheight
}
d.dom.list.append(d.dom.list.html()),
b.prevbtn && !d.dom.prevbtn.length && (d.dom.prevbtn = a("", {
"class": "prev"
}).prependto(c)),
b.nextbtn && !d.dom.nextbtn.length && (d.dom.nextbtn = a("", {
"class": "next"
}).prependto(c)),
b.auto && c.hover(function() {
b.auto = !1,
d.lock = !1
},
function() {
b.auto = !0,
d.lock = !1,
d.on()
}),
d.bindevents(),
d.on()
}
},
d.bindevents = function() {
b.nextbtn && d.dom.prevbtn.length && d.dom.nextbtn.bind("click",
function() {
d.lock || d.goto(d.nextval, b.accel)
}),
b.prevbtn && d.dom.prevbtn.length && d.dom.prevbtn.bind("click",
function() {
d.lock || d.goto(d.prevval, b.accel)
})
},
d.on = function() {
b.auto && ("undefined" != typeof d.run && cleartimeout(d.run), d.run = settimeout(function() {
d.goto(b.direction)
},
b.time))
},
d.off = function() {
d.dom.box.stop(!0),
"undefined" != typeof d.run && cleartimeout(d.run)
},
d.goto = function(c, e) {
var f, g, h;
switch (d.off(), b.controllock && (d.lock = !0), h = e || b.speed, c) {
case "left":
case "top":
f = 0,
"left" == c ? (0 == parseint(d.dom.box.scrollleft(), 10) && d.dom.box.scrollleft(d.itemsum * d.moveval), g = d.dom.box.scrollleft() - d.moveval * b.step, g % d.itemwidth > 0 && (g -= g % d.itemwidth - d.itemwidth), f > g && (g = f), d.dom.box.animate({
scrollleft: g
},
h, b.easing,
function() {
parseint(d.dom.box.scrollleft(), 10) <= f && d.dom.box.scrollleft(0)
})) : (0 == parseint(d.dom.box.scrolltop(), 10) && d.dom.box.scrolltop(d.itemsum * d.moveval), g = d.dom.box.scrolltop() - d.moveval * b.step, g % d.itemheight > 0 && (g -= g % d.itemheight - d.itemheight), f > g && (g = f), d.dom.box.animate({
scrolltop: g
},
h, b.easing,
function() {
parseint(d.dom.box.scrolltop(), 10) <= f && d.dom.box.scrolltop(0)
}));
break;
case "right":
case "bottom":
f = d.itemsum * d.moveval,
"right" == c ? (g = d.dom.box.scrollleft() + d.moveval * b.step, g % d.itemwidth > 0 && (g -= g % d.itemwidth), g > f && (g = f), d.dom.box.animate({
scrollleft: g
},
h, b.easing,
function() {
parseint(d.dom.box.scrollleft(), 10) >= f && d.dom.box.scrollleft(0)
})) : (g = d.dom.box.scrolltop() + d.moveval * b.step, g % d.itemheight > 0 && (g -= g % d.itemheight), g > f && (g = f), d.dom.box.animate({
scrolltop: g
},
h, b.easing,
function() {
parseint(d.dom.box.scrolltop(), 10) >= f && d.dom.box.scrolltop(0)
}))
}
d.dom.box.queue(function() {
b.controllock && (d.lock = !1),
d.on(),
a(this).dequeue()
})
},
d.init())
},
a.cxscroll = {
defaults: {
direction: "right",
easing: "swing",
step: 1,
accel: 160,
speed: 800,
time: 4e3,
auto: !0,
prevbtn: !0,
nextbtn: !0,
safelock: !0
}
}
} (jquery);