var theGameObj=null;theGame.prototype.setImage=function setImage(img){this.imagesCursor=img;if(this.imagesCursor<0)this.imagesCursor=0;if(this.imagesCursor>this.imagesList.length-1)this.imagesCursor=this.imagesList.length-1};
theGame.prototype.setGatunek=function setGatunek(id){for(var i in this.gatunekBTN)this.gatunekBTN[i].className=this.gatunekBTN[i].className.replace(/\bactive\b/,"");this.gatunekBTN[id].className=this.gatunekBTN[id].className+" active";for(var i in G_Sounds)G_Sounds[i].stop();G_Sounds[this.mainList[id].photos[0].snd].loop();G_Sounds[this.mainList[id].photos[0].snd].play();this.gatunek=id;this.resetLoopCounter()};
theGame.prototype.setLasA=function setLasA(id){for(var i in this.lasABTN)this.lasABTN[i].className=this.lasABTN[i].className.replace(/\bactive\b/,"");this.lasABTN[id].className=this.lasABTN[id].className+" active";this.lasA=id;this.resetLoopCounter()};theGame.prototype.setLasB=function setLasB(id){for(var i in this.lasBBTN)this.lasBBTN[i].className=this.lasBBTN[i].className.replace(/\bactive\b/,"");this.lasBBTN[id].className=this.lasBBTN[id].className+" active";this.lasB=id;this.resetLoopCounter()};
theGame.prototype.setKotytarz=function setKotytarz(id){for(var i in this.korytarzBTN)this.korytarzBTN[i].className=this.korytarzBTN[i].className.replace(/\bactive\b/,"");this.korytarzBTN[id].className=this.korytarzBTN[id].className+" active";this.korytarz=id;this.resetLoopCounter()};
theGame.prototype.setStaleA=function setStaleA(stale){this.areaA.setCzestotliwoscKatastrof(stale.czest_kat);this.areaA.setSilaKatastrof(stale.smier_kat*100);this.areaA.setRozrodczosc(stale.rozr);this.areaA.setSmiertelnosc(stale.smier_typ*100);this.areaA.setEmigracja(stale.max_em_los*100);this.sliderPojemnoscA.onChangeFN(this.sliderPojemnoscA.value);this.sliderOsobnikiA.onChangeFN(this.sliderOsobnikiA.value);this.resetLoopCounter()};
theGame.prototype.setStaleB=function setStaleB(stale){this.areaB.setCzestotliwoscKatastrof(stale.czest_kat);this.areaB.setSilaKatastrof(stale.smier_kat*100);this.areaB.setRozrodczosc(stale.rozr);this.areaB.setSmiertelnosc(stale.smier_typ*100);this.areaB.setEmigracja(stale.max_em_los*100);this.sliderPojemnoscB.onChangeFN(this.sliderPojemnoscB.value);this.sliderOsobnikiB.onChangeFN(this.sliderOsobnikiB.value);this.resetLoopCounter()};
theGame.prototype.resetLoopCounter=function resetLoopCounter(){this.dieAVGA=[];this.dieAVGB=[];this.dieAVGC=[];this.loopCounter=1};
theGame.prototype.start=function start(){this.islands=2;this.rand=30;this.dataLoader=g_dataLoader;this.dataLoader.load("img/logo/INTRO_ptak.png","logo");this.load();this.currentPhoto=0;this.resetLoopCounter();this.mainList=SSS;this.infoClicked=false;that=this;this.gatunekBTN=[];this.gatunekBTN[0]=document.getElementById("btn-dzieciol-b");this.gatunekBTN[1]=document.getElementById("btn-dzieciol-d");this.gatunekBTN[2]=document.getElementById("btn-bogatka");this.gatunekBTN[3]=document.getElementById("btn-czarnoglowka");
this.lasABTN=[];this.lasABTN[0]=document.getElementById("btn-li-a");this.lasABTN[1]=document.getElementById("btn-ll-a");this.lasBBTN=[];this.lasBBTN[0]=document.getElementById("btn-li-b");this.lasBBTN[1]=document.getElementById("btn-ll-b");this.korytarzBTN=[];this.korytarzBTN[0]=document.getElementById("btn-k-a");this.korytarzBTN[1]=document.getElementById("btn-k-b");this.korytarzBTN[2]=document.getElementById("btn-k-c");this.korytarzBTN[3]=document.getElementById("btn-k-d");this.korytarzBTN[4]=document.getElementById("btn-k-e");
this.gatunek=0;this.lasA=0;this.lasB=0;this.korytarz=0;attachEvent(this.gatunekBTN[0],"tap",function(){that.setGatunek(0);that.setStaleA(that.mainList[that.gatunek].stale[that.lasA]);that.setStaleB(that.mainList[that.gatunek].stale[that.lasB])});attachEvent(this.gatunekBTN[1],"tap",function(){that.setGatunek(1);that.setStaleA(that.mainList[that.gatunek].stale[that.lasA]);that.setStaleB(that.mainList[that.gatunek].stale[that.lasB])});attachEvent(this.gatunekBTN[2],"tap",function(){that.setGatunek(2);
that.setStaleA(that.mainList[that.gatunek].stale[that.lasA]);that.setStaleB(that.mainList[that.gatunek].stale[that.lasB])});attachEvent(this.gatunekBTN[3],"tap",function(){that.setGatunek(3);that.setStaleA(that.mainList[that.gatunek].stale[that.lasA]);that.setStaleB(that.mainList[that.gatunek].stale[that.lasB])});attachEvent(this.lasABTN[0],"tap",function(){that.setLasA(0);that.setStaleA(that.mainList[that.gatunek].stale[that.lasA]);that.setStaleB(that.mainList[that.gatunek].stale[that.lasB])});attachEvent(this.lasABTN[1],
"tap",function(){that.setLasA(1);that.setStaleA(that.mainList[that.gatunek].stale[that.lasA]);that.setStaleB(that.mainList[that.gatunek].stale[that.lasB])});attachEvent(this.lasBBTN[0],"tap",function(){that.setLasB(0);that.setStaleA(that.mainList[that.gatunek].stale[that.lasA]);that.setStaleB(that.mainList[that.gatunek].stale[that.lasB])});attachEvent(this.lasBBTN[1],"tap",function(){that.setLasB(1);that.setStaleA(that.mainList[that.gatunek].stale[that.lasA]);that.setStaleB(that.mainList[that.gatunek].stale[that.lasB])});
attachEvent(this.korytarzBTN[0],"tap",function(){that.setKotytarz(0);that.areaA.setPrzepustowoscKorytarza(0.005*100);that.areaB.setPrzepustowoscKorytarza(0.005*100)});attachEvent(this.korytarzBTN[1],"tap",function(){that.setKotytarz(1);that.areaA.setPrzepustowoscKorytarza(0.25*100);that.areaB.setPrzepustowoscKorytarza(0.25*100)});attachEvent(this.korytarzBTN[2],"tap",function(){that.setKotytarz(2);that.areaA.setPrzepustowoscKorytarza(0.5*100);that.areaB.setPrzepustowoscKorytarza(0.5*100)});attachEvent(this.korytarzBTN[3],
"tap",function(){that.setKotytarz(3);that.areaA.setPrzepustowoscKorytarza(0.75*100);that.areaB.setPrzepustowoscKorytarza(0.75*100)});attachEvent(this.korytarzBTN[4],"tap",function(){that.setKotytarz(4);that.areaA.setPrzepustowoscKorytarza(1*100);that.areaB.setPrzepustowoscKorytarza(1*100)});attachEvent(document.getElementById("prev"),"tap",function(e){document.location="intro.html"});attachEvent(document.getElementById("next"),"tap",function(e){document.location="ogolny.html"});this.areaA=new area("A");
this.areaB=new area("B");this.sumAB=[];var that=this;this.sliders=[];this.sliderOsobnikiA=new makeSlider("pb05-a",function(v){that.areaA.setOsobniki(v*2);that.resetLoopCounter()});this.sliderOsobnikiB=new makeSlider("pb05-b",function(v){that.areaB.setOsobniki(v*2);that.resetLoopCounter()});this.sliderPojemnoscA=new makeSlider("pb01-a",function(v){that.areaA.powierzchnia=v;var osobniki=v*that.mainList[that.gatunek].stale[that.lasA].zag;that.chartA.setMaxY(Math.floor(osobniki/2));that.chartC.setMaxY(Math.floor((that.areaB.pojemnosc*
1+osobniki*1)/2));that.areaA.setPojemnosc(osobniki);that.sliderOsobnikiA.p_max=Math.floor(osobniki/2);if(that.sliderOsobnikiA.value>that.sliderOsobnikiA.p_max)that.sliderOsobnikiA.value=that.sliderOsobnikiA.p_max;that.sliderOsobnikiA.refreshSlider();that.sliderOsobnikiA.drawSlider();that.sliderOsobnikiA.onChangeFN(that.sliderOsobnikiA.value);that.resetLoopCounter()});this.sliders.push(this.sliderPojemnoscA);this.sliderPojemnoscB=new makeSlider("pb01-b",function(v){that.areaB.powierzchnia=v;var osobniki=
v*that.mainList[that.gatunek].stale[that.lasB].zag;that.chartB.setMaxY(Math.floor(osobniki/2));that.chartC.setMaxY(Math.floor((that.areaA.pojemnosc*1+osobniki*1)/2));that.areaB.setPojemnosc(osobniki);that.sliderOsobnikiB.p_max=Math.floor(osobniki/2);if(that.sliderOsobnikiB.value>that.sliderOsobnikiB.p_max)that.sliderOsobnikiB.value=that.sliderOsobnikiB.p_max;that.sliderOsobnikiB.refreshSlider();that.sliderOsobnikiB.drawSlider();that.sliderOsobnikiB.onChangeFN(that.sliderOsobnikiB.value);that.resetLoopCounter()});
this.sliders.push(this.sliderPojemnoscB);this.sliders.push(this.sliderOsobnikiA);this.sliders.push(this.sliderOsobnikiB);this.chartA=document.getElementById("chart-A");this.chartAContext2D=this.chartA.getContext("2d");this.chartB=document.getElementById("chart-B");this.chartBContext2D=this.chartB.getContext("2d");this.chartC=document.getElementById("chart-C");this.chartCContext2D=this.chartC.getContext("2d");this.canvas=document.getElementById("display");this.context2D=this.canvas.getContext("2d");
this.context2D.font="15pt Calibri";this.context2D.fillStyle="black";this.backBuffer=document.createElement("canvas");this.backBuffer.width=this.canvas.width;this.backBuffer.height=this.canvas.height;this.backBufferContext2D=this.backBuffer.getContext("2d");this.attachEvents();this.areas=[];this.subjects=[];this.chartA=new chart(document.getElementById("chart-A"),"Populacja A","liczba par l\u0119gowych","lata");this.chartB=new chart(document.getElementById("chart-B"),"Populacja B","liczba par l\u0119gowych",
"lata");this.chartC=new chart(document.getElementById("chart-C"),"Metapopulacja A+B","liczba par l\u0119gowych","lata");for(var i in this.sliders)this.sliders[i].onChangeFN(this.sliders[i].value);this.setGatunek(0);this.setLasA(0);this.setLasB(1);this.setKotytarz(4);that.areaA.setPrzepustowoscKorytarza(100);that.areaB.setPrzepustowoscKorytarza(100);this.setStaleA(this.mainList[this.gatunek].stale[this.lasA]);this.setStaleB(this.mainList[this.gatunek].stale[this.lasB]);this.redrawFrame();return this};
