(function(b){var a={};b.fn.rolling=function(f,h,d,e){var c="dev_rolling_000";var i=this.attr("id");a[c]={id:i,rollingIsStarted:false,rollingItemCount:0,rollingAnimationIndex:0,rollingItemWidth:0,rollingItemHeight:0,viewingItemCount:0,rollingTime:0,viewingTime:0,rollingAnimationFrame:0,rollingDirection:null,rollingLeft:0,rollingTop:0,requestReverse:false,newRollingAnimationFrame:0};var g=a[c];g.rollingDirection=f;g.rollingItemWidth=h;g.rollingItemHeight=d;if(e==undefined){g.viewingItemCount=1}else{g.viewingItemCount=e}if(g.rollingDirection=="left"||g.rollingDirection=="right"){this.css("width",g.rollingItemWidth*g.viewingItemCount);this.css("height",g.rollingItemHeight)}else{if(g.rollingDirection=="up"||g.rollingDirection=="down"){this.css("width",g.rollingItemWidth);this.css("height",g.rollingItemHeight*g.viewingItemCount)}}this.css("position","relative");this.css("overflow","hidden");this.attr("rollingId",c);this.empty();rollingContentDiv=b("<div/>").appendTo(this);rollingContentDiv.attr("id",c);rollingContentDiv.css("position","absolute");rollingContentDiv.attr("align","left");rollingContentDiv.css("left","0");rollingContentDiv.css("top","0");return this};b.fn.addRollingItem=function(d){var f=a[this.attr("rollingId")];var e=b("#"+this.attr("rollingId"));f.rollingItemCount++;var c=null;if(f.rollingDirection=="up"){c=b("<div class='item'/>").appendTo(e)}else{if(f.rollingDirection=="right"){c=b("<div class='item'/>").prependTo(e);c.css("display","inline");e.css("width",f.rollingItemCount*f.rollingItemWidth);e.css("left",-(f.rollingItemCount-f.viewingItemCount)*f.rollingItemWidth);f.rollingLeft=-(f.rollingItemCount-f.viewingItemCount)*f.rollingItemWidth}else{if(f.rollingDirection=="down"){c=b("<div class='item'/>").prependTo(e);f.rollingTop=-(f.rollingItemCount-f.viewingItemCount)*f.rollingItemHeight;e.css("top",-(f.rollingItemCount-f.viewingItemCount)*f.rollingItemHeight)}else{if(f.rollingDirection=="left"){c=b("<div class='item'/>").appendTo(e);c.css("display","inline");e.css("width",f.rollingItemCount*f.rollingItemWidth)}}}}c.css("overflow","hidden");c.css("width",f.rollingItemWidth);c.css("height",f.rollingItemHeight);c.html(d);return this};rollingAnimation=function(d){var e=a[d];var i=b("#"+d);if(i.size()==0){return}var h=e.rollingTime;if(e.rollingIsStarted==false){setTimeout("rollingAnimation('"+d+"')",h);return}if(e.rollingAnimationIndex==0){if(e.newRollingAnimationFrame!=e.rollingAnimationFrame){e.rollingAnimationFrame=e.newRollingAnimationFrame}}var c=false;if(e.requestReverse==true){c=true;e.requestReverse=false;e.rollingAnimationIndex=e.rollingAnimationFrame-e.rollingAnimationIndex;if(e.rollingDirection=="left"){e.rollingDirection="right"}else{if(e.rollingDirection=="right"){e.rollingDirection="left"}else{if(e.rollingDirection=="down"){e.rollingDirection="up"}else{if(e.rollingDirection=="up"){e.rollingDirection="down"}}}}b("#"+e.id).trigger("reverse")}else{if(e.rollingDirection=="up"){e.rollingTop-=e.rollingItemHeight/e.rollingAnimationFrame;if(-e.rollingTop>parseFloat(e.rollingItemHeight)*e.rollingItemCount){e.rollingTop=-parseFloat(e.rollingItemHeight)*e.rollingItemCount}i.css("top",e.rollingTop)}else{if(e.rollingDirection=="right"){e.rollingLeft+=e.rollingItemWidth/e.rollingAnimationFrame;if(e.rollingLeft>parseFloat(e.rollingItemWidth)){e.rollingLeft=parseFloat(e.rollingItemWidth)}i.css("left",e.rollingLeft)}else{if(e.rollingDirection=="down"){e.rollingTop+=e.rollingItemHeight/e.rollingAnimationFrame;if(e.rollingTop>parseFloat(e.rollingItemHeight)){e.rollingTop=parseFloat(e.rollingItemHeight)}i.css("top",e.rollingTop)}else{if(e.rollingDirection=="left"){e.rollingLeft-=e.rollingItemWidth/e.rollingAnimationFrame;if(-e.rollingLeft>parseFloat(e.rollingItemWidth)*e.rollingItemCount){e.rollingLeft=-parseFloat(e.rollingItemWidth)*e.rollingItemCount}i.css("left",e.rollingLeft)}}}}e.rollingAnimationIndex++}if(e.rollingAnimationIndex!=0&&e.rollingAnimationIndex%e.rollingAnimationFrame==0){var j=0;if(e.rollingDirection=="up"||e.rollingDirection=="left"){j=0}else{if(e.rollingDirection=="right"||e.rollingDirection=="down"){j=e.rollingItemCount-1}}var g=b("div[class='item']:eq("+j+")",i);var f=null;if(e.rollingDirection=="up"){f=g.clone(true).appendTo(i);e.rollingTop+=parseFloat(e.rollingItemHeight);e.rollingTop=e.rollingItemHeight*Math.round(e.rollingTop/e.rollingItemHeight);i.css("top",e.rollingTop)}else{if(e.rollingDirection=="right"){f=g.clone(true).prependTo(i);e.rollingLeft-=parseFloat(e.rollingItemWidth);e.rollingLeft=e.rollingItemWidth*Math.round(e.rollingLeft/e.rollingItemWidth);b("#debug").html("rollingLeft:"+e.rollingLeft);f.css("display","inline");i.css("left",e.rollingLeft)}else{if(e.rollingDirection=="down"){f=g.clone(true).prependTo(i);e.rollingTop-=parseFloat(e.rollingItemHeight);e.rollingTop=e.rollingItemHeight*Math.round(e.rollingTop/e.rollingItemHeight);i.css("top",e.rollingTop)}else{if(e.rollingDirection=="left"){f=g.clone(true).appendTo(i);e.rollingLeft+=parseFloat(e.rollingItemWidth);e.rollingLeft=e.rollingItemWidth*Math.round(e.rollingLeft/e.rollingItemWidth);b("#debug").html("rollingLeft:"+e.rollingLeft);f.css("display","inline");i.css("left",e.rollingLeft)}}}}g.remove();if(!c){h=e.viewingTime}else{h=0}var k=b("div[class='item']:eq("+j+")",i);b("#"+e.id).trigger("viewing",[k]);e.rollingAnimationIndex=0}if(e.rollingAnimationIndex!=0){var g=b("div[class='item']:eq(0)",i);b("#"+e.id).trigger("rolling",[g])}setTimeout("rollingAnimation('"+d+"')",h)};b.fn.startRolling=function(f,c,e){var h=a[this.attr("rollingId")];var g=b("#"+this.attr("rollingId"));var i=0;if(h.rollingDirection=="up"||h.rollingDirection=="left"){i=0}else{if(h.rollingDirection=="right"||h.rollingDirection=="down"){i=h.rollingItemCount-1}}var d=b("div[class='item']:eq("+i+")",g);this.trigger("viewing",[d]);h.rollingTime=f;h.viewingTime=c;h.rollingAnimationFrame=e;h.newRollingAnimationFrame=e;h.rollingIsStarted=true;this.trigger("start");setTimeout("rollingAnimation('"+this.attr("rollingId")+"')",h.viewingTime);return this};b.fn.stopRolling=function(){this.trigger("stop");a[this.attr("rollingId")].rollingIsStarted=false;return this};b.fn.resumeRolling=function(){if(a[this.attr("rollingId")].rollingIsStarted!=true){a[this.attr("rollingId")].rollingIsStarted=true;this.trigger("start")}return this};b.fn.getRollingTime=function(){return a[this.attr("rollingId")].rollingTime};b.fn.getViewingTime=function(){return a[this.attr("rollingId")].viewingTime};b.fn.getRollingAnimationFrame=function(){return a[this.attr("rollingId")].rollingAnimationFrame};b.fn.getRollingDirection=function(){return a[this.attr("rollingId")].rollingDirection};b.fn.setRollingTime=function(c){a[this.attr("rollingId")].rollingTime=c;return this};b.fn.setViewingTime=function(c){a[this.attr("rollingId")].viewingTime=c;return this};b.fn.setRollingAnimationFrame=function(c){var d=a[this.attr("rollingId")].rollingAnimationFrame;var f=a[this.attr("rollingId")].rollingAnimationIndex;var e=c/d;a[this.attr("rollingId")].rollingAnimationFrame=c;a[this.attr("rollingId")].newRollingAnimationFrame=c;a[this.attr("rollingId")].rollingAnimationIndex=Math.round(e*f);return this};b.fn.setRollingAnimationFrameNext=function(c){a[this.attr("rollingId")].newRollingAnimationFrame=c;return this};b.fn.getRollingItems=function(){return b("div[class=item]",this)};b.fn.bindViewingEvent=function(c){return this.bind("viewing",c)};b.fn.unbindViewingEvent=function(){return this.unbind("viewing")};b.fn.bindRollingEvent=function(c){return this.bind("rolling",c)};b.fn.unbindRollingEvent=function(){return this.unbind("rolling")};b.fn.bindStartEvent=function(c){return this.bind("start",c)};b.fn.unbindStartEvent=function(){return this.unbind("start")};b.fn.bindStopEvent=function(c){return this.bind("stop",c)};b.fn.unbindStopEvent=function(){return this.unbind("stop")};b.fn.bindReverseEvent=function(c){return this.bind("reverse",c)};b.fn.unbindReverseEvent=function(){return this.unbind("reverse")};b.fn.reverseRolling=function(){a[this.attr("rollingId")].requestReverse=true;return this}})(jQuery);
