// -- OMPLIR fadeimages amb les rutes dels arxius
// dintre de la cel.la (td) que toqui, posar per exemple:
			//<script type="text/javascript">
			//    new fadeshow(fadeimages, 274, 274, 0, 5000, 1, 0)
			// < /script>
var fadeimages=new Array()
var fadebgcolor="rgb(192,192,192)"

////NO need to edit beyond here/////////////
 
var fadearray=new Array() //array to cache fadeshow instances
var fadeclear=new Array() //array to cache corresponding clearinterval pointers
 
var dom=(document.getElementById) //modern dom browsers
var iebrowser=document.all

// --------------------------- JOEL
// selecciona una imatge FENT TRANSICIÓ i para el SLIDESHOW
function select_image(numItem)
{
g_CANCEL=1;
var obj=fadearray[0];

clearInterval(fadeclear[obj.slideshowid])
obj.nextcanvas=(obj.curcanvas==obj.canvasbase+"_0")? obj.canvasbase+"_0" : obj.canvasbase+"_1"
obj.tempobj=iebrowser? iebrowser[obj.nextcanvas] : document.getElementById(obj.nextcanvas)
obj.tempobj.style.opacity=100;
obj.populateslide(obj.tempobj, numItem)
obj.nextimageindex=numItem
obj.curimageindex=numItem
obj.rotateimage(0,numItem)
}

function start_fadeshow()
{
	if (iebrowser&&dom||dom) //if IE5+ or modern browsers such as Firefox
	{
	var obj=fadearray[0];
	obj.startit()
	}
}
// --------------------------- JOEL
 
function fadeshow(theimages, fadewidth, fadeheight, borderwidth, delay, pause, displayorder){
	this.pausecheck=pause
	this.mouseovercheck=0
	this.delay=delay
	this.degree=10 //initial opacity degree (10%)
	this.curimageindex=0
	this.nextimageindex=1
	fadearray[fadearray.length]=this
	this.slideshowid=fadearray.length-1
	this.canvasbase="canvas"+this.slideshowid
	this.curcanvas=this.canvasbase+"_0"
	// [JOEL] no vull RANDOM if (typeof displayorder!="undefined")
	//theimages.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :)
	this.theimages=theimages
	this.imageborder=parseInt(borderwidth)
	this.postimages=new Array() //preload images
	for (p=0;p<theimages.length;p++){
		this.postimages[p]=new Image()
		this.postimages[p].src=theimages[p][0]
		this.postimages[p].width="50px"
	}
 
	var fadewidth=fadewidth+this.imageborder*2
	var fadeheight=fadeheight+this.imageborder*2
	 
	if (iebrowser&&dom||dom) //if IE5+ or modern browsers (ie: Firefox)
	{
		document.write('<div id="master'+this.slideshowid+'" style="position:relative;width:'+fadewidth+'px;height:'+fadeheight+'px;overflow:hidden;"><div id="'+this.canvasbase+'_0" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div><div id="'+this.canvasbase+'_1" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div></div>')
	}
}

function fadepic(obj,auto,numeroImatge){
if (auto==0) g_CANCEL=1;

	if (obj.degree<100){
		obj.degree+=10
		if (obj.tempobj.filters&&obj.tempobj.filters[0]){
			if (typeof obj.tempobj.filters[0].opacity=="number") //if IE6+
				obj.tempobj.filters[0].opacity=obj.degree
			else //else if IE5.5-
				obj.tempobj.style.filter="alpha(opacity="+obj.degree+")"
		}
		else if (obj.tempobj.style.MozOpacity)
			obj.tempobj.style.MozOpacity=obj.degree/101
		else if (obj.tempobj.style.KhtmlOpacity)
			obj.tempobj.style.KhtmlOpacity=obj.degree/100
		else if (obj.tempobj.style.opacity&&!obj.tempobj.filters)
			obj.tempobj.style.opacity=obj.degree/101
	}
	else{
		// al final de fer la transició, en el next canvas posa la següent imatge
		clearInterval(fadeclear[obj.slideshowid])
		obj.nextcanvas=(obj.curcanvas==obj.canvasbase+"_0")? obj.canvasbase+"_0" : obj.canvasbase+"_1"
		obj.tempobj=iebrowser? iebrowser[obj.nextcanvas] : document.getElementById(obj.nextcanvas)
		//alert(obj.nextimageindex)
		obj.populateslide(obj.tempobj, obj.nextimageindex)
		obj.nextimageindex=(obj.nextimageindex<obj.postimages.length-1)? obj.nextimageindex+1 : 0
			if (g_CANCEL==0) // mentre no cancel.lem el slide
			{setTimeout("fadearray["+obj.slideshowid+"].rotateimage("+auto+")", obj.delay)}
	}
}

fadeshow.prototype.populateslide=function(picobj, picindex){
	if (picindex>numeroFotos-1) picindex=numeroFotos-1;
	
	var slideHTML=""
	slideHTML+='<img src="'+this.postimages[picindex].src+'" border="'+this.imageborder+'px">'
	picobj.innerHTML=slideHTML
}
  
fadeshow.prototype.rotateimage=function(auto,numeroImatge){
// control de si estic passant les imatges automàticament
if (auto==0) g_CANCEL=1;
if ((auto==1)&&(g_CANCEL==1)) return;

	if (iebrowser&&dom||dom)
	{
		this.resetit()
	var crossobj=this.tempobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
		crossobj.style.zIndex++
		fadeclear[this.slideshowid]=setInterval("fadepic(fadearray["+this.slideshowid+"],"+auto+","+numeroImatge+")",50)
		this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0"
	}
	
			{
			// -------------------- [JOEL]
			// actualitzem els colors de fons dels selectors d'imatges
			// també ensenya el link que toca!
			var contenedor=document.getElementById('pr_imatge')
			var descripcio=document.getElementById('pr_imatge_descripcio')
			for (var i=0;i<numeroFotos;i++)
			{
			var nom="selector_imatge"+i
			var td=document.getElementById(nom)
			nom="div_zoom_icon"+i
			var divlupa=document.getElementById(nom)
				if (this.curimageindex==i)
				{
				td.style.backgroundColor="rgb(255,255,255)";
					if (divlupa)
					{
					divlupa.style.visibility="visible";
					var posicio=contenedor_width-50;
					divlupa.style.left=posicio+"px";
					}
				}
				else
				{
				td.style.backgroundColor="#CCCCCC";	
					if (divlupa)
					{divlupa.style.visibility="hidden";}
				}
			}
			descripcio.innerHTML="<br>"+g_aImatges_descripcio[this.curimageindex];
			// -------------------- [JOEL]
			}
	
this.curimageindex=(this.curimageindex<this.postimages.length-1)? this.curimageindex+1 : 0
}
	 
fadeshow.prototype.resetit=function(){
	this.degree=10
	var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
	if (crossobj.filters&&crossobj.filters[0]){
		if (typeof crossobj.filters[0].opacity=="number") //if IE6+
			crossobj.filters(0).opacity=this.degree
		else //else if IE5.5-
			crossobj.style.filter="alpha(opacity="+this.degree+")"
	}
	else if (crossobj.style.MozOpacity)
		crossobj.style.MozOpacity=this.degree/101
	else if (crossobj.style.KhtmlOpacity)
		crossobj.style.KhtmlOpacity=this.degree/100
	else if (crossobj.style.opacity&&!crossobj.filters)
		crossobj.style.opacity=this.degree/101
}
 
 
fadeshow.prototype.startit=function(){
	var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
	this.populateslide(crossobj, this.curimageindex)
	this.rotateimage(1)
}