jQuery(document).ready(function()
{
//	"G_bannerRotator" è definita in index.php perché contiene inclusioni php

	jQuery.noConflict(); /* Metto jQuery in compatibilità per evitare problemi con altre librerie JS eventualmente aggiunte */
	jQuery(function()
	{
		var bannerRotator = jQuery('#banner_rotator');
		if ( bannerRotator.length > 0 && G_bannerRotator.shown < G_bannerRotator.shownTot )
		{
			setInterval(function()
			{
				bannerRotator.find('div.banner').fadeOut(G_bannerRotator.animSpeed * 1000, function()
				{
					jQuery(this).remove();
				});
				setTimeout(function()
				{
					bannerRotator.hide();
					G_bannerRotator.idx = G_bannerRotator.idx + G_bannerRotator.shown;
					if (G_bannerRotator.idx >= G_bannerRotator.images.length)
					{
						G_bannerRotator.idx = 0;
					}
					/*document.title = G_bannerRotator.idx+' .. '+G_bannerRotator.shown+' .. '+G_bannerRotator.images.length;*/
					for (var i=G_bannerRotator.idx; i<Math.min(G_bannerRotator.idx+G_bannerRotator.shown,G_bannerRotator.images.length); i++)
					{
						var html = '<div class="banner">';
						if (G_bannerRotator.images[i].href)
						{
							html += '<a href="'+G_bannerRotator.images[i].href+'">';
						}
						html += '<img src="'+G_bannerRotator.images[i].src+'" alt="'+G_bannerRotator.images[i].alt+'" title="'+G_bannerRotator.images[i].alt+'" width="'+G_bannerRotator.images[i].width+'" height="'+G_bannerRotator.images[i].height+'" />';
						if (G_bannerRotator.images[i].href)
						{
							html += '</a>';
						}
						html += '</div>';
						bannerRotator.append(html);
					}
					setTimeout(function()
					{
						bannerRotator.fadeIn(G_bannerRotator.animSpeed * 1000);
					}, 0.5 * 1000);
				}, G_bannerRotator.animSpeed * 1000);
			}, G_bannerRotator.speed * 1000);
		}
	});
});
