  /* centra i pop up sullo schermo */
  function centerPopX(popW){ if(!popW) popW=500; return ((screen.availWidth - popW)/2);  }
  function centerPopY(popH){ if(!popH) popH=270; return ((screen.availHeight - popH)/2); }


  function inspect(elm)
  {
    var str = "";
    for (var i in elm){
      str += i + ": " + elm.getAttribute(i) + "; ";
    }
    alert(str);
  }


function TMdd(topOgg,e,oggId)
{

	// trova l'elemento da cui è partito l'evento
	if(e.srcElement) tt = e.srcElement; //ie
	else tt = e.target; // dom

	// non effettua le modifiche se è stato cliccato il link, ma solo la riga con la freccietta
	if(tt.nodeName == 'A' || tt.nodeName == 'DIV' || (tt.nodeName == '#text' && tt.parentNode.nodeName == 'DIV') || (tt.nodeName == 'IMG' && tt.parentNode.nodeName == 'DIV'))
	{
		closeAllSiblings(topOgg);

		// scambia classi a voci con sottomenu
		topOggClassi = topOgg.className.split(' ');

		classNotFound = true;
		var i = 0;
		do
		{
			if(topOggClassi[i] == 'TMOp')
			{
				topOggClassi[i] = 'TMCl';
				classNotFound = false;
				if(tt.nodeName == 'IMG')
				{
					re = /minus\.gif/g;
					tt.src = tt.src.replace(re,'plus.gif');
				}
				//updateTMMenuCookie(oggId,'C')
			}
			else if(topOggClassi[i] == 'TMCl')
			{
				topOggClassi[i] = 'TMOp';
				classNotFound = false;
				if(tt.nodeName == 'IMG')
				{
					re = /plus\.gif/g;
					tt.src = tt.src.replace(re,'minus.gif');
				}
				//updateTMMenuCookie(oggId,'O')
			}
		}while(classNotFound && ++i < topOggClassi.length)
		topOgg.className = topOggClassi.join(' ');


		/* cerca il submenu relativo alla riga cliccata e lo apre/chiude */
		currSibling = topOgg.nextSibling;
		siblingNotFound = true;
		while(siblingNotFound && currSibling != null)
		{
			if(currSibling.className != null)
			{
				siblingNotFound = false;
			}
			else
				currSibling = currSibling.nextSibling;
		}
		if(currSibling != null)
		{
			if(currSibling.style.display != 'none') currSibling.style.display = 'none';
			else currSibling.style.display = 'block';
		}
	}
}

function closeAllSiblings(currOgg)
{
	pn = currOgg.parentNode;
	currChild = null;
	do
	{
		if(currChild==null) currChild = pn.firstChild
		else currChild = currChild.nextSibling;

		if(currChild!=null)
		{
			if(currChild.className=='frEnd_menuSub')
			{
				if(currChild!=currOgg.nextSibling)
				{
					currChild.style.display = 'none';
					a = currChild.previousSibling;
					cn = a.className;
					cn.replace(/TMOp/,'TMCl');
					a.className = cn;
				}
			}
		}

	} while(currChild != null)
}




var RotationImage = function()
{
	this.imgList=new Array();
	this.imgLoaded=new Array();
	this.linkList=new Array();
	this.rotationTimeout=5000;
	this.lastImgIndex=0;
	this.nextImgIndex=1;
	this.imgUrl=PATH2ROOT+'common/images/rotationImages/';
	this.useImgUrl=false;
	this.imgObj=null;
	this.imgId=null;

	this.rotationInterval=null;
}

RotationImage.prototype.preload = function(pos)
{
	this.imgLoaded[pos] = new Image();
	if(this.useImgUrl) this.imgLoaded[pos].src = this.imgList[pos];
	else this.imgLoaded[pos].src = this.imgUrl+this.imgList[pos];
}

RotationImage.prototype.getNext = function()
{
	if(this.imgList.length>1)
	{

		if((this.imgList.length-1) == this.lastImgIndex)
		{
			this.lastImgIndex = 0;
			this.nextImgIndex = 1;
		}
		else
		{
			this.lastImgIndex++;
			if((this.imgList.length-1) == this.nextImgIndex) this.nextImgIndex = 0;
			else this.nextImgIndex++;
		}

		if(this.imgLoaded[this.nextImgIndex] === null)
		{
			this.preload(this.nextImgIndex);
		}

		if(this.useImgUrl) this.show(this.imgList[this.lastImgIndex]);
		else this.show(this.imgUrl+this.imgList[this.lastImgIndex]);
	}
}

RotationImage.prototype.show = function(url,linkData)
{
	if(this.imgObj==null)
	{
		this.imgObj = document.getElementById(this.imgId);
	}
	if(url)
	{

		if(this.linkList.length > 0)
		{
			linkData = this.linkList[this.lastImgIndex];
			imgLink = this.imgObj.parentNode;
			if(linkData[0]!='')
			{
				if(imgLink.nodeName!='A')
				{
					newImgLink = imgLink.insertBefore(document.createElement('A'),this.imgObj);
					newImgLink.appendChild(this.imgObj);
					imgLink = newImgLink;
				}
				imgLink.href = linkData[0];
				if(linkData[1]!='') imgLink.target = linkData[1];
			}
			else
			{
				if(imgLink.nodeName=='A')
				{
					pNode = imgLink.parentNode;
					pNode.appendChild(this.imgObj);
					pNode.removeChild(imgLink);
				}
			}
		}

		//this.imgObj.src = url;


		if(this.imgObj.filters)
		{
			try{
				this.imgObj.style.filter= 'Fade(overlap=1.0,duration=2.0)';
				this.imgObj.filters(0).Apply();
				this.imgObj.src = url;
				this.imgObj.filters(0).Play();
			}
			catch(e)
			{
				this.imgObj.style.filter= 'BlendTrans(duration=2)';
				this.imgObj.filters(0).Apply();
				this.imgObj.src = url;
				this.imgObj.filters(0).Play();
			}
		}
		else
		{
			for(fd=100,ft=10; fd>=0; fd -= 2, ft+=10)
			{
				//window.setTimeout("ri.imgObj.style.opacity = "+(fd/100)+";",ft);
				window.setTimeout("__rc.rList['" + this.imgId + "'].imgObj.style.opacity = "+(fd/100)+";",ft);
			}
			//window.setTimeout("ri.imgObj.src = '" +url+"';",(ft+10));
			window.setTimeout("__rc.rList['" + this.imgId + "'].imgObj.src = '" +url+"';",(ft+10));
			for(fd=0,ft+=20; fd<=100; fd += 2, ft+=10)
			{
				//window.setTimeout("ri.imgObj.style.opacity = "+(fd/100)+";",ft);
				window.setTimeout("__rc.rList['" + this.imgId + "'].imgObj.style.opacity = "+(fd/100)+";",ft);
			}
		}

	}
}




var RotationContainer =
{
	rList:new Array()
}

RotationContainer.addItem = function(ogg)
{
	this.rList[ogg.imgId] = ogg;
}

RotationContainer.init = function()
{
	window.__rc = this;
	for(i in this.rList)
	{
		if(window.attachEvent)
		{
			document.getElementById(this.rList[i].imgId).attachEvent("onmouseover", new Function(" __rc.handleRotation('stop','" + this.rList[i].imgId +"')") );
			document.getElementById(this.rList[i].imgId).attachEvent("onmouseout", new Function(" __rc.handleRotation('continue','" + this.rList[i].imgId +"')") );
		}
		else
		{
			document.getElementById(this.rList[i].imgId).addEventListener("mouseover",new Function(" __rc.handleRotation('stop','" + this.rList[i].imgId +"')"),false );
			document.getElementById(this.rList[i].imgId).addEventListener("mouseout", new Function(" __rc.handleRotation('continue','" + this.rList[i].imgId +"')"),false );
		}
		this.handleRotation("start",this.rList[i].imgId);
	}
}

RotationContainer.handleRotation = function(comando,oggId)
{
	ogg = this.rList[oggId];
	if(comando=="stop")
	{
		window.clearInterval(ogg.rotationInterval);
	}
	else if(comando=="continue")
	{
		if(ogg.imgList.length > 1)
		{
			ogg.preload(ogg.nextImgIndex);
			if(ogg.rotationInterval!==null) window.clearInterval(ogg.rotationInterval);
			window.setTimeout(" __rc.rList['" + oggId + "'].getNext()",300);
			ogg.preload(ogg.nextImgIndex);
			ogg.rotationInterval = window.setInterval(" __rc.rList['" + oggId + "'].getNext()",ogg.rotationTimeout);
		}
	}
	else if(comando=="start")
	{
		if(ogg.imgList.length > 1)
		{
			ogg.preload(ogg.nextImgIndex);

			ogg.rotationInterval = window.setInterval(" __rc.rList['" + oggId + "'].getNext()",ogg.rotationTimeout);
		}
	}
}

var rc = RotationContainer;


if(window.attachEvent) window.attachEvent("onload", function() { rc.init(); } );
else window.addEventListener("load",function() { rc.init(); },false);
