


var zero_value;



// gestisce maschera ricerca
function submitricerca(task)
{
	document.forms['stayhere'].task.value = task;
	document.forms['stayhere'].content_id.value = document.forms['form_vetrina'].content_id.value;

	try { document.forms['stayhere'].onsubmit(); }
	catch(e){}

	document.forms['stayhere'].submit();
}

//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++;
		}
	}
}

// Over delle immagini <img src=""..>
function attachSwitch(){	
	var images = document.getElementsByTagName('img');
	
	//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 over... associo funzioni di swap img
		if (relAttribute.toLowerCase().match('over')){
			image.onmouseover = function(){
				if(this.className!="active"){
					this.src= this.src.replace('_off', '_on');	
				}
			};
			image.onmouseout = function(){
				if(this.className!="active"){
					this.src= this.src.replace('_on', '_off');	
				}
			};			
		}
		if(image.className == "active") image.src= image.src.replace('_off', '_on');
	}
}

// Over del menu
function startMenu() {
	if (document.getElementById('menu')) 
	{				
		var node;
		var displaymenu;
		
		displaymenu = document.getElementById("menu");
		for (i=0; i<displaymenu.childNodes.length; i++) {
			node = displaymenu.childNodes[i];
			if (node.nodeName=="LI")
			{
				node.onmouseover=function() 
				{
						this.className+=' active';
					
				}
				node.onmouseout=function()
				{
						this.className.replace(' active', '');						
				
				}
			}
		}
	}
}


/************************************************************************************************************************/
//	CALCOLO DELL'ALTEZZA DEL MAIN (INIZIO FUNZIONI)


function mainHeight()
{
	var main;
	var heightTotale;
	
	var head = $('head');
	var container =$('container');
	var colonnaSx = $('colonnaSx');

	var footer=  $('footer');
	
	main = $('main');
		
	var flash =$('flash');
	var briciole = $('briciole');
	var menu_orizzontale = $('menu_orizzontale');
	var contenuto1 =$('contenuto1');
	var contenuto2 =$('contenuto2');
	var contenuto3 =$('contenuto3');
	
	var altezza_contenuto = $('contenuto').offsetHeight;
	
	
	if(contenuto1 && contenuto1.style.display != 'none')
	altezza_contenuto = contenuto1.offsetHeight;
	if(contenuto2 && contenuto2.style.display != 'none')
	altezza_contenuto = contenuto2.offsetHeight;
	if(contenuto3 && contenuto3.style.display != 'none')
	altezza_contenuto = contenuto3.offsetHeight;
	$('contenuto').style.height = altezza_contenuto + 35 + 'px';

	var flash_height =0 ;
	var briciole_height =0;
	var menu_orizzontale_height=0;
	var container_height;
	
	if (flash) flash_height = flash.offsetHeight;
	if (briciole) briciole_height = briciole.offsetHeight;
	if (menu_orizzontale) menu_orizzontale_height = menu_orizzontale.offsetHeight;
	
	//$('infor').hide();


	container_height = flash_height + briciole_height + menu_orizzontale_height +altezza_contenuto + 34;


	var container_altezza = (Math.max(container_height,colonnaSx.offsetHeight));


	
	container.style.height = container_altezza + 'px';


	colonnaSx.style.height = container_altezza + 'px';



		
//	questa quando il layout � a due colonne
	heightTotale = Math.max(colonnaSx.offsetHeight,container.offsetHeight) + head.offsetHeight + footer.offsetHeight;
//	footer.style.top = head.offsetHeight + Math.max(colonnaSx.offsetHeight,container.offsetHeight) + 'px';
	main.style.height = heightTotale + 'px';
}

//	CALCOLO DELL'ALTEZZA DEL MAIN (FINE FUNZIONI)
/***************************************************************************************************************************/

//	Corregge la visualizzazione dei PNG in explorer
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 switchHtml(number)
{
	var htmlareas= new Array('contenuto1','contenuto2','contenuto3');
	var starters= new Array('starter1','starter2','starter3');
	
	for(var i=0;i<htmlareas.length;i++)
	{
		if(htmlareas[i].match(number)) 
		{
			//Effect.Appear(document.getElementById(htmlareas[i]), {duration: 1.0});
			document.getElementById(htmlareas[i]).style.display = 'block';
						
		}
		else
		{
			//Effect.Fade(document.getElementById(htmlareas[i]), {duration: 1.0, afterFinish: mainHeight});	
			document.getElementById(htmlareas[i]).style.display = 'none';

		}
	}	
	
	for(var j=0;j<starters.length;j++)
	{
		if(starters[j].match(number)) 
		{
			document.getElementById(starters[j]).style.display = 'none';
		}
		else
		{
			document.getElementById(starters[j]).style.display = 'block';
		}
		
	}
	
	mainHeight();
	
	return false;
}



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") 
			{
					child.style.top = zero_value+"px";
					
					if(child.className!='active')
					{
						child.style.display = "none";

					}
					else
					{
						child.style.display = "block";
						child.style.left = "195px";						
					}
					
			}
			
			collapseMenu(child);
		}		
	}

}

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++) 
	{
		var nodo_ul = links[i].parentNode.getElementsByTagName("UL")[0];
		if(nodo_ul)		
		{
			
			if(nodo_ul.className=='active')			
			{				
				nodo_ul.style.left= '195px';		
				nodo_ul.style.top= "0px";

				var li_fratello = nodo_ul.parentNode.nextSibling;
				if(navigator.userAgent.match('MSIE'))
				{					
					while (li_fratello)
					{
						li_fratello.style.top = '-2px';
						li_fratello = li_fratello.nextSibling;					
					}
					
				}
			}
			else
			{
				nodo_ul.style.left= '0px';	
				nodo_ul.style.top= zero_value+"px";	
			}
			links[i].onclick = function() 
			{
										
				toggleMenu(this.parentNode.getElementsByTagName("UL")[0], this.href);
				return false;
			}
		
		}	
		
	}
}

function toggleMenu(node, link) 
{
	if (!document.getElementById) return false;
	// Collapse all nodes, and only show clicked node (when clicking top level of menu)
	
	var OBJmenu = $('menu');
	
	
	
	if(OBJmenu.title.match('moving')) return false;
	
	if (node && node.parentNode.parentNode.id == "menu") 
	{
		hideTopLevels();
	}	

	if(node)
	{
		node.style.top= zero_value+"px";	
				
		//node -> UL
								
		var li_fratello = node.parentNode.nextSibling;
		
		
		
		if ((node.style.display == "" || node.style.display == "block")&& node.style.left =='195px' ) 
		{		

			 
			 OBJmenu.title += ' moving';
			 
			 node.parentNode.className = node.parentNode.className.replace('active','');						
			 new Effect.Move(node, { x:  -195, y: 0, duration: 1.00});
			
			// Con sta cosa qua in afterFinish si mette a posto ma solo in "Prodotti" .... perch???
			Effect.Fade(node, {duration: 1.0, afterFinish:rMargin=function()
				{
						OBJmenu.title = OBJmenu.title.replace('moving', '');
				}
			});
			node.className = node.className.replace('active','');
		

			if(navigator.userAgent.match('MSIE'))
			{					
				while (li_fratello)
				{
					li_fratello.style.top = '0px';
					li_fratello = li_fratello.nextSibling;					
				}
				
			}
			
		}
		if (node.style.display == "none" && node.style.left =='0px' ) 
		{						

			OBJmenu.title += ' moving';			
			
			
			if(navigator.userAgent.match('MSIE'))
			{					
				while (li_fratello)
				{
					li_fratello.style.top = '-2px';
					li_fratello = li_fratello.nextSibling;					
				}
				
			}
						
			node.parentNode.className+=" active";
			node.className="active";
			new Effect.Move(node, { x:  195, y: 0, duration: 1.00});
			Effect.Appear(node, {duration: 1.0, afterFinish:free=function(){
			
			OBJmenu.title = OBJmenu.title.replace('moving', '');
			}
			
			
			});									
		}	
	
	}

}



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 == '' || grandchild.style.display =="block") 
					{						
						 new Effect.Move(grandchild, { x:  -195, y: 0, duration: 1.00, afterFinish:my_f2=function()
						 
						 {
						 //node.style.display = 'none';
						 }
						 });
						Effect.Fade(grandchild, {duration: 1.0 });		
								
						child.className = child.className.replace('active','');
					}
				}
			}
		}		
	}
}



function crossingAirpalne()
{
	var aereo = $('aereo');
	var arrayPageSize = getPageSize();
	
	aereo.setStyle(
	{
		'position': 'absolute',
		'left': '-' + aereo.getDimensions().width + 'px',
		'top': (arrayPageSize[3])/2 + 'px',
		'background': '#000000',
		'z-index': '100'
	});
	
	var first_x = ((arrayPageSize[2] - arrayPageSize[2]/2) - aereo.offsetWidth/2);
	new Effect.Move (aereo,{ x:first_x/2, y: (arrayPageSize[3]/2),mode: 'absolute',duration: 2.0, afterFinish: disappear=function()
	{
		new Effect.Move (aereo,{ x:arrayPageSize[2], y: (arrayPageSize[3]/2),mode: 'absolute',duration: 2.0, delay:7.0, afterFinish: hide=function()
		{
			aereo.hide();
		}});
	}});	
}




// getPageSize()
// Returns array with page width(0), height(1) and window width(2), height(3)
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}















// Richiamo delle funzioni precedenti in un unica funzione
function allFunctions() {


	var loading = $('page_loading');		
	var main = $('main');
if(!navigator.userAgent.match('MSIE 7')) main.setStyle({'visibility': 'hidden'});

	if(navigator.userAgent.match('Safari'))
	{
		zero_value = '-31';
	}
	else zero_value = '0';
	
	preloadIMG();
	attachSwitch();
//	startMenu();
	collapseMenu();
	prepareMenu();
	mainHeight();
	if(navigator.userAgent.match('MSIE')) correctPNG();
	


	loading.style.display = 'none';
	if(!navigator.userAgent.match('MSIE 7')) main.setStyle({'visibility': 'visible'});



}



// Richiamo delle funzioni precedenti in un unica funzione
function allFunctions2() {


	var loading = $('page_loading');		
	var main = $('main');
if(!navigator.userAgent.match('MSIE 7')) main.setStyle({'visibility': 'hidden'});

	if(navigator.userAgent.match('Safari'))
	{
		zero_value = '-31';
	}
	else zero_value = '0';
	
	preloadIMG();
	attachSwitch();
//	startMenu();
	collapseMenu();
	prepareMenu();
	mainHeight();
	if(navigator.userAgent.match('MSIE')) correctPNG();
	


	loading.style.display = 'none';
	if(!navigator.userAgent.match('MSIE 7')) main.setStyle({'visibility': 'visible'});
	//crossingAirpalne();

}
