
//****************************************/
//**** Objecte per la transicio en *******/
//**** moviment de un bloc de contingut **/
//****************************************/
function prisma(elkk,ind,dir,T) {
	this.el=elkk;
	this.ElapseRate=10;
	this.ElapsePx=1;
	this.IdTransition;
	this.Transitant=false;
	this.Pos=0;
	this.indexEl;
	this.w="";
	this.dir=dir;
	if(T<0.05){
		T=0.05;
	}
	this.T=Math.round(T*1000);
	this.el.style.marginTop="0px";
	this.el.style.marginLeft="0px";
	this.transitant=true;
	this.Vel=50;
	this.nChilds=0;
	this.classInd=ind;
	this.posIni=0;
	this.standBye=false;
	this.launch=false;
	this.IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;

	// Internet Explorer 7
	this.IE7 = false /*@cc_on || @_jscript_version == 5.7 @*/;

	// > Internet Explorer 7
	this.gteIE7 = false /*@cc_on || @_jscript_version >= 5.7 @*/;

	// Internet Explorer
	this.isMSIE = /*@cc_on!@*/false;

	this.loaded=false;
}
prisma.prototype.StartRotatePrisma = function() {
	var temp="";
	var tempChild="";
	if(this.dir=="vertical"){
		if (this.el.style.height){
			temp=""+this.el.style.height;
		}
		if (this.el.style.pixelHeight){
			temp=""+this.el.style.pixelHeight;
		}
		if (this.el.offsetHeight){
			temp=""+this.el.offsetHeight;
		}
		if (document.defaultView && document.defaultView.getComputedStyle) {
			temp=""+document.defaultView.getComputedStyle(this.el,'').getPropertyValue('height');
		}
	} else {
		if (this.el.style.width){
			temp=""+this.el.style.width;
		}
		if (this.el.style.pixelWidth){
			temp=""+this.el.style.pixelWidth;
		}
		if (this.el.offsetWidth){
			temp=""+this.el.offsetWidth;
		}
		if (document.defaultView && document.defaultView.getComputedStyle) {
			temp=""+document.defaultView.getComputedStyle(this.el,'').getPropertyValue('width');
		}
	}
	if(this.el.childNodes[0]){
		if (this.el.style.width){
			tempChildH=""+this.el.childNodes[0].style.height;
			tempChildW=""+this.el.childNodes[0].style.width;
		}
		if (this.el.style.pixelWidth){
			tempChildH=""+this.el.childNodes[0].style.pixelHeight;
			tempChildW=""+this.el.childNodes[0].style.pixelWidth;
		}
		if (this.el.offsetWidth){
			tempChildH=""+this.el.childNodes[0].offsetHeight;
			tempChildW=""+this.el.childNodes[0].offsetWidth;
		}
		if (document.defaultView && document.defaultView.getComputedStyle) {
			tempChildH=""+document.defaultView.getComputedStyle(this.el.childNodes[0],'').getPropertyValue('height');
			tempChildW=""+document.defaultView.getComputedStyle(this.el.childNodes[0],'').getPropertyValue('width');
		}
		this.nChilds=this.el.childNodes.length;
		// Perque quan arribi a l'ultim doni la sensacio que rota i no que fa un salt al primer un altre cop.
		// <div>A</div><div>B</div><div>C</div><div>A</div>  (Apartir d'aqui ja no es rotara i es tornara al primer element amb un salt)     <div>B</div><div>C</div>
		this.el.innerHTML=this.el.innerHTML+this.el.innerHTML;
		this.indexEl=0;
		tempChildH=tempChildH.split("px");
		tempChildW=tempChildW.split("px");
		if(this.dir=="vertical"){
			this.el.style.width=parseInt(tempChildW[0])+"px";
			this.el.style.height=2*parseInt(tempChildH[0])*(this.nChilds+1)+"px";// Per lo dit abans sobre la rotacio
		} else {
			this.el.style.width=2*parseInt(tempChildW[0])*(this.nChilds+1)+"px";// Per lo dit abans sobre la rotacio
			this.el.style.height=parseInt(tempChildH[0])+"px";
		}
		var temp2=temp.split("px");
		this.w=temp2[0];
		this.Vel=this.T/(this.ElapseRate*(1+(this.w/this.ElapseRate - Math.floor(this.w/this.ElapseRate))));
		this.ElapsePx=Math.floor(this.w/this.ElapseRate);
		this.loaded=true;
		this.PrismaRotation();
	}
};
prisma.prototype.PrismaRotation = function() {
	if(this.loaded){
		if(this.standBye){
			this.transitant=false;
			this.launch=true;
			this.IdTransition=setTimeout("prismaArr"+this.classInd+".PrismaRotation();",parseInt(this.Vel*100,10));
		} else {
			if(this.launch){
				this.launch=false;
				this.IdTransition=setInterval("prismaArr"+this.classInd+".DivTransition()",parseInt(this.Vel,10));
			} else {
				if(this.indexEl>=this.nChilds){
					this.indexEl=0;
					this.el.style.marginTop="0px";
					this.el.style.marginLeft="0px";
				}
				this.indexEl=this.indexEl+1;
				this.posIni=this.indexEl*this.w;
				if(this.IE6){
					this.posIni=Math.floor(this.posIni/2);
				}
				this.transitant=false;
				this.launch=true;
				this.IdTransition=setTimeout("prismaArr"+this.classInd+".PrismaRotation();",parseInt(this.Vel*100,10));
			}
		}
	}
};
prisma.prototype.DivTransition = function() {
	if(this.loaded){
		if(!this.transitant){
			this.pos=this.posIni;
		}
		this.transitant=true;
		if(this.pos==this.posIni){

			if(this.dir=="vertical"){
				marginTxt=this.el.style.marginTop;
				arrMargin=marginTxt.split("px");
				marge=parseInt(arrMargin[0]);
				if(-this.pos>marge){
					if((-marge-this.pos)<this.ElapsePx){
						marginTxt=parseInt(marge+1)+"px";
					} else {
						marginTxt=parseInt(marge+this.ElapsePx)+"px";
					}
				}
				if(-this.pos<marge){
					if((this.pos+marge)<this.ElapsePx){
						this.el.style.marginTop=parseInt(marge-1)+"px";
					} else {
						this.el.style.marginTop=parseInt(marge-this.ElapsePx)+"px";
					}
				}
				if(this.pos==-marge){
					clearInterval(this.IdTransition);
					this.IdTransition=setTimeout("prismaArr"+this.classInd+".PrismaRotation()",parseInt(this.Vel,10));
					this.transitant=false;
				}
			} else {
				marginTxt=this.el.style.marginLeft;
				arrMargin=marginTxt.split("px");
				marge=parseInt(arrMargin[0]);
				if(-this.pos>marge){
					if((-marge-this.pos)<this.ElapsePx){
						marginTxt=parseInt(marge+1)+"px";
					} else {
						marginTxt=parseInt(marge+this.ElapsePx)+"px";
					}
				}
				if(-this.pos<marge){
					if((this.pos+marge)<this.ElapsePx){
						this.el.style.marginLeft=parseInt(marge-1)+"px";
					} else {
						this.el.style.marginLeft=parseInt(marge-this.ElapsePx)+"px";
					}
				}
				if(this.pos==-marge){
					clearInterval(this.IdTransition);
					this.IdTransition=setTimeout("prismaArr"+this.classInd+".PrismaRotation()",parseInt(this.Vel,10));
					this.transitant=false;
				}
			}

		}
	}
};

/********** funciones para parpadeo *****************/
var blink_b1_ind=1;
function startBlink(id){
	var el=document.getElementById(id);
	var arr;
	if(el.getAttribute("rel")){
		arr=el.getAttribute("rel").split("|");
		switch(arr[0]){
			case "b1":
				setInterval("BlinkB1('"+id+"');",arr[1]);
				break;
		}
	} else {
		return -1;
	}
}
function BlinkB1(id,rel){
	var el=document.getElementById(id);
	var arr;
	if(el.getAttribute("rel")){
		arr=el.getAttribute("rel").split("|");
		el.style.color="#"+arr[blink_b1_ind+1];
		blink_b1_ind=blink_b1_ind+1;
		if(blink_b1_ind>=(arr.length-1)){
			blink_b1_ind=1;
		}
	} else {
		return -1;
	}
}
/*********** funcions utilitaries *********************/
function showID(id){
	document.getElementById(id).style.visibility="visible";
}
function hideID(id){
	document.getElementById(id).style.visibility="hidden";
}
/******************************************************/