
// ©		copyright  Aad van der Arend,  2002....

Sho=600;Sbr=800;Vho=600;Vbr=800;Vbrmid=Math.round(Vbr/2);Vhomid=Math.round(Vho/2);

KLOK=null;
klokperiode0=1;
klokperiode=klokperiode0;
gereedvoorbewegen=false;
vloindex=0;
presentatienr=0;
volgmuis=true;
Nvlooien=10;
maxNvlooien=50;
cirkelpartfactor=1;
straalfactor=1;
straal0=100*straalfactor;
straalstreef0=straal0;
straalstreef=straalstreef0;
straal=straalstreef;
snelheidsfactor=1;
linksom=true;
xcentrum=300;
ycentrum=300;
xcentrumstreef=xcentrum;
ycentrumstreef=ycentrum;

sinw=new Array();
sinAargnr=0;
sinBargnr=0;
Ncirkelpt0=200;
Ncirkelpt=Ncirkelpt0;
Ncirkelpthalf=Math.round(Ncirkelpt/2);
TweePi=2*Math.PI;
boog=TweePi/Ncirkelpt;
vlo0cirkelpt=0;
cirkelptpervlo=Ncirkelpt/Nvlooien;
sinAsinBnuloffset0=Ncirkelpt/4;
sinAsinBnuloffset=sinAsinBnuloffset0;
sinAsinBnuloffsetfactor0=1;
sinAsinBnuloffsetfactor=sinAsinBnuloffsetfactor0;
toppenfactor0=1;
toppenfactor=toppenfactor0;
vlooien=new Array();
vlonamen=new Array('baloranje09x09','*','* STERREN:','sterblauw12x12','sterblauw16x16','stergeel16x16','stergroen16x16','sterrood16x16','sterwit16x16','steranim32x32','*','*  BALLEN:','balblauwanim24x24','discobal24x24','balfelleklranim24x24','balgoud24x24','baloranje09x09','baloranje12x12','parel24x24','balrood12x12','*','* CD\'s:','cdrom24x24','cdromanim24x24','*','* PUNTEN:','puntwit03x03','puntblauw03x03','puntgeel03x03','puntoranje03x03','*','* OVERIG:','ballonnen32x32','diamant30x30','oogbal24x24','roos67x67','*');
Nvlonamen=vlonamen.length;
shows=new Array(10,	'baloranje09',1.0,1.0,1.0,1.0,1.0,'true',50,'puntwit03x03',1.3,1.0,3.0,1.0,-2.0,'true',9,'sterblauw16x16',1.5,1.0,0.8,1.2,1.0,'true',7,'cdrom24x24',0.5,0.8,1.5,0.8,1.0,'true',19,'sterwit',1.5,0.3,2.0,1.0,2.5,'true',29,'puntblauw',1.2,0.8,2.0,1.0,0.8,'true',29,'stergeel',1.0,1.0,3.0,1.4,1.0,'true',29,'parel24x24',1.6,1.0,2.0,1.0,2.0,'true',5,'diamant30x30',1.0,	1.0,1.0,1.2,1.0,'true',50,'puntwit03x03',1.3,1.0,3.0,1.0,2.0,'true');
Nshows=shows.length/8;

document.onmousemove=bijmuisbeweegopdezepag;

function startvlooienspel(){
	maak_htm_vlooienlijst();
	xcentrum=Vbrmid;
	ycentrum=Vhomid;
	sinwaarden();
	maakstartposities();
	doepresentatie(presentatienr,0);
};

function maak_htm_vlooienlijst(){
	Str='<select id="vlokeuze" size="1" onChange="toonvlooien()">';
	for(i=0;i<Nvlonamen;i++){
		Str+='<option value="">&nbsp;'+vlonamen[i]+'</option>';
		if(vlonamen[i].indexOf('*')<0)vlooien[i]='vlooien/'+vlonamen[i]+'.gif';
	};
	Str+='</select>';
	DID('htm_vlooienlijstdiv').innerHTML=Str;
};

function maakwillekeurigevlo(){
	vloindex=Math.floor(Math.random()*Nvlonamen);
	while(vlonamen[vloindex].indexOf('*')>-1){vloindex=Math.floor(Math.random()*Nvlonamen);};
	DID('instelform').vlokeuze.selectedIndex=vloindex;
};

function willekpresentatie(){
	doepresentatie(Math.round(Math.random()*(Nshows-1)),0);
};

function sinwaarden(){
	boog=TweePi/Ncirkelpt;
	hoek=0;
	for(i=0;i<Ncirkelpt;i++){
		sinw[i]=Math.sin(hoek);hoek+=boog;
	};
};

function maakstartposities(){
	for(i=0;i<maxNvlooien;i++){
		randomx=Math.round(Math.random()*Vbr);
		randomy=Math.round(Math.random()*Vho);
		vloi='vlo'+i;
		STIJL(vloi).left=randomx;
		STIJL(vloi).top =randomy;
	};
};

function wijzigNvlooien(plusmin,nr){
	Nvlooien+=plusmin*nr;
	if(Nvlooien<0)Nvlooien=0;
	if(Nvlooien>maxNvlooien)Nvlooien=maxNvlooien;
	cirkelptpervlo=Ncirkelpt/Nvlooien;
	toonvlooien();
};

function doepresentatie(p,q){
	if(q!=0){presentatienr+=q}else{presentatienr=p};
	if(presentatienr<0)presentatienr=0;
	if(presentatienr>=Nshows)presentatienr=(Nshows-1);
	DID('vakpresnr').value=presentatienr;
	var0=presentatienr*8;
	Nvlooien=shows[var0];
	cirkelptpervlo=Ncirkelpt/Nvlooien;
	vloindex=0;
	for(i=0;i<Nvlonamen;i++){
		if((vlonamen[i].indexOf(shows[var0+1]))>-1){vloindex=i;break};
	};
	DID('vlokeuze').selectedIndex=vloindex;
	straalfactor=shows[var0+2];
	cirkelpartfactor=shows[var0+3];
	snelheidsfactor=shows[var0+4]*0.8;
	sinAsinBnuloffsetfactor=shows[var0+5];
	toppenfactor=shows[var0+6];
	volgmuis=eval(shows[var0+7]);
	//if(IE)snelheidsfactor*=0.4;
	toonvlooien();
};

function toonvlooien(){
	vloindex=DID('vlokeuze').selectedIndex;
	if(vlonamen[vloindex].indexOf('*')>-1)maakwillekeurigevlo();
	if(straal<0)straal=0;
	straalstreef0=straal0*straalfactor;
	straalstreef=straalstreef0;
	straal=straalstreef;
	if(snelheidsfactor<0.1)snelheidsfactor=0.1;
	Ncirkelpt=Math.round(Ncirkelpt0/snelheidsfactor);
	sinwaarden();
	cirkelptpervlo=Ncirkelpt/Nvlooien;
	if(sinAsinBnuloffsetfactor<0)sinAsinBnuloffsetfactor=0;
	if(sinAsinBnuloffsetfactor>2)sinAsinBnuloffsetfactor=2;
	sinAsinBnuloffset=Ncirkelpt/4*sinAsinBnuloffsetfactor;
	if(cirkelpartfactor>1)cirkelpartfactor=1;
	if(cirkelpartfactor<0.1)cirkelpartfactor=0.1;
	vulinstellaagform();
	for(i=0;i<maxNvlooien;i++){
		vloi='vlo'+i;
		STIJL(vloi).visibility='hidden';
	};
	Nvlooiendeelcirkel=Math.round(Nvlooien*cirkelpartfactor);
	DID('instelform').vakNvlooien.value=Nvlooiendeelcirkel;
	for(i=0;i<Nvlooiendeelcirkel;i++){
		vloi='vlo'+i;
		DID(vloi).src=vlooien[vloindex];
		STIJL(vloi).visibility='visible';
	};
	gereedvoorbewegen=true;
	bewegen('ja');
};

function bewegen(x){
	clearInterval(KLOK);
	if(gereedvoorbewegen && x=='ja')KLOK=setInterval('vlooienverplaatsen()',klokperiode);
};

function vulinstellaagform(){
	with(DID('instelform')){
		vlokeuze.selectedIndex=vloindex;
		vakNvlooien.value=Nvlooien;
		vakstraalfactor.value=straalfactor;
		vaksnelheidsfactor.value=snelheidsfactor;
		vaksinAsinBnuloffsetfactor.value=sinAsinBnuloffsetfactor;
		vakcirkelpartfactor.value=cirkelpartfactor;
		vaktoppenfactor.value=toppenfactor;
		volgmuisvak.checked=volgmuis;
		vakpresnr.value=presentatienr;
	};
};


function bijmuisbeweegopdezepag(evt) {
	if(document.getElementById('instellaag').style.visibility=='visible' ||
			(document.getElementById('instellaag').style.visibility=='hidden' && !volgmuis)){
		if(document.getElementById('volgmuisvak').checked ){
			volgmuis=true;
		}else{
			volgmuis=false;
		};
		xcentrumstreef= Vbrmid - parseInt(document.getElementById('instellaag').style.width)/2;
		ycentrumstreef= Vhomid;xcentrum=xcentrumstreef;
		ycentrum=ycentrumstreef;
		xcentrumwas=xcentrum;
		ycentrumwas=ycentrum;
	}else{
		if (!evt) {
			evt = window.event;
		}	
		xcentrumstreef=evt.clientX;
		ycentrumstreef=evt.clientY;
	};
};

function vlooienverplaatsen(){
	delta_x=xcentrumstreef-xcentrum;
	delta_y=ycentrumstreef-ycentrum;
	xcentrum=xcentrum+delta_x*0.02;
	ycentrum=ycentrum+delta_y*0.02;
	straalstreef=straalstreef0*(1-(Math.abs(delta_x)+Math.abs(delta_y))*0.0025);
	straal=straal+(straalstreef-straal)*0.05;
	for(j=0;j<Nvlooien;j++){
		vloj='vlo'+j;
		vloafstand=cirkelptpervlo*j;
		if(toppenfactor>=0){
			sinAargnr=Math.round(vlo0cirkelpt+vloafstand)%Ncirkelpt;
			sinBargnr=Math.round(vlo0cirkelpt+Math.abs(vloafstand*toppenfactor)+sinAsinBnuloffset)%Ncirkelpt;
		}else{
			sinBargnr=Math.round(vlo0cirkelpt+vloafstand)%Ncirkelpt;
			sinAargnr=Math.round(vlo0cirkelpt+Math.abs(vloafstand*toppenfactor)+sinAsinBnuloffset)%Ncirkelpt;
		}
		document.getElementById(vloj).style.left=Math.round(straal*sinw[sinAargnr]+xcentrum);
		document.getElementById(vloj).style.top= Math.round(straal*sinw[sinBargnr]+ycentrum);
	};
	if((xcentrum>Vbrmid && ycentrum<Vhomid) || (xcentrum<Vbrmid && ycentrum>Vhomid)){
		vlo0cirkelpt++;
		if(vlo0cirkelpt>=Ncirkelpt)vlo0cirkelpt=0;
	}else{
		vlo0cirkelpt--;
		if(vlo0cirkelpt<0)vlo0cirkelpt=Ncirkelpt;
	};
};



