$(function(){

	$('marquee').marquee('pointer').mouseover(function () {
	  $(this).trigger('stop');
   }).mouseout(function () {
	  $(this).trigger('start');
   }).mousemove(function (event) {
	  if ($(this).data('drag') == true) {
		 this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
	  }
   }).mousedown(function (event) {
	  $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
   }).mouseup(function () {
	  $(this).data('drag', false);
   });
	
});
//marquee plugin
(function(l) {
    l.fn.marquee = function(m) {
        var g = [],
        o = this.length;
        function h(f, b, c) {
            var a = c.behavior,
            d = c.width,
            e = c.dir;
            var i = 0;
            if (a == 'alternate') {
                i = f == 1 ? b[c.widthAxis] - (d * 2) : d
            } else if (a == 'slide') {
                if (f == -1) {
                    i = e == -1 ? b[c.widthAxis] : d
                } else {
                    i = e == -1 ? b[c.widthAxis] - (d * 2) : 0
                }
            } else {
                i = f == -1 ? b[c.widthAxis] : 0
            }
            return i
        }
        function n() {
            var f = g.length,
            b = null,
            c = null,
            a = {},
            d = [],
            e = false;
            while (f--) {
                b = g[f];
                c = l(b);
                a = c.data('marqueeState');
                if (c.data('paused') !== true) {
                    b[a.axis] += (a.scrollamount * a.dir);
                    e = a.dir == -1 ? b[a.axis] <= h(a.dir * -1, b, a) : b[a.axis] >= h(a.dir * -1, b, a);
                    if ((a.behavior == 'scroll' && a.last == b[a.axis]) || (a.behavior == 'alternate' && e && a.last != -1) || (a.behavior == 'slide' && e && a.last != -1)) {
                        if (a.behavior == 'alternate') {
                            a.dir *= -1
                        }
                        a.last = -1;
                        c.trigger('stop');
                        a.loops--;
                        if (a.loops === 0) {
                            if (a.behavior != 'slide') {
                                b[a.axis] = h(a.dir, b, a)
                            } else {
                                b[a.axis] = h(a.dir * -1, b, a)
                            }
                            c.trigger('end')
                        } else {
                            d.push(b);
                            c.trigger('start');
                            b[a.axis] = h(a.dir, b, a)
                        }
                    } else {
                        d.push(b)
                    }
                    a.last = b[a.axis];
                    c.data('marqueeState', a)
                } else {
                    d.push(b)
                }
            }
            g = d;
            if (g.length) {
                setTimeout(n, 25)
            }
        }
        this.each(function(f) {
            var b = l(this),
            c = b.attr('width') || b.width(),
            a = b.attr('height') || b.height(),
            d = b.after('<div ' + (m ? 'class="' + m + '" ': '') + 'style="display: block-inline; height: ' + a + 'px; overflow: hidden;"><div style="text-align:center;">' + b.html() + '</div></div>').next(),
            e = d.get(0),
            i = 0,
            k = (b.attr('direction') || 'left').toLowerCase(),
            j = {
                dir: /down|right/.test(k) ? -1 : 1,
                axis: /left|right/.test(k) ? 'scrollLeft': 'scrollTop',
                widthAxis: /left|right/.test(k) ? 'scrollWidth': 'scrollHeight',
                last: -1,
                loops: b.attr('loop') || -1,
                scrollamount: b.attr('scrollamount') || this.scrollAmount || 2,
                behavior: (b.attr('behavior') || 'scroll').toLowerCase(),
                width: /left|right/.test(k) ? c: a
            };
            if (b.attr('loop') == -1 && j.behavior == 'slide') {
                j.loops = 1
            }
            b.remove();
            if (/left|right/.test(k)) {
                d.find('> div').css('padding', '0 ' + c + 'px')
            } else {
                d.find('> div').css('padding', a + 'px 0')
            }
            d.bind('stop',
            function() {
                d.data('paused', true)
            }).bind('pause',
            function() {
                d.data('paused', true)
            }).bind('start',
            function() {
                d.data('paused', false)
            }).bind('unpause',
            function() {
                d.data('paused', false)
            }).data('marqueeState', j);
            g.push(e);
            e[j.axis] = h(j.dir, e, j);
            d.trigger('start');
            if (f + 1 == o) {
                n()
            }
        });
        return l(g)
    }
} (jQuery));