window.onload=function() {
	url="xml/obteImg.php";
	var params="img=1";
	var ajax=new Ajax.Request( url, {
		method: 'post',
		postBody: params,
		onComplete: function(reply) {
			var arrImg=new Array();
			arrImg=reply.responseText.split(",");
				
			var dCont=$('banner');
			buida(dCont);
			for (var k=0; k<arrImg.length;k++) {
				var img=document.createElement('img');
				img.src="img/1/"+arrImg[k];
				img.style.display='none';
				img.id="banner"+k;
				dCont.appendChild(img);
			}
			
			posaEfecte(arrImg.length);
		}
	});
}

function posaEfecte(j) {
	//new Effect.Appear("banner0", { duration: 20.0 });
	
	for (var k=0; k<j;k++) {
		new Effect.Appear("banner"+k, { duration: 2.0, queue: { position: 'end', scope: 'banner' } });
			
		if (k==(j-1)) {
			new Effect.Fade("banner"+k, { duration: 2.0, queue: { position: 'end', scope: 'banner' }, afterFinish: function() { posaEfecte(j); } });
		} else {
			new Effect.Fade("banner"+k, { duration: 2.0, queue: { position: 'end', scope: 'banner' } });
		}
	}
}

function buida(el){// elimina tots els "child nodes" de l'element que li passam per parámetre
    if(el!=null){
        if(el.childNodes){
            for(var i=el.childNodes.length-1;i>=0;i--){
                var childNode=el.childNodes[i];
                el.removeChild(childNode);
            }
        }
    }
}

function ponFlash(i, fl) {
	
	var d=i.parentNode;
	i.alt="Restaurante-Bahía-Mediterraneo";
	i.title="Restaurante-Bahía-Mediterraneo";
	
	var i1=document.createElement('img');
	i1.src="img/panoramicas/entrada.jpg";
	i1.onclick=function() {
		ponFlash(this,"panoEntrada.swf");
	}
	var d1=$('dEntrada');
	buida(d1);
	d1.appendChild(i1);
	
	var i2=document.createElement('img');
	i2.src="img/panoramicas/rest1.jpg";
	i2.onclick=function() {
		ponFlash(this,"rest1.swf");
	}
	var d2=$('dRest1');
	buida(d2);
	d2.appendChild(i2);
	
	var i3=document.createElement('img');
	i3.src="img/panoramicas/rest2.jpg";
	i3.onclick=function() {
		ponFlash(this,"rest2.swf");
	}
	var d3=$('dRest2');
	buida(d3);
	d3.appendChild(i3);
	
	var i4=document.createElement('img');
	i4.src="img/panoramicas/rest3.jpg";
	i4.onclick=function() {
		ponFlash(this,"rest3.swf");
	}
	
	var d4=$('dRest3');
	buida(d4);
	d4.appendChild(i4);
	
	
	var so = new SWFObject('flash/'+fl,d.id+"civ",'606','243','8');
		so.write(d.id);
}
