// Funcions comunes
var theLayer1;
var theLayer2;
var theLayer3;
var theLayer4;
var theLayer5;
var theLayer6;
var theLayer7;
var theLayer8;
var theLayer9;
var theLayer10;
var i,e,aux;


var taula_rand = crear_taula( 10, 1, 10 );

function crear_taula(num,min,max)
{
    var temp, nums = new Array;

    for (var element=0; element<num; element++)
        {
        while((temp=num_trobat((Math.round((max-min) * Math.random() + min)),nums))==-1);
        nums[element] = temp;
        }
    return (nums)
}


function num_trobat (random_num,num_array)
{
    for (var element=0; element<num_array.length; element++)
        {
        if (random_num==num_array[element])
            return (-1);
        }
    return (random_num);
}	


function init(){
if (document.layers){
	theLayer1 = document.layers['ly1'];
	theLayer2 = document.layers['ly2'];
	theLayer3 = document.layers['ly3'];
	theLayer4 = document.layers['ly4'];
	theLayer5 = document.layers['ly5'];
	theLayer6 = document.layers['ly6'];
	theLayer7 = document.layers['ly7'];
	theLayer8 = document.layers['ly8'];
	theLayer9 = document.layers['ly9'];
	theLayer10 = document.layers['ly10'];
}else{
	theLayer1 = ly1.style;
	theLayer2 = ly2.style;
	theLayer3 = ly3.style;
	theLayer4 = ly4.style;
	theLayer5 = ly5.style;
	theLayer6 = ly6.style;
	theLayer7 = ly7.style;
	theLayer8 = ly8.style;
	theLayer9 = ly9.style;
	theLayer10 = ly10.style;
}
	
theLayer1.left = 251;
theLayer1.top = 71;
theLayer2.left = 253;
theLayer2.top = 73;
theLayer3.left = 255;
theLayer3.top = 75;
theLayer4.left = 257;
theLayer4.top = 77;
theLayer5.left = 259;
theLayer5.top = 79;
theLayer6.left = 261;
theLayer6.top = 81;
theLayer7.left = 263;
theLayer7.top = 83;
theLayer8.left = 265;
theLayer8.top = 85;
theLayer9.left = 267;
theLayer9.top = 87;
theLayer10.left = 269;
theLayer10.top = 89;
	
pause(2);

}

function pause(b){
  counter=(b-1);
    if (counter>0){
      setTimeout('pause(counter)',counter*1000);
    }else if(counter==0){
      llocs();
    }
}

function getWinNm() {
var now = new Date();
var hr = new String(now.getHours());
var mn = new String(now.getMinutes());
var sc = new String(now.getSeconds());
var winNm = hr + mn + sc;
return winNm;
}

function openWin(url) {
   window.open(url,getWinNm(),'width=770,height=440,location=no,toolbar=no,directories=no,menubar=no,resizable=no,scrollbars=no,status=no');
}

function llocs(){
tops = new Array(10);
lefts = new Array(10);

tops [0]= 45;	
tops [1]= 45;	
tops [2]= 45;	
tops [3]= 45;	
tops [4]= 45;	
tops [5]= 240;	
tops [6]= 240;	
tops [7]= 240;	
tops [8]= 240;	
tops [9]= 240;	

lefts [0]= 5;	
lefts [1]= 155;	
lefts [2]= 305;	
lefts [3]= 455;	
lefts [4]= 605;	
lefts [5]= 5;	
lefts [6]= 155;	
lefts [7]= 305;	
lefts [8]= 455;	
lefts [9]= 605;	
	
//theLayer1.left = lefts[taula_rand[0]-1];
//theLayer1.top = tops[taula_rand[0]-1];
//theLayer2.left = lefts[taula_rand[1]-1];
//theLayer2.top = tops[taula_rand[1]-1];
//theLayer3.left = lefts[taula_rand[2]-1];
//theLayer3.top = tops[taula_rand[2]-1];
//theLayer4.left = lefts[taula_rand[3]-1];
//theLayer4.top = tops[taula_rand[3]-1];
//theLayer5.left = lefts[taula_rand[4]-1];
//theLayer5.top = tops[taula_rand[4]-1];
//theLayer6.left = lefts[taula_rand[5]-1];
//theLayer6.top = tops[taula_rand[5]-1];
//theLayer7.left = lefts[taula_rand[6]-1];
//theLayer7.top = tops[taula_rand[6]-1];
//theLayer8.left = lefts[taula_rand[7]-1];
//theLayer8.top = tops[taula_rand[7]-1];
//theLayer9.left = lefts[taula_rand[8]-1];
//theLayer9.top = tops[taula_rand[8]-1];
//theLayer10.left = lefts[taula_rand[9]-1];
//theLayer10.top = tops[taula_rand[9]-1];

rang1left=parseInt((parseInt(lefts[taula_rand[0]-1])-parseInt(theLayer1.left))/10);
rang1top=parseInt((parseInt(tops[taula_rand[0]-1])-parseInt(theLayer1.top))/10);
rang2left=parseInt((parseInt(lefts[taula_rand[1]-1])-parseInt(theLayer2.left))/10);
rang2top=parseInt((parseInt(tops[taula_rand[1]-1])-parseInt(theLayer2.top))/10);
rang3left=parseInt((parseInt(lefts[taula_rand[2]-1])-parseInt(theLayer3.left))/10);
rang3top=parseInt((parseInt(tops[taula_rand[2]-1])-parseInt(theLayer3.top))/10);
rang4left=parseInt((parseInt(lefts[taula_rand[3]-1])-parseInt(theLayer4.left))/10);
rang4top=parseInt((parseInt(tops[taula_rand[3]-1])-parseInt(theLayer4.top))/10);
rang5left=parseInt((parseInt(lefts[taula_rand[4]-1])-parseInt(theLayer5.left))/10);
rang5top=parseInt((parseInt(tops[taula_rand[4]-1])-parseInt(theLayer5.top))/10);
rang6left=parseInt((parseInt(lefts[taula_rand[5]-1])-parseInt(theLayer6.left))/10);
rang6top=parseInt((parseInt(tops[taula_rand[5]-1])-parseInt(theLayer6.top))/10);
rang7left=parseInt((parseInt(lefts[taula_rand[6]-1])-parseInt(theLayer7.left))/10);
rang7top=parseInt((parseInt(tops[taula_rand[6]-1])-parseInt(theLayer7.top))/10);
rang8left=parseInt((parseInt(lefts[taula_rand[7]-1])-parseInt(theLayer8.left))/10);
rang8top=parseInt((parseInt(tops[taula_rand[7]-1])-parseInt(theLayer8.top))/10);
rang9left=parseInt((parseInt(lefts[taula_rand[8]-1])-parseInt(theLayer9.left))/10);
rang9top=parseInt((parseInt(tops[taula_rand[8]-1])-parseInt(theLayer9.top))/10);
rang10left=parseInt((parseInt(lefts[taula_rand[9]-1])-parseInt(theLayer10.left))/10);
rang10top=parseInt((parseInt(tops[taula_rand[9]-1])-parseInt(theLayer10.top))/10);

moviment(tops,lefts,rang1left,rang2left,rang3left,rang4left,rang5left,rang6left,rang7left,rang8left,rang9left,rang10left,rang1top,rang2top,rang3top,rang4top,rang5top,rang6top,rang7top,rang8top,rang9top,rang10top,10,taula_rand);


}


function moviment(tops,lefts,rang1left,rang2left,rang3left,rang4left,rang5left,rang6left,rang7left,rang8left,rang9left,rang10left,rang1top,rang2top,rang3top,rang4top,rang5top,rang6top,rang7top,rang8top,rang9top,rang10top,a){

	counter=a-1;
	if(a>0){
		theLayer1.left = parseInt(theLayer1.left) + rang1left;
		theLayer1.top = parseInt(theLayer1.top) + rang1top;
		theLayer2.left = parseInt(theLayer2.left) + rang2left;
		theLayer2.top = parseInt(theLayer2.top) + rang2top;
		theLayer3.left = parseInt(theLayer3.left) + rang3left;
		theLayer3.top = parseInt(theLayer3.top) + rang3top;
		theLayer4.left = parseInt(theLayer4.left) + rang4left;
		theLayer4.top = parseInt(theLayer4.top) + rang4top;
		theLayer5.left = parseInt(theLayer5.left) + rang5left;
		theLayer5.top = parseInt(theLayer5.top) + rang5top;
		theLayer6.left = parseInt(theLayer6.left) + rang6left;
		theLayer6.top = parseInt(theLayer6.top) + rang6top;
		theLayer7.left = parseInt(theLayer7.left) + rang7left;
		theLayer7.top = parseInt(theLayer7.top) + rang7top;
		theLayer8.left = parseInt(theLayer8.left) + rang8left;
		theLayer8.top = parseInt(theLayer8.top) + rang8top;
		theLayer9.left = parseInt(theLayer9.left) + rang9left;
		theLayer9.top = parseInt(theLayer9.top) + rang9top;
		theLayer10.left = parseInt(theLayer10.left) + rang10left;
		theLayer10.top = parseInt(theLayer10.top) + rang10top;
		setTimeout('moviment(tops,lefts,rang1left,rang2left,rang3left,rang4left,rang5left,rang6left,rang7left,rang8left,rang9left,rang10left,rang1top,rang2top,rang3top,rang4top,rang5top,rang6top,rang7top,rang8top,rang9top,rang10top,counter)',counter);
	}
}


function screwIt() {	
	if (parseInt(theLayer1.left) > 0) {
		theLayer1.left = parseInt(theLayer1.left) - 10;
		theLayer2.left = parseInt(theLayer2.left) - 10;
		theLayer3.left = parseInt(theLayer3.left) - 10;
		theLayer4.left = parseInt(theLayer4.left) - 10;
		theLayer5.left = parseInt(theLayer5.left) - 10;
		theLayer6.left = parseInt(theLayer6.left) - 10;
		theLayer7.left = parseInt(theLayer7.left) - 10;
		theLayer8.left = parseInt(theLayer8.left) - 10;
		theLayer9.left = parseInt(theLayer9.left) - 10;
		theLayer10.left = parseInt(theLayer10.left) - 10;
		if (parseInt(theLayer1.top) > 5) {
			theLayer1.top = parseInt(theLayer1.top) - 4;
			theLayer2.top = parseInt(theLayer2.top) - 4;
			theLayer3.top = parseInt(theLayer3.top) - 4;
			theLayer4.top = parseInt(theLayer4.top) - 4;
			theLayer5.top = parseInt(theLayer5.top) - 4;
			theLayer6.top = parseInt(theLayer6.top) - 4;
			theLayer7.top = parseInt(theLayer7.top) - 4;
			theLayer8.top = parseInt(theLayer8.top) - 4;
			theLayer9.top = parseInt(theLayer9.top) - 4;
			theLayer10.top = parseInt(theLayer10.top) - 4;
		}
		setTimeout('screwIt()', 1);
	}
	/*theLayer1.top = 5;
	
	theLayer2.left = 150;	
	theLayer2.top = 5;*/
}
