if (someIssuesFixed == undefined) var someIssuesFixed = false;

Event.observe(window, 'load', function() {
	if (!someIssuesFixed)
	{	
		someIssuesFixed = true;

		// login/register
		if ($$('div.user_logout').length == 0)
		{
			if ($$('li.login').length > 0) $$('li.login')[0].style.display = 'block';
			if ($$('li.registrati').length > 0) $$('li.registrati')[0].style.display = 'block';
		} else {
			if ($$('li.modifica-registrazione').length > 0) $$('li.modifica-registrazione')[0].style.display = 'block';
		}
		
		// home page boxes
		if ($$('li.primo_piano').length > 0 && $('ul_content_0_0') && $('ul_content_0_0').getElementsBySelector('li.dynamic_menu_item').length > 2)
		{
			var height = 0;
			var b = $('ul_content_0_0').getElementsBySelector('li.dynamic_menu_item');
			for (var i = 2; i < b.length; i++)
				if (b[i].getHeight() > height) height = b[i].getHeight();
			for (var i = 2; i < b.length; i++)
			{
				b[i].style.height = height + 'px';
				if (b[i].getHeight() > height) b[i].style.height = (height - (b[i].getHeight() - height)) + 'px';
			}
			
			// same applies for titles here
			if ($$('body#home #liquid_container ul li.box_larivista_home div.titolo').length > 0 &&
				$$('body#home #liquid_container ul li.box_rapporto_annuale_home div.titolo').length > 0)
			{
				height = 0;
				var br = [ $$('body#home #liquid_container ul li.box_larivista_home div.titolo')[0], 
						$$('body#home #liquid_container ul li.box_rapporto_annuale_home div.titolo')[0] ];

	                        for (var i = 0; i < br.length; i++)
	                        	if (br[i].getHeight() > height) height = br[i].getHeight();
		                for (var i = 0; i < br.length; i++)
                		{
                        		br[i].style.height = height + 'px';
                                	if (br[i].getHeight() > height) br[i].style.height = (height - (br[i].getHeight() - height)) + 'px';
                        	}

			}

		}

		//
		if ($$('span.nota_metodologica')[0] != null && $$('span.nota_metodologica')[0].innerHTML.replace(/^\s+/,'').replace(/\s+$/,'') == '')
			$$('span.nota_metodologica')[0].remove();
			
		// S E A R C H   C A P T I O N
		if (navigator.userAgent.indexOf('MSIE') == -1 && $('search_box_menu_top') && $('search_box_menu_top').select('label').length > 0)
		{
			$('search_box_menu_top').select('input[name="search_term"]')[0].style.marginLeft = '10px';
			$('search_box_menu_top').select('label')[0].innerHTML = 'ricerca libera';
			$('search_box_menu_top').select('label')[0].style.visibility = 'visible';
			$('search_box_menu_top').style.backgroundImage = 'none';
		}

		// A R C I P E L A G O   L I N K S   M U S T   O P E N   I N   A   N E W   W I N D O W
		var l = $$('div.arcipelago_list a');
		for (var i = 0; i < l.length; i++)
			l[i].target = '_blank';

		// P R I N T   A N D   S E N D   D I V S 
		if ($$('div.print_send')[0] == null) return; // if the print_send div is not there, exit

		var c = $$('span.landing_label')[0];
		// if (c == null) c = $$('div.comunicati_stampa_title_content')[0]; 
		if (c == null) c = $$('span.comunicati_landing_label')[0];
		// rapporto annuale: if (c == null) c = $$('div.rapporto_annuale_title_content')[0];
                // if (c == null) c = $$('span.rapporto_annuale_landing_label')[0];
		// if (c == null) c = $$('div.pubblicazioni_title_content')[0];
		// if (c == null) c = $$('span.pubblicazioni_landing_label')[0];
		// if (c == null) c = $$('div.ricerche_title_content')[0];
		// if (c == null) c = $$('span.ricerche_landing_label')[0];
		// if (c == null) c = $$('div.larivista_title_content')[0];
		// if (c == null) c = $$('span.censis_label')[0];
		// if (c == null) c = $$('div.arcipelago_title_content')[0];
		// if (c == null) c = $$('div.contatti_title_content')[0];
		// if (c == null) c = $$('span.editoriali_landing_label')[0];
		// if (c == null) c = $$('span.multimedia_landing_label')[0];
		// if (c == null) c = $$('div.contatti_title_content')[0];
		// home-page: if (c == null) c = $$('span.primo_piano_label')[0];
		// if (c == null) c = $$('div.eventi_title_content')[0];
		if (c)
		{
			if ($$('a.addthis_button_email')[0])
				$$('a.addthis_button_email')[0].style.width = '45px';
			if ($$('a.addthis_button_print')[0])
                		$$('a.addthis_button_print')[0].style.width = '60px';

			if ($$('div.print_send')[0])
			{
				var divSend = $$('div.print_send')[0].remove();
 				divSend.style.position = 'absolute';
				divSend.style.right = 0;
				divSend.style.top = '15px';
				divSend.style.width = '150px';
				c.insert( divSend);
			}
			if ($('print_send_container'))
				$('print_send_container').style.display='';
		}

		if ($$('a.addthis_button_email')[0])
			$$('a.addthis_button_email')[0].observe('click', function() { 

				// hide the AddThis logo
				new PeriodicalExecuter( function(p) {
						if ($('at-logo') != null)
						{
							$('at-logo').style.visibility = 'hidden';
							p.stop();
						}
					}, 1);

				// fix a bug with FF3 - the Flash would overlay the e-mail screen	
				if (navigator.userAgent.indexOf('Firefox\/3.0') == -1) return; // ONLY FIREFOX 3.0 FROM THIS POINT ON
				$('myFlashContent').style.visibility = 'hidden';
				new PeriodicalExecuter( function(p) {
						if ($('at16lb').style.display != 'none') return;
						$('myFlashContent').style.visibility = 'visible';
						p.stop();
					} , 1);
			} );
	}
});

new PeriodicalExecuter( function(p) {
                if ($('sbf_anno') != undefined)
		{
			for (var i = $('sbf_anno').childElements().length; i > 1; i--)
                        	$('sbf_anno').insert( $('sbf_anno').childElements()[i-1].remove());
			p.stop();
		}
	}, 1);

