function submitSearch(order)
{
	if(order)	
	$('search').orderBY.value = order;
//	else	
//	$('search').orderBY.value = 'nome';
	
	$('search').submit();
	return false;
}


var altezza_contenuto_iniziale;


/************************************************************************************************************************/
//	CALCOLO DELL'ALTEZZA DEL MAIN

function mainHeight()
{
	var head = document.getElementById('head');
	var container = document.getElementById('container');
	var colonnaSx = document.getElementById('colonnaSx');
	var footer = document.getElementById('footer');
	var main = document.getElementById('main');
	var contenuto = document.getElementById('contenuto');
	var colonnaDx_float = document.getElementById('colonnaDx_float');
	var colonnaSx = document.getElementById('colonnaSx');
	var percent_a;
	var percent_b;
	var immagine_ajax = $('immagine_ajax');
	
	
	var colonnaDx_height = 0;

	
	if(contenuto)
	{	
		if(colonnaDx_float)
		{
			
			if(immagine_ajax)
			{
				if(immagine_ajax.offsetHeight>colonnaDx_float.offsetHeight)
				{				
					colonnaDx_float.style.height =  immagine_ajax.offsetHeight + 'px';
					colonnaDx_height = immagine_ajax.offsetHeight ;				
				}
				else colonnaDx_height = colonnaDx_float.offsetHeight -1;
			}
			else colonnaDx_height = colonnaDx_float.offsetHeight -1; 

			if(contenuto.offsetHeight < colonnaDx_height)
			{
				contenuto.style.height = colonnaDx_height -54+ 'px'; 
				// 55 = padding-top + padding-bottom di contenuto
			}
			else if(contenuto.offsetHeight > colonnaDx_height)
			{
				colonnaDx_float.style.height = contenuto.offsetHeight  -1 + 'px';  
				// 1 = border-top di colonnaDx_float *//
			}
			
		}		
		if(colonnaSx)
		{		
/*
			alert('iniziale ' + altezza_contenuto_iniziale);
			alert('menu ' + (colonnaSx.offsetHeight - 54));
			alert('contenuto' + contenuto.offsetHeight);
			if(colonnaDx_float)alert('colonnaDX' + colonnaDx_float.offsetHeight);
*/

		 	//contenuto iniziale piu grande menu sx 
		 	
		 	
		 	if(immagine_ajax && colonnaDx_float)
		 	{
				if(colonnaDx_float) percent_b =  (colonnaDx_height) * 100 / colonnaDx_height;		 		

				if (Math.abs(colonnaDx_float.offsetHeight-colonnaDx_height)>4)
				if(colonnaDx_float) new Effect.MYScale(colonnaDx_float, Math.round(percent_b), {scaleX: false, scaleY: true , duration: 0.5});
	
		 		
		 	}		 	
		 	else if (altezza_contenuto_iniziale>(colonnaSx.offsetHeight - 55))
			{

				percent_a =  (altezza_contenuto_iniziale - 55) * 100 / contenuto.offsetHeight;
				

				if(colonnaDx_float) percent_b =  (altezza_contenuto_iniziale-55) * 100 / colonnaDx_height;
/*				
				alert('percent_a ' + percent_a);
				alert('percent_b ' + percent_b);
*/		
				//scalo se contenuto iniziale piu piccolo del contenuto attuale, alla dimensione iniziale		
				if (Math.abs(altezza_contenuto_iniziale-contenuto.offsetHeight)>4)
				{
					new Effect.MYScale(contenuto, Math.round(percent_a), {scaleX: false, scaleY: true, duration: 0.5});
					if(colonnaDx_float) new Effect.MYScale(colonnaDx_float, Math.round(percent_b), {scaleX: false, scaleY: true , duration: 0.5});

				}				
				
				//contenuto.style.height = altezza_contenuto_iniziale + 'px'; /* 55 = padding-top + padding-bottom di contenuto */
				//if(colonnaDx_float) colonnaDx_float.style.height = altezza_contenuto_iniziale + 'px';  /* 1 = border-top di colonnaDx_float */							
			}			
			//contenuto iniziale piu piccolo menu sx
			else			
			{				
				//alert('secondo if');
				


				percent_a =  colonnaSx.offsetHeight* 100 / contenuto.offsetHeight;
				if(colonnaDx_float) percent_b =  colonnaSx.offsetHeight  * 100 / colonnaDx_height;
				
				//alert('percent_a ' + percent_a);
				//alert('percent_b ' + percent_b);				

				//riduci se contenuto inziale piu piccolo del contenuto attuale e menu piu piccolo del contenuto oppure aumento se menu piu grande di contenuto
				if ((altezza_contenuto_iniziale<contenuto.offsetHeight) && ((colonnaSx.offsetHeight - 54)<contenuto.offsetHeight) || ((colonnaSx.offsetHeight - 54)>=contenuto.offsetHeight))
				{				
					new Effect.MYScale(contenuto, Math.round(percent_a), {scaleX: false, scaleY: true, duration: 0.5});
					if(colonnaDx_float) new Effect.MYScale(colonnaDx_float, Math.round(percent_b), {scaleX: false, scaleY: true, duration: 0.5});
		
				}
				
				//contenuto.style.height = colonnaSx.offsetHeight - 55 + 'px'; /* 55 = padding-top + padding-bottom di contenuto */
				//if(colonnaDx_float) colonnaDx_float.style.height = colonnaSx.offsetHeight - 1 + 'px';  /* 1 = border-top di colonnaDx_float */
			}
		}
		
	}
	
	
	if(colonnaSx.offsetHeight == 'undefined') colonnaSx.offsetHeight = 0;
	colonnaSx.style.top = container.style.top = head.offsetHeight + 'px';
	
	var altezza_colonne = Math.max(colonnaSx.offsetHeight,container.offsetHeight);
	heightTotale = altezza_colonne + head.offsetHeight + footer.offsetHeight;
	footer.style.top = head.offsetHeight + altezza_colonne + 'px';
	
	main.style.height = heightTotale + 'px';
	
}

//	FINE CALCOLO DELL'ALTEZZA DEL MAIN
/***************************************************************************************************************************/

function correctPNG() {
	for(var i=0; i<document.images.length; i++){
		var img = document.images[i];
		var imgName = img.src.toUpperCase();
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
			var imgID = (img.id) ? "id='" + img.id + "' " : "";
			var imgClass = (img.className) ? "class='" + img.className + "' " : "";
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
			var imgStyle = "display:inline-block;" + img.style.cssText ;
			if (img.align == "left") imgStyle = "float:left;" + imgStyle;
			if (img.align == "right") imgStyle = "float:right;" + imgStyle;
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;     
			var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + img.src + "\', sizingMethod='crops');\"></span>";
			img.outerHTML = strNewHTML;
			i = i-1;
		}
	}
}


function collapseMenu(node) 
{
	if (!document.getElementById) return false;
	if (!document.getElementById("menu")) return false;
	if (!node) node = document.getElementById("menu");

	if (node.childNodes.length > 0) 
	{

		for (var i=0; i<node.childNodes.length; i++) 
		{
			var child = node.childNodes[i];

			if (child.nodeName == "UL") 
			{

					if(child.className.match('active'))
					{
						child.style.display = "block";
					}
					else
					{
						child.style.display = "none";
					}
			}

			if (child.nodeName == "LI") 
			{
					

					if(child.className.match('noshow'))
					{					
						child.style.display = "none";
						child.parentNode.style.display = 'none';
					}
										
					//se un li non ha figli... non viene visualizzato
					var primo_ul_figlio = child.getElementsByTagName("UL")[0];
					if(!primo_ul_figlio)
					{
						child.style.display = 'none';
					}
					else
					{
					}
					
					
			}
			
			collapseMenu(child);
			
			//per chiudere un ul i cui il sono tutti display none
			if (child.nodeName == "UL")
			{
				var one_block = false;
				var little_child;
				var j;
				
				for(j=0;(j<child.childNodes.length && !one_block);j++)
				{
					little_child = child.childNodes[j];
					if ((little_child.nodeName=="LI") && (little_child.style.display != "none"))
					one_block = true;					
				}				
				if(!one_block) child.style.display ='none';
			}

		}		
	}

}

function prepareMenu() {
	if (!document.getElementById || !document.getElementsByTagName) return false;
	if (!document.getElementById("menu")) return false;

	var links = document.getElementById("menu").getElementsByTagName("a");
	for (var i=0; i<links.length; i++) 
	{		
		links[i].onclick = function() {
			toggleMenu(this.parentNode.getElementsByTagName("UL")[0], this.href);
			return false;
		}
	}
}

function toggleMenu(node, link) 
{	
	//alert(node);
	//alert(link);









	if (!document.getElementById) return false;
	if (!link) return false;

	//apro href nel caso in cui non abbia node (cioe ul figlio)
	if (!node) 
	{
//		alert('caso utile 1');
		location.href = link;
		return false;
	}

	//apro href nel caso in cui non abbia un ul figlio
	if(!node.getElementsByTagName("UL")[0])
	{
		
		
		//location.href = link;
		
		var link_pagina =  node.getElementsByTagName("A")[0];
		if(link_pagina) location.href = link_pagina.href;
		else location.href = link;
		
		
		
		
		return false;
	}	


	// Collapse all nodes, and only show clicked node (when clicking top level of menu)
	if (node.parentNode.parentNode.id == "menu") 
	{
		hideTopLevels();
	}

	if (node.style.display == 'block') 
	{

		//node.style.visibility = 'hidden';
		//mainHeight();		
		/*Effect.BlindUp(node, {duration: 0.6, afterFinish: fine1=function()
		{
			OBJmenu.title = OBJmenu.title.replace('moving', '');
			//node.style.display='none';
			//mainHeight();
		}	
			
		});*/
		node.style.display='none';
		mainHeight();		
		//Effect.BlindUp(node, {duration: 1.0, afterFinish:mainHeight });
	} 
	else 
	{		
		//node.style.visibility = 'hidden';				
		//node.style.display = 'block';	
		//alert(node.offsetHeight);
		//mainHeight();
		//node.style.display = 'none';
		//node.style.visibility = '';				

		/*Effect.BlindDown(node, {duration: 0.6, afterFinish: fine2=function()
		{
			OBJmenu.title = OBJmenu.title.replace('moving', '');
			//node.style.display='inline';
			//mainHeight();
		}
		}); 
		*/
		node.style.display='block';
		mainHeight();
	}
}


function hideTopLevels() {
	if (!document.getElementById) return false;
	if (!(node = document.getElementById("menu"))) return false;	
	
	if (node.childNodes.length > 0) {
		for (var i=0; i<node.childNodes.length; i++) {
			var child = node.childNodes[i];
			for(var j=0; j<child.childNodes.length; j++) {
				var grandchild = child.childNodes[j];
				if (grandchild.nodeName == "UL") {
					if (grandchild.style.display == '') {
						//Effect.BlindUp(grandchild, {duration: 0.6, afterFinish: mainHeight });				
						grandchild.style.display == 'none';
						mainHeight();
					}
				}
			}
		}		
	}
}

function prepareNewsletter()
{
	var newsletter = document.getElementById('newsletter');
	var linguetta = document.getElementById('linguetta');
	
	if (linguetta)
	{
		if($('menu'))
		{
			$('sottomain').style.width = '901px';
			$('sottomain').style.marginLeft= "-450px";
			newsletter.style.left = '731px';
		}
		linguetta.onclick = function(){showSection('linguetta','newsletter')}
	}
}


//***********************************************************************//
function prepareNewsHide()
{
	var news_hide = document.getElementById('news_hide');
	var linguetta = document.getElementById('linguetta_news');
	
	if(linguetta)
	{
		if($('menu'))
		{
			$('sottomain2').style.width = '901px';
			$('sottomain2').style.marginLeft= "-450px";
			news_hide.style.left = '731px';
		}
		
		linguetta.onclick = function(){showSection('linguetta_news','news_hide')}
	}
}

function showSection(linguetta_rif,elemento)
{
	var main = document.getElementById('main');
	var newsletter = document.getElementById(elemento);
	var linguetta = document.getElementById(linguetta_rif);
	var altro_main;
	var altra_linguetta;
	var altra_newsletter;
	if(linguetta_rif=='linguetta') altro_main = 'sottomain2';
	else  altro_main = 'sottomain';
	if(linguetta_rif=='linguetta') altra_linguetta = $('linguetta_news');
	else  altra_linguetta = $('linguetta');	
	
	if(linguetta_rif=='linguetta') altra_newsletter = $('news_hide');
	else  altra_newsletter = $('newsletter');
	var movimento=0;
	

		
		
	if(linguetta.name.match('chiudi') && !linguetta.name.match('muovendo') && (altra_linguetta == undefined || !altra_linguetta.name.match('muovendo')))
	{
		
		//1 aperto --> chiudo 1 e chiudo 2 se chiuso
		//alert('chiudo');
		
		if ($('menu')) Effect.Appear($('colonnaSx'));
		linguetta.name += ' muovendo';

		movimento=-10;
		new Effect.Move(main,{ x: 160, y: 0, duration: 1.00});
		
		//caso senza altra newsletter
		if(altra_linguetta==undefined)
		{
		
		}
		else if(altra_linguetta!=undefined)
		{
			new Effect.Move(altra_newsletter,{ x: 160, y: 0, duration: 1.00,afterFinish: ciao1=function()			
			{

			}
		
			
			});
		}
		new Effect.Move(newsletter,{ x: movimento, y: 0, duration: 1.00, afterFinish: ciao2=function()
		{
			linguetta.name = linguetta.name.replace('muovendo', '');
			linguetta.name = linguetta.name.replace('chiudi', 'apri');
			linguetta.src = linguetta.src.replace('chiudi', 'apri');
						
		}
		});
		
			
	}
	else if(linguetta.name.match('apri') && !linguetta.name.match('muovendo') && (altra_linguetta==undefined || !altra_linguetta.name.match('muovendo')))
	{
		//1 chiuso
		//alert('apri');
		if ($('menu')) Effect.Fade($('colonnaSx'));
		
		linguetta.name += ' muovendo';

		//caso home page
		if(altra_linguetta==undefined)
		{
			movimento=10;
			new Effect.Move(main,{ x: -160, y: 0, duration: 1.00});		
		}
		else if(altra_linguetta.name.match('apri'))
		{
			movimento=10;
			new Effect.Move(main,{ x: -160, y: 0, duration: 1.00});
			new Effect.Move(altra_newsletter,{ x: -160, y: 0, duration: 1.00, afterFinish: ciao3=function()
			{

			}			
			});			
		}
		else
		{
			//alert('casino?');
			//chiudo la 2
			movimento=170;
							
			if(altra_linguetta)
			{
				altra_linguetta.name += ' muovendo';
				new Effect.Move(altra_newsletter,{ x: -170, y: 0, duration: 1.00, afterFinish: ciao4=function()
				{
					
					altra_linguetta.name =  altra_linguetta.name.replace('muovendo', '');
					altra_linguetta.name =  altra_linguetta.name.replace('chiudi', 'apri');
					altra_linguetta.src = altra_linguetta.src.replace('chiudi', 'apri');				
				}			
				});					
			}
		}

		new Effect.Move(newsletter,{ x: movimento, y: 0, duration: 1.00, afterFinish: ciao5 = function()
		{
			linguetta.name =  linguetta.name.replace('muovendo', '');
			linguetta.name =  linguetta.name.replace('apri', 'chiudi');
			linguetta.src = linguetta.src.replace('apri', 'chiudi');			
		}
		});			
		
	}

}


//preload immagini
function preloadIMG(){	
	var images = document.getElementsByTagName('img');
	var immagini=new Array();	
	var cont = 0;
	
	//percorro tutte le immagini		
	for (var i=0; i<images.length; i++){
		var image = images[i];
		var relAttribute = String(image.getAttribute('name'));
	
		//se hanno match preload... associo funzioni di preload
		if (relAttribute.toLowerCase().match('preload')){
			immagini[cont]=new Image();
			immagini[cont].src=image.src;
			cont++;
		}
	}
}



function ajaxImage()
{
	
	var colonna_height;
	var immagine_height;
	var immagine_ajax;
	var contenuto;
	var diff;

	
	var ajax_link = new Array();
	var all_links = document.getElementsByTagName('a');
	var j=0;
	
	if(document.getElementById('immagine_ajax'))
	{
		for(var i=0;i<all_links.length;i++)
		{				
			the_link = all_links[i];		
			if(the_link.rel.match('ajaxImage'))
			{
				if(j == 0) 
				{

					var href=the_link.href;

					imgPreloader = new Image();
	
					// once image is preloaded, resize image container
					imgPreloader.onload=function()					
					{
						
						new Effect.Fade('immagine_ajax', { duration: 0.4, afterFinish: ciao11=function ()
						{																				
							document.getElementById('immagine_ajax').src = href;

							new Effect.Appear('immagine_ajax', { duration: 0.4, from: 0.0, to: 1.0 , afterFinish:ciao222=function ()
							{																																							
								mainHeight();
								
								new Effect.Fade('load_load', {duration: 0.4});
																	
							}													
							});			
						
						}	
						});						
					}

					imgPreloader.src = href;
				
				}
				the_link.onclick = function()
				{
					var href=this.href;									

					new Effect.Fade('immagine_ajax', { duration: 0.5, afterFinish: ciao11=function ()					
					{																																										
						document.getElementById('immagine_ajax').src = 'images/immagine_vuota.gif';
						imgPreloader = new Image();
		
						// once image is preloaded, resize image container
						imgPreloader.onload=function()
						{
							document.getElementById('immagine_ajax').src = href;

							new Effect.Appear('load_load', {duration: 0.4, afterFinish:ciao223=function ()
							{
								new Effect.Appear('immagine_ajax', { duration: 0.4, from: 0.0, to: 1.0 , afterFinish:ciao222=function ()
								{
									mainHeight();
									new Effect.Fade('load_load', {duration: 0.4});
						
								}														
								});
							}
							});			
						}
						imgPreloader.src = href;																						

					}
					});


					return false;
				}
				j++;
			}
		}
	}
	
}


// Over delle immagini
function overImg()
{
	var immagini = new Array;
	var immagine;
	var name;
	
	immagini = document.getElementsByTagName('img');
	for(var i=0;i<immagini.length;i++)
	{
		immagine = immagini[i];
		name = String(immagine.getAttribute('name'));
		if (name.match('over')){
			immagine.onmouseover = function(){
					this.src= this.src.replace('_off', '_on');	
			};
			immagine.onmouseout = function(){
					this.src= this.src.replace('_on', '_off');	
			};			
		}
	}
}



// Richiamo delle funzioni precedenti in un unica funzione
function allFunctions() 
{
	
	var loading = document.getElementById('page_loading');		
	var main = document.getElementById('main');
	var sottomain = document.getElementById('sottomain');
	main.style.visibility="hidden";	
	if(sottomain) sottomain.style.visibility="hidden";
	
	var contenuto = document.getElementById('contenuto');
	var colonnaDx_float = document.getElementById('colonnaDx_float');
	var colonnaSx = document.getElementById('colonnaSx');
	var immagine_ajax = $('immagine_ajax');
	var colonnaDx_height = 0;
	

	
	if (contenuto)
	{
		//altezza_contenuto_iniziale = $('container').offsetHeight;
		
		if(colonnaDx_float)
		{
			
			if(immagine_ajax)
			{
				if(immagine_ajax.offsetHeight>colonnaDx_float.offsetHeight)				
				colonnaDx_height =  immagine_ajax.offsetHeight + 'px';				
				else colonnaDx_height = colonnaDx_float.offsetHeight -1;
			}	
			else colonnaDx_height = colonnaDx_float.offsetHeight -1;
			
			if(contenuto.offsetHeight < colonnaDx_height)
			altezza_contenuto_iniziale = colonnaDx_height +1;
			else if(contenuto.offsetHeight > colonnaDx_height)
			altezza_contenuto_iniziale = contenuto.offsetHeight ;
		}
		else
		altezza_contenuto_iniziale = contenuto.offsetHeight;		
		

	}		
	
	preloadIMG();
	collapseMenu();

	prepareMenu();
	mainHeight();
	ajaxImage();
	overImg();
	if(navigator.userAgent.match('MSIE')) correctPNG();
	prepareNewsletter();
	prepareNewsHide();

	var loading_page = document.getElementById('page_loading');
	loading_page.style.display = 'none';
	main.style.visibility="visible";
	if(sottomain) sottomain.style.visibility="visible";	
}