var maxrychlost, vyska, sirka, start, naxvelikost, pocet_prasatek;
maxrychlost = 10;
vyska = 800;
sirka = 1000;
start = -200;
maxvelikost = 100;





function novy_prase(id,orientace)
{
this.id = id;
this.orientace = orientace;
this.rychlost=((Math.random()+0.2)*maxrychlost)*(2*this.orientace -1);
this_id = 'prasatko'+this.id;
if(orientace>0) this.left = (sirka+1); else (this.left)=start-1;

/*
this.pohni2 = function() {  
this_id = 'prasatko'+this.id;
this.left = this.left + this.rychlost;
document.getElementById(this_id).style.left = this.left;
setTimeout("this.pohni();",200);  
}  
*/
this.pohni = function() {
this.left = this.left + this.rychlost;
this_id = 'prasatko'+this.id;
//alert("u "+this.id+" nastavuju "+this.left+" a id je "+this_id);

if (this.left < start ) {
this.left = sirka;
document.getElementById(this_id).style.top = Math.random()*vyska;
document.getElementById(this_id).height = (Math.random()+0.2)*maxvelikost;
//rychlost pro opacne orientovany (orientace = 0) bude zaporna
this.rychlost=((Math.random()+0.2)*maxrychlost)*(2*this.orientace -1);
}
if (this.left > sirka ) {
this.left = start;
document.getElementById(this_id).style.top = Math.random()*vyska;
document.getElementById(this_id).height = (Math.random()+0.2)*maxvelikost;
//rychlost pro opacne orientovany (orientace = 0) bude zaporna
this.rychlost=((Math.random()+0.2)*maxrychlost)*(2*this.orientace -1);
}
document.getElementById(this_id).style.left = this.left;
}
}

//nektery masiny hazej chybu pri mnohonasobny rekurzi JEDNY fce - tak to obejdeme dvema stejnyma
function hejbej1()
{ for(b=1; b<pocet_prasatek; b++){
prasatka[b].pohni(); } 
setTimeout("hejbej2();",100);}
function hejbej2()
{ for(c=1; c<pocet_prasatek; c++){
prasatka[c].pohni(); } 
setTimeout("hejbej1();",100);}



//prvni volana funkce - vytvori objekty k paralelne vytvorenym obrazkum ( ty vytvori php skript a zavola f-ci s jejich pocetm coby parametrem)
function prasatka(pocet)
{
//pocet potrebujem v global promenny
pocet_prasatek=pocet;
prasatka = new Array(); 
for(i=1; i<pocet_prasatek; i++){
a=i % 2;
prasatka[i] = new novy_prase(i,a); 
 }
hejbej1(); 


}





