// @author Dan Gidman (danatcofo at gmail dot com) http://www.gnu.org/licenses/gpl.html V 2.3 prereq http://plugins.jquery.com/project/timers
(function (m) { var h = "$autoscroll", e = "$tAutoscroll", p = { up: 90, left: 180, right: 0, upleft: 135, upright: 45, downleft: 225, downright: 315, leftup: 135, rightup: 45, leftdown: 225, rightdown: 315, down: 270 }, n = { init: function (d) { return this.each(function () { if (o(this)) { m(this).data(h, g(m.extend(o(this), d))) } else { m(this).data(h, g(m.extend({ e: false, fr: false }, m.fn.autoscroll.defaults.settings, d))); m(this).hover(function () { if (c = o(this)) { if (c.scroll) { m(this).stop(true) } c.e = true } }, function () { if ((c = o(this)) && c.e) { c.e = false } }); m(this).everyTime(50, h, function () { if ((c = o(this)) && c.scroll && !c.e && !c.fr) { if ((l = m(this).data(e)) && !q(l, c)) { m(this).stop(true).animate(i(c.step, c.direction, this), 1000, "linear") } else { m(this).animate(i(c.step, c.direction), 1000, "linear") } } m(this).data(e, m.extend(true, {}, c)) }) } }) }, destroy: function () { return this.each(function () { if (o(this)) { m(this).stop(true); m.timer.remove(this, h); m(this).data(h, null); m(this).data(e, null) } }) }, delay: function (d) { return this.each(function () { if ((c = o(this)) && c.scroll) { m(this).autoscroll("pause"); m(this).oneTime(d || m.fn.autoscroll.defaults.delay, h, function () { m(this).autoscroll("resume") }) } }) }, fastforward: function (d) { return a(this, "f", d) }, rewind: function (d) { return a(this, "r", d) }, pause: function () { return this.each(function () { if ((c = o(this)) && c.scroll) { c.scroll = false; m(this).stop(true) } }) }, resume: function () { return this.each(function () { if (c = o(this)) { c.scroll = true } }) }, reverse: function () { return this.each(function () { if ((c = o(this)) && (c.direction += 180) > 360) { c.direction -= 360 } }) }, toggle: function () { return this.each(function () { if (c = o(this)) { if (c.scroll) { c.scroll = false; m(this).stop(true) } else { c.scroll = true } } }) }, get: function () { return this.each(function () { if (o(this)) { return o(this) } }) }, addpausesource: function (k) { if (typeof k == "undefined") { return this } if (!(k instanceof jQuery)) { if (typeof k == "string" || k instanceof HTMLElement) { k = m(k) } else { return this } } var d = this.selector; k.each(function () { m(this).hover(function () { m(d).each(function () { if (c = o(this)) { if (c.scroll) { m(this).stop(true) } c.e = true } }) }, function () { m(d).each(function () { if ((c = o(this)) && c.e) { c.e = false } }) }) }); return this } }, o = function (d) { return m(d).data(h) }, q = function (k, d) { return k.step === d.step && k.direction === d.direction && k.scroll === d.scroll }, a = function (d, t, k) { f = g(m.extend(m.fn.autoscroll.defaults.ffrw, k)); return d.each(function () { if (c = o(this)) { var s = c.scroll, r = c.direction; c.fr = true; if (t == "r" && (r += 180) > 360) { r -= 360 } m(this).stop(true).animate(i(f.step, r), f.speed, "swing", function () { o(this).fr = false }) } }) }, g = function (d) { if (m.inArray(typeof d.scroll, ["undefined", "boolean"]) < 0) { m.error("scroll is not a boolean") } if (m.inArray(typeof d.step, ["undefined", "number"]) < 0 && isNaN(d.step = Number(d.step))) { m.error("step is not a valid number") } if (d.direction) { d.direction = b(d.direction) } return d }, j = function (d) { return d * Math.PI / 180 }, b = function (d) { if (typeof d === "string" && isNaN(Number(d))) { if (p[d]) { d = p[d] } else { if (d.indexOf("rad") == d.length - 3 && !isNaN(d = Number(d.substring(0, d.length - 3)))) { d = d * 180 / Math.PI } } } if (isNaN(d = Number(d))) { m.error("Invalid direction on jQuery.autoscroll") } while (d < 0) { d += 360 } return d }, i = function (r, k) { var d = Math.round(r * Math.cos(k = j(k))), u = Math.round(r * Math.sin(k)), t = arguments[2]; if (t instanceof HTMLElement) { return { scrollTop: t.scrollTop + u * -1, scrollLeft: t.scrollLeft + d} } return { scrollTop: ((u < 0) ? "+=" : "-=") + Math.abs(u), scrollLeft: ((d < 0) ? "-=" : "+=") + Math.abs(d)} }; m.fn.autoscroll = function (k, d) { if (n[k]) { return n[k].apply(this, Array.prototype.slice.call(arguments, 1)) } else { if (typeof k === "object" || !k) { return n.init.apply(this, arguments) } else { m.error("Method " + k + " does not exist on jQuery.autoscroll") } } }; m.fn.autoscroll.defaults = { settings: { step: 50, scroll: true, direction: "down" }, delay: 5000, ffrw: { speed: "fast", step: 100}} })(jQuery);
