//EYEspin_dhtml (c) Petre Stefan
//email: eyecon@eyecon.ro
//website: www.eyecon.ro
//Modified by JavaScriptKit.com for relative positioning of menu
//please leave this copyright notice intact


function SpinMenu(ident)
{	this.ident = ident;
	this.p = 0; /*diametro pił piccolo dell'ellisse del menu*/	
	this.x = 0; /*Posizionamento orizzontale del menu*/ 	
	this.y = 0; /*Posizionamento verticale del menu*/ 
	this.w = 0; /*Larghezza dell'ellisse*/  /*Larghezza degli elementi*/
	this.h = 0; /*Altezza dell'ellisse*/ 
	this.hElem = 0; /*Altezza elementi*/
	this.r = 0; /*Raggio di lontananza dei pulsanti dal centro del menu*/ 
	this.v = 0; /*Velocitą di rotazione*/	
	this.s = 0; /*Inclinazione del menu*/ 
	this.isVertical = 0; /*Posizionamento verticale od orizzontale*/	
	this.a1 = 0; /*Arco del primo pulsante dalla posizione iniziale*/ 
	this.a2 = 0; /*Arco al quale aggiornare la posizione dei pulsanti*/ 
	this.a3 = 0; /*Numero di pulsanti interni al menu*/	
	this.color = '#ff0000'; //Colore testo
	this.colorover = '#ff0000'; //Colore teso onmousover
	this.backgroundcolor = '#B42C2C'; //Colore sfondo
	this.backgroundcolorover = '#B42C2C'; //Colore sfondo onmouseover
	this.bordercolor = '#000000'; //Colore del bordo
	this.fontsize = 12; //Dimensione del font
	this.fontfamily = 'Arial'; //Famiglia font
	this.pas = 0; //Passo per collocare i pulsanti interni

	this.spinmenu = function()
		{	this.p = this.r / this.s;
			this.a1 = this.a2 = (this.isVertical) ? 0 : (Math.PI / 2);
		};

	this.spinmenuitem = function(titolo, link, win)
		{	stropen = " onclick=\"window.open('" + link + "'"
			if(win)
				stropen += ",'" + win + "'";
			else
				stropen += ",'_self'";
			stropen += ")\"";

			document.write("<div id=\"spinmenu" + this.a3 
			+ "\" style='cursor:pointer; cursor:expression(\"hand\"); position:absolute; width:" 
			+ this.w + "px; left:0px; background-color:" + this.backgroundcolor 
			+ ";color:" + this.color + ";border:1px solid " + this.bordercolor + ";font:normal " 
			+ this.fontsize + "px " + this.fontfamily 
			+ ";text-align:center;cursor:hand;z-Index:1000;' onmouseover=\"this.style.color='" 
			+ this.colorover + "';this.style.backgroundColor='" + this.backgroundcolorover 
			+ "'\" onmouseout=\"this.style.color='" + this.color + "';this.style.backgroundColor='" 
			+ this.backgroundcolor + "'\" " + stropen + "><b>" + titolo + "</b></div>");
			this.a3++;
		};

	this.muta = function()
		{	spinobj = document.getElementById("controale");
			for(i=0;i<this.a3;i++)
			{	menuitem = document.getElementById("spinmenu" + i);
				if(this.isVertical)
				{	xi = parseInt(this.r * Math.cos(this.a1 + i*this.pas)) / this.s;
					yi = parseInt(this.r * Math.sin(this.a1 + i*this.pas));
					coeff_prosp = (this.p + xi) / (2*this.p); //Coefficiente di prospettiva del pulsante
					fontsize_new = this.fontsize * coeff_prosp + 2; //Calcolo della nuova dimensione del font
					zindex_new = parseInt(100 * coeff_prosp);
				}else
				{	xi = parseInt(this.r * Math.cos(this.a1+i*this.pas));
					yi = parseInt(this.r* Math.sin(this.a1+i*this.pas))/this.s;
					coeff_prosp = (this.p + yi) / (2*this.p); //Coefficiente di prospettiva del pulsante
					fontsize_new = this.fontsize * coeff_prosp + 2; //Calcolo della nuova dimensione del font
					zindex_new = parseInt(100*coeff_prosp);
				}
				width_new = (this.w - 20) * coeff_prosp + 20;  //Calcolo della larghezza del pulsante in base alla proiezione
				height_new = (this.h - 20) * coeff_prosp + 10; 
				menuitem.style.top = (yi + this.y - height_new / 2) + "px";
				menuitem.style.left = (xi + this.x - width_new / 2) + "px";
				menuitem.style.width = width_new + "px";
				menuitem.style.fontSize = fontsize_new + "px";
				menuitem.style.zIndex = zindex_new;
			}
			spinobj.style.top = this.y + (this.isVertical ? this.r : this.p) + this.h / 2 + 20;
			//spinobj.style.top = this.y - (this.isVertical ? this.r : this.p) + this.h / 2 + 6;
			//spinobj.style.left = this.x - spinobj.offsetWidth / 2;
			spinobj.style.left = this.x - spinobj.style.posWidth / 2;
			if(this.a1 != this.a2)
			{	this.a1 = (this.a1>this.a2)?(this.a1-this.pas/this.v):(this.a1+this.pas/this.v);
				if(Math.abs(this.a1-this.a2)<this.pas/this.v)
					this.a1 = this.a2;
				window.setTimeout(this.ident + ".muta()",10);
			}
		};

	this.spinmenuclose = function()
			{	this.pas = 2 * Math.PI / this.a3;
				this.muta();
			};
}

function getposOffset(what, offsettype)
{	var totaloffset = (offsettype=="left") ? what.offsetLeft : what.offsetTop;
	var parentEl = what.offsetParent;
	while (parentEl!=null)
	{	totaloffset=(offsettype=="left")? (totaloffset + parentEl.offsetLeft) : (totaloffset + parentEl.offsetTop);
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

