var RB={}; RB.Scene=function(b,k){if(!b)throw"RB.Scene(canvasObject): You must specify a canvas object";k||(k=24);this.timeInterval=k;var n=document;this.ctx=b.getContext("2d");var d=[],m=null,u=!1,z=!1,s=!1,p=!1,v=!1,t=null,A=0,l=0,q=[],r=[],w=!1,x=0,a=0,y=0;this.genID=function(){return"RB_OBJECT"+y++};this.add=function(c){if(!c)throw"RB.Scene.add(o): the object you are trying to add to the scene doesn't exist.";d.push(c);c.collidable&&q.push(c);c.draggable&&r.push(c);return c};this.addLots=function(c){for(var i=0;i< c.length;i++)this.add(c[i])};this.remove=function(c){for(var c=c.getId(),i=d.length,a=r.length,h=q.length,e=0;e=a&&(e=a-1);a=d[h];d[h]=d[e];d[e]=a};getObjectById=function(c){for(var a=d.length,f=0;f=0;a--){var f=r[a];if(f.checkRange(RB.xPos(c),RB.yPos(c))){f.onmousedown(c);t=f;currentObjectIndex=a;A=RB.xPos(c)-t.x;l=RB.yPos(c)-t.y;v=!0;break}}j.onmousedown(c)};b.onmouseup=function(c){v=!1;j.onmouseup(c)};n.onkeydown= function(c){B(c,!0);j.onkeydown(c)};n.onkeyup=function(c){B(c,!1);j.onkeyup(c)};this.getObjectSize=function(){return d.length};this.getObj=function(c){return d[c]};this.rect=function(c,a,f,h,e){var h=h||this.genID(),h=RB.createCanvas(c,a,h),g=h.getContext("2d");if(f)g.fillStyle=RB.getFS(f,g,a),g.fillRect(0,0,c,a);if(e)f=e.lineWidth||1,g.lineWidth=e.lineWidth,g.strokeStyle=e.strokeStyle,g.rect(0+f,0+f,c-f-f,a-f-f),g.stroke();return rectObj=new RB.Obj(h,this.ctx)};this.image=function(c,i,f){var h=new Image, e=this,g=null;h.onload=function(){f=f||e.genID();g=RB.createCanvas(h.width,h.height,f);g.getContext("2d").drawImage(this,0,0);a++;var c=new RB.Obj(g,e.ctx);i(c)};h.src=c;x++};this.loadImage=function(c,i,f){var h=new Image,e=this,g=null;h.onload=function(){i=i||e.genID();g=RB.createCanvas(h.width,h.height,i);g.getContext("2d").drawImage(this,0,0);a++;f(g)};h.src=c;x++};this.imagePattern=function(c,i,f,h,e){var g=new Image,b=this;g.onload=function(){e=e||b.genID();var c=RB.createCanvas(i,f,e).getContext("2d"), d=c.createPattern(g,h);c.fillStyle=d;c.fillRect(0,0,i,f);a++;a==x&&b.doAfterLoad()};g.src=c;x++};this.roundRect=function(c,a,f,h,e,g){var e=e||this.genID(),e=RB.createCanvas(c,a,e),b=e.getContext("2d");b.beginPath();b.moveTo(0+f,0);b.lineTo(c+0-f,0);b.quadraticCurveTo(c+0,0,c+0,0+f);b.lineTo(c+0,a+0-f);b.quadraticCurveTo(c+0,0+a,c+0-f,0+a);b.lineTo(0+f,0+a);b.quadraticCurveTo(0,0+a,0,0+a-f);b.lineTo(0,0+f);b.quadraticCurveTo(0,0,0+f,0);b.closePath();if(h)b.fillStyle=RB.getFS(h,b,a),b.fill();if(g)b.lineWidth= g.lineWidth,b.strokeStyle=g.strokeStyle,b.stroke();return new RB.Obj(e,this.ctx)};this.text=function(a,b,f,h,e){var g=RB.getTextBuffer(),e=e||this.genID();g.innerHTML=a;g.style.fontFamily=b;g.style.fontSize=f+"px";var d=RB.el(e);d?(e=d.getContext("2d"),d.width=g.offsetWidth,d.height=g.offsetHeight+15,e.clearRect(0,0,g.offsetWidth,g.offsetHeight+15)):(d=RB.createCanvas(g.offsetWidth,g.offsetHeight+15,e),e=d.getContext("2d"));e.fillStyle=RB.getFS(h,e,g.offsetHeight+25);e.font="normal "+f+"px "+b;e.fillText(a, 0,g.offsetHeight+5);return new RB.Obj(d,this.ctx)};this.start=function(){w=!0;this.animate()};this.stop=function(){w=!1};this.toggleStart=function(){w?this.stop():this.start()};this.onLoop=function(){};this.runOnce=function(){this.ctx.restore();for(var a=d.length,b=q.length,f=0;fb;d=l.xd;return a&&d},r=function(a,b,d,j){b=l.yb;a=l.getX2()>a&&l.getX2()j;a=l.xa;return b&&a},x=function(a,b,d,j){b=l.getY2()>b&&l.getY2()a;return b&&a};this.checkRange=function(a,b){var d=a>=this.x&&a<=this.getX2(),j=b>=this.y&&b<=this.getY2();return d&&j}};RB.createTextBuffer=function(){var b=document,k=b.createElement("div");k.id="txtBuffer";k.style.position="absolute";k.style.width="auto";k.style.height="auto";k.style.padding="0px";k.style.visibility="hidden";b.body.appendChild(k)}; RB.getTextBuffer=function(){RB.el("txtBuffer")||RB.createTextBuffer();return RB.el("txtBuffer")};RB.createCanvasLocation=null;RB.createCanvas=function(b,k,n){var d=document,m=d.createElement("canvas");m.width=b;m.height=k;m.id=n;m.style.display="none";RB.createCanvasLocation?RB.createCanvasLocation.appendChild(m):d.body.appendChild(m);return m};RB.destroyCanvas=function(b){var k=document,b=k.getElementById(b);k.body.removeChild(b)};RB.el=function(b){return document.getElementById(b)}; RB.linearGradient=function(b,k){var n=k.createLinearGradient(0,5,0,b.h);csLen=b.colors.length;for(var d=0;d