(function(m){var b="ticker";function h(n,o){return(n>=o)?h(n-o,o):((n<0)?h(n+o,o):n)}function k(p){var q=p.data(b);var o;for(var n=0;n<200;n++){if(!q.content[n]){o=n;break}}q.nextItem=h((q.nextItem||0),o);q.currentItem=q.nextItem;q.elemIndex=[q.currentItem];q.charIndex=0;q.nextItem++}function l(o){var p={elem:o.clone().empty()};var n=o.children();if(n.length){n.each(function(q){p[q]=l(m(this))});return p}else{p.text=o.text();return p}}function e(p,n){var o;if(p[n[0]]){if(p[n[0]].text){return p[n[0]]}else{if(n.length==1){return true}else{o=m.makeArray(n);return e(p[o[0]],o.splice(1,o.length))}}}else{return false}}function d(n){if(n.length>1){n[n.length-1]++;return n}else{return false}}function g(o,n){if(n===false){return false}var p=e(o,n);if(p===false){return g(o,d(n.slice(0,n.length-1)))}else{if(p===true){n[n.length]=0;return g(o,n)}else{return n}}}function c(r,q,n,s){var p,o;var t=r.children().eq(n[0]);if(!n.length){return{readout:r,text:q.text}}else{if(t.length){o=t}else{o=q[n[0]].elem.appendTo(r)}}p=m.makeArray(n).slice(1,n.length);return c(o,q[n[0]],p,s)}function i(n){var o=n.data(b);m("*",n).empty();n.empty();o.start=0;o.sum=0;if(o.cursorIndex){cursorIndex=0}}function a(n){var o=n.data(b);o.start=o.sum}function j(q,n,r){var o,p;if(r.cursorIndex!==false){r.cursorIndex=h(r.cursorIndex+1,r.cursorList.length);r.cursor.html(r.cursorList[r.cursorIndex])}else{r.cursor.html(r.cursorList)}o=r.charIndex-r.start;p=r.text.charAt(o-1);r.cursor.before(p);if(r.charIndex>=r.sum){r.cursor.remove();r.elemIndex=d(r.elemIndex);return f(q,n)}else{return setTimeout(function(){if(r.eventIndex==n){r.charIndex++;j(q,n,r)}n=null},r.rate)}}function f(o,n){var p=o.data(b);if(p.eventIndex==n){p.elemIndex=g(p.content,p.elemIndex);if(p.elemIndex===false){return setTimeout(function(){if(p.running&&(p.eventIndex==n)){k(o);return f(o,n)}n=null},p.delay)}else{if(!p.charIndex){i(o)}else{a(o)}}m.extend(p,c(o,p.content,p.elemIndex));p.sum=p.sum+p.text.length;p.readout.append(p.cursor);return j(o,n,p)}}m.fn[b]=function(n){var p=m.extend({},m.fn.ticker.defaults,n);return this.each(function(){var o=m(this);o.data(b,{rate:p.rate,delay:p.delay,content:l(o),cursor:p.cursor,cursorList:p.cursorList,cursorIndex:(typeof(p.cursorList)=="object")?0:false,nextItem:0,eventIndex:0}).bind("stop",function(r){var q=o.data(b);q.running=false}).bind("play",function(r){var q=o.data(b);q.eventIndex++;q.running=true;q.nextItem=(r.item||q.nextItem);k(o);f(o,q.eventIndex)}).bind("control",function(r){var q=o.data(b);m().extend(q,{nextItem:r.item,rate:r.rate,delay:r.delay})}).children().remove()})};m.fn[b].defaults={rate:50,delay:2000,cursorList:"_",cursor:m('<span class="cursor" />')}})(jQuery);
