// JavaScript Document

var Via_img = "img/calendari/";
var Via_ombra = "ombra/";
var Img_blanc = "blanc.gif";
var Img_gris10 = "gris_10.gif";
var Marge = 10;
var Interval = 50;
var NumMoviments = 18;
var Ombra = 3;
var OmbraCentre = 2;
var OpacitatOff = 63;

function NumAleatori(NumMax) {
	var j
	NumMax+=1;
	j=parseInt(Math.random()*NumMax);
  j=(isNaN(j))?0:j;
	return j;
}

ObjAnimacio=function(NomFull, Pujar) {
	this.NomFull = NomFull;
	this.Pujar = Pujar;
	this.Moviments = NumMoviments;
	this.MovimentActual = 0;
	this.CanviarImatgeEfecte = false;
}

ObjImg=function(src) {
	this.Img = new Image();
	this.Carragada = false;
	this.Img.src = src;
	this.Img.onload = new Function ('Calendari.ImatgeCarregada(this)');
	this.Img.onerror = new Function ('Calendari.ErrorCarregaImatge(this)');
}

ObjFull=function (Nom, Num, Color, ImgSup, ImgInf) {
	this.Nom = Nom;
	this.Num = Num;
	this.Color = Color;
	Via = Via_img + "full_";
	if (Num < 10) Via += "0";
	Via += Num;
	if (ImgSup) this.ImgSup = new ObjImg(Via + "d.gif");
	if (ImgInf) this.ImgInf = new ObjImg(Via + "b.gif");
	this.Visible = false;
}

ObjCalendari=function (Id, X, Y, Ample, Alçada) {
	this.Id = Id;
	this.Anys = new Array();
	this.ObjFulls = new Array();
	this.Fulls = new Array();
	this.NumImg = 0;
	this.NumImgOk = 0;
	this.NumImgError = 0;
	this.CarregaImatgesfinalitzada = false;
	this.Left = X;
	this.Top = Y;
	this.ImgWidth = Ample;
	this.ImgHeight = Alçada / 2;
	this.Visible = false;
	this.Element;
	this.Ombra = new Array();
	this.Bloc;
	this.BlocSuperior;
	this.ImgSuperiorEfecte;
	this.ImgSuperior;
	this.BlocInferior;
	this.ImgInferior;
	this.ImgInferiorEfecte;
	this.Botonera;
	this.NomFullDefecte = "";
	this.NomFullActual = "";
	this.NumFullActual = -1;
	this.Animacions = new Array();
	this.Interval;
	this.OrdresAProcessar = new Array();
	this.AlçadaAnterior = 0;
	this.Info;
	this.BotoneraServei = false;
}

ObjCalendari.prototype={
	Crear:function (Info) {
		this.Info = Info;
		this.Element = document.createElement("div");
		this.Element.id = this.Id;
		this.Element.style.position = "absolute";
		this.Element.style.left = this.Left + "px";
		this.Element.style.top = this.Top + "px";
		this.Element.style.width = (this.ImgWidth + (2 * Ombra)) + "px";
		this.Element.style.height = (2 * (this.ImgHeight + Ombra)) + "px";
		//this.Element.style.backgroundColor = "#00FFFF";
		this.Element.style.visibility = "hidden";
		document.body.appendChild(this.Element);

		this.AfegirImatgeOmbra("TL", 0, 0, Ombra, 2 * Ombra, 1000, true);
		this.AfegirImatgeOmbra("TC", 0, 2 * Ombra, Ombra, this.ImgWidth - (2 * Ombra), 1000, true);
		this.AfegirImatgeOmbra("TR", 0, this.ImgWidth, Ombra, 2 * Ombra, 1000, true);
		this.AfegirImatgeOmbra("LT", Ombra, 0, Ombra, Ombra, 1000, true);
		this.AfegirImatgeOmbra("LC", 2 * Ombra, 0, 2 * (this.ImgHeight - Ombra), Ombra, 1000, true);
		this.AfegirImatgeOmbra("LB", 2 * this.ImgHeight, 0, Ombra, Ombra, 1000, true);
		this.AfegirImatgeOmbra("RT", Ombra, this.ImgWidth + Ombra, Ombra, Ombra, 1000, true);
		this.AfegirImatgeOmbra("RC", 2 * Ombra, this.ImgWidth + Ombra, 2 * (this.ImgHeight - Ombra), Ombra, 1000, true);
		this.AfegirImatgeOmbra("RB", 2 * this.ImgHeight, this.ImgWidth + Ombra, Ombra, Ombra, 1000, true);
		this.AfegirImatgeOmbra("BL", 2 * this.ImgHeight + Ombra, 0, Ombra, 2 * Ombra, 1000, true);
		this.AfegirImatgeOmbra("BC", 2 * this.ImgHeight + Ombra, 2 * Ombra, Ombra, this.ImgWidth - (2 * Ombra), 1000, true);
		this.AfegirImatgeOmbra("BR", 2 * this.ImgHeight + Ombra, this.ImgWidth, Ombra, 2 * Ombra, 1000, true);
		this.AfegirImatgeOmbra("CC", this.ImgHeight + Ombra - (OmbraCentre / 2), Ombra, OmbraCentre, this.ImgWidth, 1002, false);
		this.AfegirImatgeOmbra("EV", 0, Ombra, 1, this.ImgWidth, 1002, false);

		this.Bloc = document.createElement("div");
		this.Bloc.id = "Bloc";
		this.Bloc.style.position = "absolute";
		this.Bloc.style.left = Ombra + "px";
		this.Bloc.style.top = Ombra + "px";
		this.Bloc.style.width = this.ImgWidth + "px";
		this.Bloc.style.height = (2 * this.ImgHeight) + "px";
		this.Bloc.style.backgroundColor = "#FFFFFF";
		this.Element.appendChild(this.Bloc);
		
		this.BlocSuperior = document.createElement("div");
		this.BlocSuperior.id = "BlocSuperior";
		this.BlocSuperior.style.width = this.ImgWidth + "px";
		this.BlocSuperior.style.height = this.ImgHeight + "px";
		this.BlocSuperior.style.display = "block";
		this.Bloc.appendChild(this.BlocSuperior);
		
		this.ImgSuperior = document.createElement("img");
		this.ImgSuperior.id = "ImgSuperior";
		this.ImgSuperior.style.width = this.ImgWidth + "px";
		this.ImgSuperior.style.height = this.ImgHeight + "px";
		this.ImgSuperior.style.position = "absolute";
		this.ImgSuperior.border = "0";
		this.ImgSuperior.style.zIndex = "1000";
		this.ImgSuperior.style.visibility = "hidden";
		this.BlocSuperior.appendChild(this.ImgSuperior);
		
		this.ImgSuperiorEfecte = document.createElement("img");
		this.ImgSuperiorEfecte.id = "ImgSuperiorEfecte";
		this.ImgSuperiorEfecte.style.width = this.ImgWidth + "px";
		this.ImgSuperiorEfecte.style.height = this.ImgHeight + "px";
		this.ImgSuperiorEfecte.style.position = "absolute";
		this.ImgSuperiorEfecte.border = "0";
		this.ImgSuperiorEfecte.style.zIndex = "1001";
		this.ImgSuperiorEfecte.style.visibility = "hidden";
		this.BlocSuperior.appendChild(this.ImgSuperiorEfecte);
		
		this.BlocInferior = document.createElement("div");
		this.BlocInferior.id = "BlocInferior";
		this.BlocInferior.style.width = this.ImgWidth + "px";
		this.BlocInferior.style.height = this.ImgHeight + "px";
		this.BlocInferior.style.display = "block";
		this.Bloc.appendChild(this.BlocInferior);
		
		this.ImgInferior = document.createElement("img");
		this.ImgInferior.id = "ImgInferior";
		this.ImgInferior.style.width = this.ImgWidth + "px";
		this.ImgInferior.style.height = this.ImgHeight + "px";
		this.ImgInferior.style.position = "absolute";
		this.ImgInferior.border = "0";
		this.ImgInferior.style.zIndex = "1000";
		this.ImgInferior.style.visibility = "hidden";
		this.BlocInferior.appendChild(this.ImgInferior);

		this.ImgInferiorEfecte = document.createElement("img");
		this.ImgInferiorEfecte.id = "ImgInferiorEfecte";
		this.ImgInferiorEfecte.style.width = this.ImgWidth + "px";
		this.ImgInferiorEfecte.style.height = this.ImgHeight + "px";
		this.ImgInferiorEfecte.style.position = "absolute";
		this.ImgInferiorEfecte.border = "0";
		this.ImgInferiorEfecte.style.zIndex = "1001";
		this.ImgInferiorEfecte.style.visibility = "hidden";
		this.BlocInferior.appendChild(this.ImgInferiorEfecte);
		
		this.Botonera = document.createElement("div");
		this.Botonera.id = "Botonera";
		this.Botonera.style.position = "relative";
		this.Botonera.style.left = (this.ImgWidth + Marge) + "px";
		this.Botonera.style.display = "block";
		this.Element.appendChild(this.Botonera);
		//this.CapturarClickElementsPerInformacio();
		this.CapturarClickElements();
	},
	AfegirImatgeOmbra:function (Nom, Top, Left, Height, Width, zIndex, Visible) {
		this.Ombra[Nom] = document.createElement("img");
		this.Ombra[Nom].id = Nom;
		this.Ombra[Nom].style.position = "absolute";
		this.Ombra[Nom].style.top = Top + "px";
		this.Ombra[Nom].style.left = Left + "px";
		this.Ombra[Nom].src = Via_img + Via_ombra + Nom + ".png";
		this.Ombra[Nom].style.height = Height + "px";
		this.Ombra[Nom].style.width = Width + "px";
		this.Ombra[Nom].border = "0";
		this.Ombra[Nom].style.zIndex = zIndex.toString();
		if (!Visible) this.Ombra[Nom].style.visibility = "hidden";
		this.Element.appendChild(this.Ombra[Nom]);
		this.Ombra[Nom].onclick = new Function("ControlClicEsquerre('" + Nom + "')");
		this.Ombra[Nom].oncontextmenu = ControlClicDret;
	}, 
	AfegirFull:function (Any, Mes, Nom, Color, ImgSup, ImgInf) {
		if (this.ObjFulls.length == 0) this.NomFullDefecte = Nom;
		this.Fulls[Nom] = this.ObjFulls.length;
		if (ImgSup) this.NumImg += 1;
		if (ImgInf) this.NumImg += 1;
		this.ObjFulls[this.ObjFulls.length] = new ObjFull(Nom, this.ObjFulls.length, Color, ImgSup, ImgInf);
		this.CarregaImatgesfinalitzada = false;
		if (!this.Anys.KeyExists(Any)) this.Anys[Any] = new Array;
		if (!this.Anys[Any].KeyExists(Mes)) this.Anys[Any][Mes] = Nom;
	},
	CapturarClickElements:function() {
		//this.Bloc.onclick = new Function("ControlClicEsquerre('Bloc')");
		//this.BlocSuperior.onclick = new Function("ControlClicEsquerre('BlocSuperior')");
		this.ImgSuperior.onclick = new Function("ControlClicEsquerre('ImgSuperior')");
		this.ImgSuperiorEfecte.onclick = new Function("ControlClicEsquerre('ImgSuperiorEfecte')");
		//this.BlocInferior.onclick = new Function("ControlClicEsquerre('BlocInferior')");
		this.ImgInferior.onclick = new Function("ControlClicEsquerre('ImgInferior')");
		this.ImgInferiorEfecte.onclick = new Function("ControlClicEsquerre('ImgInferiorEfecte')");
		
		//this.Bloc.oncontextmenu = ControlClicDret;
		//this.BlocSuperior.oncontextmenu = ControlClicDret;
		this.ImgSuperior.oncontextmenu = ControlClicDret;
		this.ImgSuperiorEfecte.oncontextmenu = ControlClicDret;
		//this.BlocInferior.oncontextmenu = ControlClicDret;
		this.ImgInferior.oncontextmenu = ControlClicDret;
		this.ImgInferiorEfecte.oncontextmenu = ControlClicDret;
	}, 
	CapturarClickElementsPerInformacio:function() {
		this.Bloc.onclick = new Function("MostrarMissatge('Bloc')");
		this.BlocSuperior.onclick = new Function("MostrarMissatge('BlocSuperior')");
		this.ImgSuperior.onclick = new Function("MostrarMissatge('ImgSuperior')");
		this.ImgSuperiorEfecte.onclick = new Function("MostrarMissatge('ImgSuperiorEfecte')");
		this.BlocInferior.onclick = new Function("MostrarMissatge('BlocInferior')");
		this.ImgInferior.onclick = new Function("MostrarMissatge('ImgInferior')");
		this.ImgInferiorEfecte.onclick = new Function("MostrarMissatge('ImgInferiorEfecte')");	
	}, 
	MostrarInfo:function() {
		alert(this.Info);
	}, 
	CrearBotoneraServei:function() {
		for (var i = 0; i < this.ObjFulls.length; i++) {
			Boto = document.createElement("input");
			Boto.type = "button";
			Boto.id = this.ObjFulls[i].Nom;
			Boto.name = "Boto_" + this.ObjFulls[i].Nom;
			Boto.value = this.ObjFulls[i].Nom;
			Boto.className = "boto_full";
			Boto.style.color = this.ObjFulls[i].Color;
			Boto.onclick = new Function ("Calendari.AnarAFull('" + this.ObjFulls[i].Nom + "')");
			//Boto.onclick = new Function ("Calendari.Mostrar('" + this.ObjFulls[i].Nom + "')");
			Paragraf = document.createElement("p");
			Paragraf.appendChild(Boto);
			Paragraf.className = "boto_full";
			this.Botonera.appendChild(Paragraf);
		}
		
		Quadre = document.createElement("input");
		Quadre.type = "text";
		Quadre.id = "interval";
		Quadre.value = Interval.toString();
		Quadre.className = "quadre_ms";
		Paragraf = document.createElement("p");
		Paragraf.appendChild(Quadre);
		Paragraf.innerHTML = "ms: " + Paragraf.innerHTML;
		Paragraf.className = "boto_full";
		this.Botonera.appendChild(Paragraf);
		
		this.Info = document.createElement("p");
		this.Info.className = "boto_full";
		this.Info.id = "info";
		this.Botonera.appendChild(this.Info);
		this.BotoneraServei = true;
	},
	CrearBotonera:function() {
		var Fila;
		var Cela;
		var Taula = document.createElement("table");
		var CosTaula = document.createElement("tbody");
		Taula.id = "TaulaBotons";
		Taula.cellPadding = 0;
		Taula.cellSpacing = 0;
		Taula.style.marginTop = Ombra + "px";
		this.Botonera.appendChild(Taula);
		Taula.appendChild(CosTaula);
		for (var i = 0; i < this.ObjFulls.length; i++) {
			Fila = document.createElement("tr");
			Cela = document.createElement("td");
			Cela.className = "Boto";
			Cela.id = this.ObjFulls[i].Nom;
			//Cela.innerHTML = this.ObjFulls[i].Nom.toLowerCase();
			Cela.appendChild(document.createTextNode(this.ObjFulls[i].Nom.toLowerCase()));
			Cela.style.fontFamily = "Verdana, Arial, Helvetica, sans-serif";
			Cela.style.color = this.ObjFulls[i].Color;
			//Cela.title = this.ObjFulls[i].Nom;
			Cela.onclick = new Function ("Calendari.AnarAFull('" + this.ObjFulls[i].Nom + "')");
			//Cela.onclick = new Function ("Calendari.Mostrar('" + this.ObjFulls[i].Nom + "')");
			Cela.onmouseover = new Function ("Calendari.CelaOver('" + this.ObjFulls[i].Nom + "')");
			Cela.onmouseout = new Function ("Calendari.CelaOut('" + this.ObjFulls[i].Nom + "')");
			Fila.appendChild(Cela);
			Cela.style.opacity = OpacitatOff / 100;
			Cela.style.filter = "alpha(opacity=" + OpacitatOff + ")";
			CosTaula.appendChild(Fila);
		}
		/*Taula.style.opacity = .65;
		Taula.style.filter = "alpha(opacity=" + 65 + ")";*/
	}, 
	CalcularMesActual:function() {
		var Data = new Date();
		var Mes = Data.getMonth();
		var Any = Data.getFullYear();
		if (this.Anys.KeyExists(Any)) {
			if (this.Anys[Any].KeyExists(Mes)) {
				this.NomFullDefecte = this.Anys[Any][Mes];
			}
		}
	},
	ProcessarOrdresAnteriors:function() {
		AmagarEspera();
		while (this.OrdresAProcessar.length > 0) {
			Ordre = this.OrdresAProcessar[0];
			this.OrdresAProcessar.splice(0,1);
			eval(Ordre);
		}
	},
	ProcessarErrorCarregaImatges:function() {
		AmagarEspera();
	},
	ImatgeCarregada:function(Img) {
		Img.Carragada = true;
		//alert('Imatge carregada: '+ Img.src);
		this.NumImgOk++;
		this.CarregaImatgesfinalitzada = ((this.NumImgOk + this.NumImgError) == this.NumImg);
		if (this.CarregaImatgesfinalitzada) {
			if (this.NumImgOk == this.NumImg) {
				this.ProcessarOrdresAnteriors();
			} else {
				this.ProcessarErrorCarregaImatges();
			}
		}
	},
	ErrorCarregaImatge:function(el) {
		alert('Error en carregar la imatge: '+ Img.src);
		this.NumImgError++;
		this.CarregaImatgesfinalitzada = ((this.NumImgOk + this.NumImgError) == this.NumImg);
		if (this.CarregaImatgesfinalitzada) this.ProcessarErrorCarregaImatges();
	},
	Mostrar:function(NomFull) {
		var Alçada = 0;
		var Mig = 0;
		if (!this.CarregaImatgesfinalitzada) {
			this.OrdresAProcessar[this.OrdresAProcessar.length] = "this.Mostrar('" + NomFull + "')";
			return;
		}
		if (!this.Fulls.KeyExists(NomFull)) NomFull = this.NomFullDefecte;
		if (NomFull != this.NomFullActual) {
			if (this.NomFullActual != "") this.MarcarBoto(this.NomFullActual, false);
			this.NomFullActual = NomFull;
			this.NumFullActual = this.Fulls[NomFull];
			AmagarElement(this.ImgSuperior);
			AmagarElement(this.ImgInferior);
			if (this.ObjFulls[this.NumFullActual].ImgSup) {
				Alçada += this.ImgHeight;
				DimensionarAlçadaElement(this.BlocSuperior, this.ImgHeight);
				CarregarImatge(this.ImgSuperior, this.ObjFulls[this.NumFullActual].ImgSup.Img.src);
				MostrarElement(this.ImgSuperior);
			} else {
				DimensionarAlçadaElement(this.BlocSuperior, 0);
			}
			if (this.ObjFulls[this.NumFullActual].ImgInf) {
				Alçada += this.ImgHeight;
				DimensionarAlçadaElement(this.BlocInferior, this.ImgHeight);
				CarregarImatge(this.ImgInferior, this.ObjFulls[this.NumFullActual].ImgInf.Img.src);
				MostrarElement(this.ImgInferior);
			} else {
				DimensionarAlçadaElement(this.BlocInferior, 0);
			}
		}
		//if (Alçada == (2 * this.ImgHeight)) Mig = this.ImgHeight;
		this.PosicionarBlocIOmbra(Alçada, Mig);
		if (this.BotoneraServei) {
			Quadre = document.getElementById("interval");
			if (Quadre) {if (!Quadre.value) Quadre.value = Interval;}
		}
		this.MarcarBoto(this.NomFullActual, true);
		this.Element.style.visibility = "visible";
		this.Visible = true;
	},
	MarcarBoto:function(NomBoto, Marcar) {
		Boto = document.getElementById(NomBoto);
		var Color = this.ObjFulls[this.Fulls[NomBoto]].Color;
		if (Marcar) {
			/*Boto.style.opacity = 1;
			Boto.style.filter = "alpha(opacity=" + 100 + ")";*/
			Boto.style.backgroundColor = Color;
			Boto.style.color = "#FFFFFF";
			Boto.style.letterSpacing = "0.1em";
			Boto.style.cursor = "default";
		} else {
			/*Boto.style.opacity = OpacitatOff / 100;
			Boto.style.filter = "alpha(opacity=" + OpacitatOff + ")";*/
			Boto.style.backgroundColor = "";
			Boto.style.color = Color;
			Boto.style.letterSpacing = "0";
			Boto.style.cursor = "pointer";
		}
	}, 
	CelaOver:function(NomBoto) {
		if (NomBoto != this.NomFullActual) {
			Cela = document.getElementById(NomBoto);
			Cela.style.letterSpacing = "0.1em";
			Cela.style.opacity = 1;
			Cela.style.filter = "alpha(opacity=" + 100 + ")";
		}
	}, 
	CelaOut:function(NomBoto) {
		if (NomBoto != this.NomFullActual) {
			Cela = document.getElementById(NomBoto);
			Cela.style.letterSpacing = "0";
			Cela.style.opacity = OpacitatOff / 100;
			Cela.style.filter = "alpha(opacity=" + OpacitatOff + ")";
		}
	}, 
	AnarAFull:function(NomFull) {
		if (!this.CarregaImatgesfinalitzada) {
			this.OrdresAProcessar[this.OrdresAProcessar.length] = "this.AnarAFull('NomFull')";
			return;
		}
		if (this.Animacions.length > 0) return;
		if (!this.Fulls.KeyExists(this.NomFullActual)) {
			NomFull = this.NomFullDefecte;
			this.Mostrar(this.ObjFulls[0].Nom);
			this.AnarAFull(NomFull);
		}	else {
			if (typeof NomFull == 'undefined') {
				NomFull = this.NomFullActual;
			} else {
				if (!NomFull) NomFull = this.NomFullActual;
			}
			if (!this.Fulls.KeyExists(NomFull)) NomFull = this.NomFullDefecte;
			var Diferencia = this.Fulls[NomFull] - this.NumFullActual;
			if (Diferencia == 0) return;
			this.Animacions = new Array();
			if (Diferencia > 0) {
				for (var i = 1; i <= Diferencia; i++) {
					this.Animacions[this.Animacions.length] = new ObjAnimacio(this.ObjFulls[this.NumFullActual + i].Nom, true);
				}
			} else {
				for (var i = -1; i >= Diferencia; i--) {
					this.Animacions[this.Animacions.length] = new ObjAnimacio(this.ObjFulls[this.NumFullActual + i].Nom, false);
				}
			}
			CalExtra = this;
			if (this.BotoneraServei) {
				Quadre = document.getElementById("interval");
				if (Quadre) Interval = Quadre.value;
			}
			this.Interval = window.setInterval("ObjCalendari.prototype.GestionarAnimacions(CalExtra)", Interval);
		}
	},
	PosicionarBlocIOmbra:function(Alçada, Mig) {
		if (this.AlçadaAnterior == Alçada) return;
		
		// Ubicació al centre
		/*Espai = parseInt(((2 * this.ImgHeight) - Alçada) / 2);
		this.Ombra["TL"].style.top = Espai + "px";
		this.Ombra["TC"].style.top = Espai + "px";
		this.Ombra["TR"].style.top = Espai + "px";
		this.Ombra["LT"].style.top = (Espai + Ombra) + "px";
		this.Bloc.style.top = (Espai + Ombra) + "px";
		this.Bloc.style.height = (Espai + (2 * Ombra)) + "px";
		this.Ombra["LC"].style.top = (Espai + (2 * Ombra)) + "px";
		this.Ombra["LC"].style.height = (Alçada - (2 * Ombra)) + "px";
		this.Ombra["LB"].style.top = (Espai + Alçada) + "px";
		this.Ombra["RT"].style.top = (Espai + Ombra) + "px";
		this.Ombra["RC"].style.top = (Espai + (2 * Ombra)) + "px";
		this.Ombra["RC"].style.height = (Alçada - (2 * Ombra)) + "px";
		this.Ombra["RB"].style.top = (Espai + Alçada) + "px";
		this.Ombra["BL"].style.top = (Espai + Alçada + Ombra) + "px";
		this.Ombra["BC"].style.top = (Espai + Alçada + Ombra) + "px";
		this.Ombra["BR"].style.top = (Espai + Alçada + Ombra) + "px";*/
		
		// Ubicació superior
		this.Bloc.style.height = Alçada + "px";
		this.Ombra["LC"].style.height = (Alçada - (2 * Ombra)) + "px";
		this.Ombra["LB"].style.top = Alçada + "px";
		this.Ombra["RC"].style.height = (Alçada - (2 * Ombra)) + "px";
		this.Ombra["RB"].style.top = Alçada + "px";
		this.Ombra["BL"].style.top = (Alçada + Ombra) + "px";
		this.Ombra["BC"].style.top = (Alçada + Ombra) + "px";
		this.Ombra["BR"].style.top = (Alçada + Ombra) + "px";
		if (Mig <= 2) {
			AmagarElement(this.Ombra["CC"]);
		} else {
			if (Alçada > this.ImgHeight) {
				PosicionarAlçadaElement(this.Ombra["CC"], Mig + Ombra - (OmbraCentre / 2));
				MostrarElement(this.Ombra["CC"]);
			} else {
				PosicionarAlçadaElement(this.Ombra["CC"], 0);
				AmagarElement(this.Ombra["CC"]);
			}
		}
		this.AlçadaAnterior = Alçada;
	}, 
	GestionarAnimacions:function(el) {
		if (el.Animacions.length == 0) return;
		el.Animacions[0].MovimentActual++;
		Info = "Pas: " + el.Animacions[0].MovimentActual;
		var Grau = (Math.PI / el.Animacions[0].Moviments) * el.Animacions[0].MovimentActual;
		Info += "<br>Grau: " + Grau;
		var Factor = Math.abs(Math.cos(Grau));
		Info += "<br>Factor: " + Factor;
		var Alçada = parseInt(el.ImgHeight * Factor);
		var AlçadaBloc = 0;
		var Mig = 0;
		Info += "<br>Alçada: " + Alçada;
		//window.alert("");
		MostrarElement(el.Ombra["CC"]);
		if (el.Animacions[0].Pujar) {
			if (el.Animacions[0].MovimentActual <= (el.Animacions[0].Moviments / 2)) {
				if (el.Animacions[0].MovimentActual == 1) {
					CarregarImatge(el.ImgSuperiorEfecte, el.ObjFulls[el.Fulls[el.Animacions[0].NomFull]].ImgSup.Img.src);
					DimensionarAlçadaElement(el.ImgSuperiorEfecte, 0);
					PosicionarAlçadaElement(el.ImgSuperiorEfecte, el.ImgHeight);
					//MostrarElement(el.ImgSuperiorEfecte);
					CarregarImatge(el.ImgInferiorEfecte, el.ImgInferior.src);
					DimensionarAlçadaElement(el.ImgInferiorEfecte, Alçada);
					MostrarElement(el.ImgInferiorEfecte);
					if (el.ObjFulls[el.Fulls[el.Animacions[0].NomFull]].ImgInf) {
						CarregarImatge(el.ImgInferior, el.ObjFulls[el.Fulls[el.Animacions[0].NomFull]].ImgInf.Img.src);
						DimensionarAlçadaElement(el.ImgInferior, el.ImgHeight);
						DimensionarAlçadaElement(el.BlocInferior, el.ImgHeight)
						MostrarElement(el.Ombra["EV"]);
					} else {
						CarregarImatge(el.ImgInferior, Img_blanc);
						DimensionarAlçadaElement(el.ImgInferior, 0);
						DimensionarAlçadaElement(el.BlocInferior, 0)
					}
				}
				DimensionarAlçadaElement(el.ImgInferiorEfecte, Alçada);
				if (el.ObjFulls[el.Fulls[el.Animacions[0].NomFull]].ImgInf) {
					PosicionarAlçadaElement(el.Ombra["EV"], Ombra + ((el.ObjFulls[el.NumFullActual].ImgSup) ? el.ImgHeight : 0) + Alçada);
				}
				AlçadaBloc = ((el.ObjFulls[el.NumFullActual].ImgSup) ? el.ImgHeight : 0) + ((el.ObjFulls[el.Fulls[el.Animacions[0].NomFull]].ImgInf) ? el.ImgHeight : Alçada);
				if (AlçadaBloc > el.ImgHeight) Mig = el.ImgHeight;
			} else {
				if (!el.Animacions[0].CanviarImatgeEfecte) {
					AmagarElement(el.ImgInferiorEfecte);
					el.Animacions[0].CanviarImatgeEfecte = true;
					MostrarElement(el.ImgSuperiorEfecte);
					if (el.ObjFulls[el.NumFullActual].ImgSup) {
						if (!el.ObjFulls[el.Fulls[el.Animacions[0].NomFull]].ImgInf) MostrarElement(el.Ombra["EV"]);
					} else {
						AmagarElement(el.Ombra["EV"]);
					}
				}
				DimensionarAlçadaElement(el.ImgSuperiorEfecte, Alçada);
				if (el.ObjFulls[el.NumFullActual].ImgSup) {
					PosicionarAlçadaElement(el.ImgSuperiorEfecte, el.ImgHeight - Alçada);
					DimensionarAlçadaElement(el.BlocSuperior, el.ImgHeight);
					PosicionarAlçadaElement(el.Ombra["EV"], Ombra + el.ImgHeight - Alçada);
				} else {
					PosicionarAlçadaElement(el.ImgSuperiorEfecte, 0);
					DimensionarAlçadaElement(el.BlocSuperior, Alçada);
				}
				AlçadaBloc = ((el.ObjFulls[el.NumFullActual].ImgSup) ? el.ImgHeight : Alçada) + ((el.ObjFulls[el.Fulls[el.Animacions[0].NomFull]].ImgInf) ? el.ImgHeight : 0);
				if (AlçadaBloc > el.ImgHeight) Mig = (AlçadaBloc == (2 * el.ImgHeight)) ? el.ImgHeight : Alçada;
				if (el.Animacions[0].MovimentActual == el.Animacions[0].Moviments) {
					CarregarImatge(el.ImgSuperior, el.ImgSuperiorEfecte.src);
					MostrarElement(el.ImgSuperior);
					AmagarElement(el.ImgSuperiorEfecte);
					if (el.ObjFulls[el.NumFullActual].ImgSup) AmagarElement(el.Ombra["EV"]);
				}
			}
			el.PosicionarBlocIOmbra(AlçadaBloc, Mig);
		} else {
			if (el.Animacions[0].MovimentActual <= (el.Animacions[0].Moviments / 2)) {
				if (el.Animacions[0].MovimentActual == 1) {
					CarregarImatge(el.ImgSuperiorEfecte, el.ImgSuperior.src);
					DimensionarAlçadaElement(el.ImgSuperiorEfecte, el.ImgHeight);
					MostrarElement(el.ImgSuperiorEfecte);
					if (el.ObjFulls[el.Fulls[el.Animacions[0].NomFull]].ImgSup) {
						CarregarImatge(el.ImgSuperior, el.ObjFulls[el.Fulls[el.Animacions[0].NomFull]].ImgSup.Img.src);
						MostrarElement(el.Ombra["EV"]);
					} else {
						CarregarImatge(el.ImgSuperior, Img_blanc);
					}
					CarregarImatge(el.ImgInferiorEfecte, el.ObjFulls[el.Fulls[el.Animacions[0].NomFull]].ImgInf.Img.src);
					DimensionarAlçadaElement(el.ImgInferiorEfecte, 0);
					//MostrarElement(el.ImgInferiorEfecte);
				}
				AlçadaBloc = (el.ObjFulls[el.Fulls[el.Animacions[0].NomFull]].ImgSup) ? el.ImgHeight : Alçada;
				if (el.ObjFulls[el.Fulls[el.Animacions[0].NomFull]].ImgSup) {
					PosicionarAlçadaElement(el.ImgSuperiorEfecte, el.ImgHeight -  Alçada);
					PosicionarAlçadaElement(el.Ombra["EV"], Ombra + el.ImgHeight - Alçada);
					DimensionarAlçadaElement(el.BlocSuperior, el.ImgHeight);
					AlçadaBloc = el.ImgHeight;
				} else {
					PosicionarAlçadaElement(el.ImgSuperiorEfecte, 0);
					DimensionarAlçadaElement(el.BlocSuperior, (Alçada == 1) ? 0 : Alçada);
					AlçadaBloc = Alçada;
				}
				DimensionarAlçadaElement(el.ImgSuperiorEfecte, Alçada);
				AlçadaBloc += ((el.ObjFulls[el.NumFullActual].ImgInf) ? el.ImgHeight : 0);
				if (AlçadaBloc > el.ImgHeight) Mig = (AlçadaBloc == (2 * el.ImgHeight)) ? el.ImgHeight : Alçada;
			} else {
				if (!el.Animacions[0].CanviarImatgeEfecte) {
					AmagarElement(el.ImgSuperiorEfecte);
					el.Animacions[0].CanviarImatgeEfecte = true;
					MostrarElement(el.ImgInferiorEfecte);
					if (el.ObjFulls[el.NumFullActual].ImgInf) {
						if (!el.ObjFulls[el.Fulls[el.Animacions[0].NomFull]].ImgSup) MostrarElement(el.Ombra["EV"]);
					} else {
						AmagarElement(el.Ombra["EV"]);
					}
				}
				DimensionarAlçadaElement(el.ImgInferiorEfecte, Alçada);
				if (el.ObjFulls[el.NumFullActual].ImgInf) {
					PosicionarAlçadaElement(el.Ombra["EV"], Ombra + ((el.ObjFulls[el.Fulls[el.Animacions[0].NomFull]].ImgSup) ? el.ImgHeight : 0) + Alçada);
					DimensionarAlçadaElement(el.BlocInferior, el.ImgHeight);
				} else {
					DimensionarAlçadaElement(el.BlocInferior, Alçada);
				}
				AlçadaBloc = ((el.ObjFulls[el.Fulls[el.Animacions[0].NomFull]].ImgSup) ? el.ImgHeight : 0) + ((el.ObjFulls[el.NumFullActual].ImgInf) ? el.ImgHeight : Alçada);
				if (AlçadaBloc > el.ImgHeight) Mig = el.ImgHeight;
				if (el.Animacions[0].MovimentActual == el.Animacions[0].Moviments) {
					CarregarImatge(el.ImgInferior, el.ImgInferiorEfecte.src);
					MostrarElement(el.ImgInferior);
					DimensionarAlçadaElement(el.ImgInferior, el.ImgHeight);
					AmagarElement(el.ImgInferiorEfecte);
					if (el.ObjFulls[el.NumFullActual].ImgInf) AmagarElement(el.Ombra["EV"]);
				}
			}
			el.PosicionarBlocIOmbra(AlçadaBloc, Mig);
		}
		Info += "<br>Canvi efecte: " + el.Animacions[0].CanviarImatgeEfecte;
		//window.alert("");
		if (el.Animacions[0].MovimentActual == el.Animacions[0].Moviments) {
			el.MarcarBoto(el.NomFullActual, false);
			el.NomFullActual = el.Animacions[0].NomFull;
			el.MarcarBoto(el.NomFullActual, true);
			el.NumFullActual = el.Fulls[el.Animacions[0].NomFull];
			Info += "<br>Full: " + el.Animacions[0].NomFull + " (" + el.Fulls[el.Animacions[0].NomFull] + ")";
			el.Animacions.splice(0,1);
			AmagarElement(el.Ombra["CC"]);
			if (el.Animacions.length == 0) el.Interval = window.clearInterval(el.Interval);
		}
		//el.Info.innerHTML = Info;
	},
	Ocultar:function() {
		this.Element.style.visibility = "hidden";
		this.Visible = false;
	}
}

function MostrarElement(el) {el.style.visibility = "visible";}
function AmagarElement(el) {el.style.visibility = "hidden";}
function CarregarImatge(el, src) {el.src = src;}
function DimensionarAlçadaElement(el, Alçada) {el.style.height = Alçada + "px";}
function PosicionarAlçadaElement(el, Alçada) {el.style.top = Alçada + "px";}
function MostrarMissatge(Nom) {window.alert(Nom + ": " + document.getElementById(Nom).offsetTop + ", " + document.getElementById(Nom).clientHeight);}

function ControlClicEsquerre(NomElement) {
	//MostrarMissatge(NomElement);
	Calendari.MostrarInfo();
} 
function ControlClicDret(e) {
	Calendari.MostrarInfo();
	return false;
}

function AmagarEspera() {
	document.getElementById("img_espera").src = "img/pixel.gif";
	//document.getElementById("espera").style.visible = "hidden";
}

function CarregarCalendari() {
	document.body.style.background = "#FFCC80 url('" + Via_img + "fons" + NumAleatori(5) + ".gif') repeat top left";
	Calendari.Crear("Calendari del curs 2009-2010. Serveis i recursos lingüístics");
	Calendari.AfegirFull(2009, 12, "Portada", "#9DB2DA", false, true);
	Calendari.AfegirFull(2009, 8, "Setembre", "#A92329", true, true);
	Calendari.AfegirFull(2009, 9, "Octubre", "#9C552A", true, true);
	Calendari.AfegirFull(2009, 10, "Novembre", "#703543", true, true);
	Calendari.AfegirFull(2009, 11, "Desembre", "#A52E79", true, true);
	Calendari.AfegirFull(2010, 0, "Gener", "#909FBA", true, true);
	Calendari.AfegirFull(2010, 1, "Febrer", "#8ECDCA", true, true);
	Calendari.AfegirFull(2010, 2, "Març", "#E75F98", true, true);
	Calendari.AfegirFull(2010, 3, "Abril", "#E3464D", true, true);
	Calendari.AfegirFull(2010, 4, "Maig", "#39B33F", true, true);
	Calendari.AfegirFull(2010, 5, "Juny", "#A8C923", true, true);
	Calendari.AfegirFull(2010, 6, "Juliol", "#A6CB15", true, true);
	Calendari.AfegirFull(2010, 7, "Agost", "#EE9C00", true, true);
	Calendari.AfegirFull(2010, 12, "Decàleg", "#B3B590", true, true);
	Calendari.AfegirFull(2010, 13, "Contraportada", "#999A9D", true, false);
	//Calendari.CrearBotoneraServei();
	Calendari.CrearBotonera();
	Calendari.CalcularMesActual();
	
	//Calendari.Mostrar("Portada");
	
	Calendari.Mostrar();
	
	//Calendari.AnarAFull();
}

var Calendari = new ObjCalendari("calendari", Marge, Marge, 306, 600);
var CalExtra;

//
//
//

if (!Array.prototype.KeyExists) {
	Array.prototype.KeyExists = function (Key) {
		var Resultat = false;
		for (var Clau in this) {
			if (Key == Clau) {
				Resultat = true;
				break;
			}
		}
		return Resultat;
	}
}
