var g_Keys=null;var keys=new Array;var direction=null;var g_ID=0;var g_dataLoader=null;var g_drawList=null;var debugBuffer=null;var debugBufferContext2D=null;smooth=0.2;function theGame(){this.gtX=0;this.gtY=0;this.xScroll=0;this.yScroll=0;this.scrollX=1;this.scrollY=10;this.canvas=null;this.context2D=null;this.backBuffer=null;this.backBufferContext2D=null;this.fields=Array();this.buildings=Array();this.Date=new Date}
theGame.prototype.drawCircle=function drawCircle(){this.context2D.beginPath();this.context2D.arc(150,150,20,0,2*Math.PI,false);this.context2D.fillStyle="green";this.context2D.fill();this.context2D.lineWidth=1;this.context2D.strokeStyle="#003300";this.context2D.stroke()};
theGame.prototype.setIslands=function setIslands(i){if(i==1){this.areas[0].x=0;this.areas[0].y=0}if(i==2)this.areas[1].y=0;if(i>this.islands){for(var ii=this.islands-1;ii<i;ii++)this.areas[ii].setSize(0);this.islands=i;this.setSize(this.size)}if(i<this.islands){this.islands=i;this.setSize(this.size,false)}};theGame.prototype.setRand=function setRand(r){this.rand=r;this.setSize(this.size)};
theGame.prototype.setSize=function setSize(s,fast){var p=0;var added=0;this.size=s;var rbox=this.size*(this.rand/100);var total=this.size-rbox;var piece=rbox/triSize(this.islands);if(fast)for(var i=0;i<this.islands;i++){var ss=total/this.islands+piece*(i+1);p=p+ss;this.areas[i].setSize(ss)}else for(var i=0;i<this.islands;i++){var ss=total/this.islands+piece*(i+1);p=p+ss;this.areas[i].setSize(ss)}};theGame.prototype.setSB=function setSB(s){for(var i in this.areas)this.areas[i].setSB(s)};
theGame.prototype.drawArea=function drawCircle(area){var context2D=this.backBufferContext2D;context2D.beginPath();var scale=this.canvas.width/800*0.1;if(!area.dr)area.dr=area.r;if(!area.dr_s)area.dr_s=area.r_s;if(area.dr_s>area.r_s)area.dr_s-=Math.ceil(Math.abs(area.r_s-area.dr_s)*0.1);if(area.dr_s<area.r_s)area.dr_s+=Math.ceil(Math.abs(area.r_s-area.dr_s)*0.1);if(area.dr>area.r)area.dr-=Math.ceil(Math.abs(area.r-area.dr)*0.1);if(area.dr<area.r)area.dr+=Math.ceil(Math.abs(area.r-area.dr)*0.1);if(Math.abs(area.r-
area.dr))context2D.globalAlpha=area.r*10/Math.abs(area.r-area.dr);else context2D.globalAlpha=1;context2D.arc(area.x*scale+this.canvas.width/2,area.y*scale+this.canvas.height/2,area.dr*scale,0,2*Math.PI,false);context2D.fillStyle="#00bd97";context2D.fill();context2D.lineWidth=2;context2D.strokeStyle="rgba(0,0,0,.2)";context2D.stroke();context2D.beginPath();context2D.arc(area.x*scale+this.canvas.width/2,area.y*scale+this.canvas.height/2,area.dr_s*scale,0,2*Math.PI,false);context2D.fillStyle="#00725b";
context2D.fill();context2D.lineWidth=2;context2D.strokeStyle="rgba(0,0,0,.2)";context2D.stroke();context2D.globalAlpha=1};
function ccollision(c1,c2,scale){if(c1===c2)return false;var dx=c1.x-c2.x;var dy=c1.y-c2.y;var dist=c1.r*1.1+c2.r*1.1;if(dx*dx+dy*dy<=dist*dist){var d=Math.ceil((Math.sqrt(dist*dist)-Math.sqrt(dx*dx+dy*dy))/2);if(c1.x<c2.x){c1.x=c1.x-d;c2.x=c2.x+d}if(c1.x>c2.x){c1.x=c1.x+d;c2.x=c2.x-d}if(c1.x==c2.x)if(Math.random()>=0.5){c1.x=c1.x+d;c2.x=c2.x-d}else{c1.x=c1.x-d;c2.x=c2.x+d}if(c1.y<c2.y){c1.y=c1.y-d;c2.y=c2.y+d}if(c1.y>c2.y){c1.y=c1.y+d;c2.y=c2.y-d}if(c1.y==c2.y)if(Math.random()>=0.5){c1.y=c1.y+d;
c2.y=c2.y-d}else{c1.y=c1.y-d;c1.y=c1.y+d}return true}return false}
theGame.prototype.drawAreas=function drawAreas(){var scale=this.canvas.width/800*0.1;for(var i=0;i<this.islands;i++)for(var ii=0;ii<this.islands;ii++)ccollision(this.areas[i],this.areas[ii],scale);for(var i=0;i<this.islands;i++){if((this.areas[i].x-this.areas[i].r)*scale<0-this.canvas.width/2)this.areas[i].x=0;if((this.areas[i].x+this.areas[i].r)*scale>this.canvas.width/2)this.areas[i].x=0;if((this.areas[i].y-this.areas[i].r)*scale<0-this.canvas.height/2)this.areas[i].y=0;if((this.areas[i].y+this.areas[i].r)*
scale>this.canvas.height/2)this.areas[i].y=0}for(var i in this.areas)this.areas[i].tick();for(var i=0;i<this.islands;i++)this.drawArea(this.areas[i])};var gTime=(new Date).getTime();var theGameObj=null;var g_tof=0;var g_dataLoader=null;var g_preloaderTO=20;function loading(){g_preloaderTO--;if(g_dataLoader.isLoading()&&g_preloaderTO>0)setTimeout(function(){loading()},100);else{document.getElementById("p01").style.opacity=1;document.getElementById("loading").style.display="none"}}window.onload=init;
function init(){g_dataLoader=(new DataLoader).start();theGameObj=(new theGame).start();setTimeout(function(){loading()},10)};
