T = 0;
PLay = 0;
Aperto = 0;
window.addEvent('domready', function() {			

BtnMen = $$('.BottoneMenu')

$each(BtnMen, function(a, b){
	a.addEvent('mouseover', function(){
		chiudiLay('','');
		clearTimeout(T);
		
		testa= a.getParent('a')
		Islay = testa.get('rel');	
		
		if (Islay != 'noLay') {		  	
		
		$(Islay).addEvent('mouseover', function(){clearTimeout(T);apriLay(a,Islay)});
		
		apriLay(a,Islay);			
		
		}
		else if (a.src.indexOf('_a.jpg') < 0) a.src = a.src.replace('.jpg', '_a.jpg');		  	
	});
	a.addEvent('mouseout', function(){
		testa= a.getParent('a')
		Islay = testa.get('rel');
		if (Islay == 'noLay' && a.id != 'MenuCorrente' ) a.src = a.src.replace('_a.jpg', '.jpg');
		
		if (Islay != 'noLay') {
		$(Islay).addEvent('mouseout', function(){
		clearTimeout(T);
		T = setTimeout('chiudiLay(\'' + a.id + '\',\'' + Islay + '\');', 300);
		});
		}
		clearTimeout(T);
		T = setTimeout('chiudiLay(\''+a.id+'\',\''+Islay+'\');',300);
	});
});


Btnbar = $$('.barraHome')

$each(Btnbar, function(a, b){
	a.addEvent('mouseover', function(){
	if (a.src.indexOf('_a.jpg') < 0) a.src = a.src.replace('.jpg', '_a.jpg');		  	
	});
	a.getParent('a').addEvent('focus', function(){
	if (a.src.indexOf('_a.jpg') < 0) a.src = a.src.replace('.jpg', '_a.jpg');		  	
	});
	a.addEvent('mouseout', function(){		
		 a.src = a.src.replace('_a.jpg', '.jpg');
	
	});
	a.getParent('a').addEvent('blur', function(){		
		 a.src = a.src.replace('_a.jpg', '.jpg');
	
	});
});

 if(Browser.Engine.trident && Browser.Engine.version <= 4){
Btnbar = $$('.PNG')

$each(Btnbar, function(a, b){
 
   var img = a
      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='image');\"></span>" 
         img.outerHTML = strNewHTML
        
      }
});

	}});	
	
	function chiudiLay(a,L){
		
		$('LivAziendaA').setStyle('z-index','2');
		$('LivProdottiA').setStyle('z-index','2');		
		$('LivSoluzioniA').setStyle('z-index','2');
		$('LivAssistenza').setStyle('z-index','2');
		
		if (a != '') {
			r = $(a);	
					
			if (r.id == 'MenuCorrente') 
				r.src = r.src.replace('_b.jpg', '_a.jpg');
			else 
				r.src = r.src.replace('_b.jpg', '.jpg');
		}
		
		if(L != '' && L != 'noLay' )$(L).setStyle('visibility','hidden')
		else{
		BtnMen = $$('.BottoneMenu')
		$each(BtnMen, function(a, b){
		if (a.id == 'MenuCorrente') 
				a.src = a.src.replace('_b.jpg', '_a.jpg');
			else 
				a.src = a.src.replace('_b.jpg', '.jpg');	
			
		});	
		$('LivSoluzioni').setStyle('visibility','hidden')
		$('LivProdotti').setStyle('visibility','hidden')
		$('LivAzienda').setStyle('visibility','hidden')
		$('LivAssistenza').setStyle('visibility','hidden')
		}
	}
function apriLay(a,L){
	
		$('LivAziendaA').setStyle('z-index','-1');
		$('LivProdottiA').setStyle('z-index','-1');		
		$('LivSoluzioniA').setStyle('z-index','-1');
		$('LivAssistenzaA').setStyle('z-index','-1');
		$(L+'A').setStyle('z-index','100');
		
	$(L).setStyle('visibility','visible')
	/*$(L).slide('in');*/
		 clearTimeout(T);
	if (a.src.indexOf('_a.jpg') >= 0) a.src = a.src.replace('_a.jpg', '_b.jpg');
	else if (a.src.indexOf('_b.jpg') < 0)	a.src = a.src.replace('.jpg', '_b.jpg');
}

function RicercaCerca(){

	re = / /gi;
	dStringa = document.FORMcerca.cerca.value;
	dStringa = dStringa.replace(re, "");

	if (dStringa == "" ){
		SqueezeBox.open("js/alert.cfm?Messaggio=Inserire una parola da cercare all'interno del sito", {size: {x: 300, y: 200}});
		return false;
	}
	else document.FORMcerca.submit();	
}
