
	/**
	 *	togglePanel 1.03
	 *	------------------------------------------------------------------------
	 *	Script javascript/DHTML crossbrowser per visualizzare l'animazione
	 *	di apertura a scorrimento di  un layer con effetto di dissolvenza.
	 *
	 *	Copyright (C) 2004 Claudio Procida
	 *	claudio [at] emeraldion [dot] it
	 *
	 *	This program is free software; you can redistribute it and/or modify
	 *	it under the terms of the GNU General Public License as published by
	 *	the Free  Software Foundation;  either version 2  of the License, or
	 *	(at your option) any later version.
	 *
	 *	This program is distributed in the hope that it will be useful,
	 *	but WITHOUT ANY WARRANTY;  without even the implied warranty of
	 *	MERCHANTABILITY  or FITNESS  FOR A PARTICULAR PURPOSE.  See the
	 *	GNU General Public License for more details.
	 *
	 *	You should have received a copy of the GNU General Public License
	 *	along with this program; if not, write to the Free Software
	 *	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
	 *
	 *
	 *
	 *	Changelog
	 *	------------------------------------------------------------------------
	 *	04/02/2005  Aggiunto il supporto per Safari; supporto per fogli di stile
	 *			non attivo in Safari
	 *	07/09/2004	Fissato bug: il container non riacquista le proprietà di
	 *			box al termine delle animazioni
	 *	11/09/2004	Aggiunto il riconoscimento degli stili settati da foglio
	 *			di stile CSS
	 *
	 */

function togglePanel(panelID, buttonObj, linkObj, show)
{
	/**
	 *	Uso:
	 *
	 *	togglePanel('idPannello',
	 *			{ btnID: 'idBottone',
	 *			  btnImgOpen: 'path/to/image.gif',
	 *			  btnImgClosed: 'path/to/image.gif',
	 *			  replaceAtEnd: true },
	 *			{ lnkID: 'idLink',
	 *			  lnkTxtOpen: 'Clicca per chiudere',
	 *			  lnkTxtClosed: 'Clicca per aprire',
	 *			  replaceAtEnd: true },
	 *			true);
	 *
	 */

	var cnt = getObj(panelID),
		 btn = buttonObj && buttonObj.btnID ? getObj(buttonObj.btnID) : null,
		 lnk = linkObj && linkObj.lnkID ? getObj(linkObj.lnkID) : null;

	if (!cnt.offHeight)
	{
		var disp = getStyle(cnt).display == 'none' ? 'none' : 'block';
		cnt.style.display = 'block';
		cnt.offHeight = cnt.offsetHeight;
		cnt.style.display = disp;
		cnt.style.overflow = 'hidden';
		cnt.timeouts = new Array();
		cnt.state = cnt.style.display == 'none' ? 'closed' : 'open';
		cnt.opPercent = cnt.state == 'open' ? 99 : 1;
		if (uA.IE)
			cnt.style.filter = 'alpha(opacity=' + cnt.opPercent + ')';
		else if (uA.Gecko)
			cnt.style.MozOpacity = cnt.opPercent / 100;

		cnt.STEP_INTERVAL = 25;
		cnt.SCROLL_STEPS = 40;
		cnt.SIN_AMPL = 160;
	}

	with (cnt.style)
	{
		if (cnt.state == 'closed' || show) // apertura
		{
			cnt.state = 'open';
			for (var i = 0; i <= cnt.timeouts.length; i++)
			{
				if (cnt.timeouts[i])
				{
					clearTimeout(cnt.timeouts[i]);
				}
			}
			var h = 0,
				ampl = cnt.offHeight - cnt.offsetHeight,
				opAmpl = 100 - cnt.opPercent;
			height = cnt.offsetHeight || '1px';
			display = 'block';
			for (var i = 0; i <= cnt.SCROLL_STEPS; i++)
			{

				if (cnt.timeouts[i])
				{
					clearTimeout(cnt.timeouts[i]);
				}
				h = cnt.offsetHeight + Math.round(ampl * Math.sin((2.0 * Math.PI * i) / cnt.SIN_AMPL));
				h = h == 0 ? 1 : h > cnt.offHeight ? cnt.offHeight : h;
				opPercent = cnt.opPercent + Math.floor(opAmpl * Math.sin((2.0 * Math.PI * i) / cnt.SIN_AMPL));
				opPercent = opPercent > 99 ? 99 : opPercent;
				opStr = uA.IE ? ('style.filter = \'alpha(opacity=' + opPercent + ')\'') : (uA.Gecko ? ('style.MozOpacity = ' + (opPercent / 100)) : 'void(0)');
				cnt.timeouts[i] = setTimeout('with (getObj(\'' + panelID + '\')) { opPercent = ' + opPercent + '; style.height = \'' + h + 'px\'; ' + opStr + '; }', cnt.STEP_INTERVAL * i);
			}
			cnt.timeouts[i] = setTimeout('with (getObj(\'' + panelID + '\')) { style.height = \'\'; offHeight = 0; }', cnt.STEP_INTERVAL * i);
			if (buttonObj)
			{
				btn.src = buttonObj.btnImgOpen;
			}
			if (linkObj)
			{
				lnk.innerHTML = linkObj.lnkTxtOpen;
			}
		}
		else // chiusura
		{
			cnt.state = 'closed';
			for (var i = 0; i <= cnt.timeouts.length; i++)
			{
				if (cnt.timeouts[i])
				{
					clearTimeout(cnt.timeouts[i]);
				}
			}
			var h = 0,
				ampl = cnt.offsetHeight,
				opAmpl = cnt.opPercent;
			for (var i = 0; i < cnt.SCROLL_STEPS; i++)
			{
				h = Math.floor(ampl * Math.sin((2.0 * Math.PI * i) / cnt.SIN_AMPL));
				h = h == 0 ? 1 : h;
				opPercent = opAmpl - Math.round(opAmpl * Math.sin((2.0 * Math.PI * i) / cnt.SIN_AMPL));
				opPercent = opPercent > 99 ? 99 : opPercent;
				opStr = uA.IE ? ('style.filter = \'alpha(opacity=' + opPercent + ')\'') : (uA.Gecko ? ('style.MozOpacity = ' + (opPercent / 100)) : 'void(0)');
				cnt.timeouts[i] = setTimeout('with (getObj(\'' + panelID + '\')) { opPercent = ' + opPercent + '; style.height = \'' + (ampl - h) + 'px\'; ' + opStr + '; }', cnt.STEP_INTERVAL * i);
			}
			opStr = uA.IE ? 'style.filter = \'alpha(opacity=1%)\'' : (uA.Gecko ? 'style.MozOpacity = .01' : 'void(0)');
			cnt.timeouts[i] = setTimeout('with (getObj(\'' + panelID + '\')) { opPercent = 1; style.display = \'none\'; ' + opStr + '; style.height = \'\'; offHeight = 0; }', cnt.STEP_INTERVAL * i);
			if (buttonObj)
			{
				if (buttonObj.replaceAtEnd)
					cnt.timeouts[i + 1] = setTimeout('getObj(\'' + buttonObj.btnID + '\').src = \'' + buttonObj.btnImgClosed + '\'', cnt.STEP_INTERVAL * (i + 1));
				else
					btn.src = buttonObj.btnImgClosed;
			}
			if (linkObj)
			{
				if (linkObj.replaceAtEnd)
					cnt.timeouts[i + 2] = setTimeout('getObj(\'' + linkObj.lnkID + '\').innerHTML = \'' + linkObj.lnkTxtClosed + '\'', cnt.STEP_INTERVAL * (i + 2));
				else
					lnk.innerHTML = linkObj.lnkTxtClosed;
			}
		}
	}
}

function getStyle(obj)
{
	if ('getComputedStyle' in window && !uA.Safari)
		return getComputedStyle(obj, '');
	else if (document.body.currentStyle)
		return obj.currentStyle;
	else
		return obj.style;
}

function getObj(id)
{
	return (document.getElementById ? document.getElementById(id) : document.all[id]);
}

uA = new Object();
uA.IE = navigator.appName.indexOf('Microsoft') != -1;
uA.Gecko = navigator.userAgent.indexOf('Gecko') != -1 && navigator.userAgent.indexOf('Safari') == -1;
uA.Safari = navigator.userAgent.indexOf('Safari') != -1;