// JavaScript Document
function init()
{
	div_effetto = document.getElementById("effetto");
	 if (div_effetto) {
	 links =  div_effetto.getElementsByTagName("a");
	 var attivita = new Array();
	 var nt = "";
	 var c = "";
	 for(i=0;i<links.length;i++)  
	  {  
	   if(/blind/.test(links[i].className) && dir !="prodotti")  
	   {		
	   			j=links[i].getAttribute('id').replace("toggle","");
				attivita[j] = new Fx.Slide('attivita_'+j);$('toggle'+j).addEvent('click', function(e){
				e = new Event(e);				
				h = this.getAttribute('id').replace("toggle","");
				document.getElementById('attivita_'+h).style.display="block";
				attivita[h].toggle();
				if (nt!="") attivita[nt].toggle();
				if (h!=nt){
					nt = h;
				}else{
					nt="";
				}
				e.stop();
				});
				if(/hide/.test($('attivita_'+j).className) && dir != "prodotti") attivita[j].hide();
	   }
	  }
	 }
	 p_list = document.getElementById("product_list");
	 sel = "";
	 if(p_list)
	 {
	  lis =  p_list.getElementsByTagName("a");
	  for(i=0;i<lis.length;i++)  
	  {
	     lis[i].onmouseover = function(){
            attr = this.getAttribute('id').split("_");  
            immg = this.getAttribute('title');  
            showtrail(300,200,'<img src="images/loading.gif" align="absmiddle" />');
            popup(immg);      
        };
	     lis[i].onmouseout = function(){hidetrail();};
	  }
	 }
	 hndl = document.getElementById("handles4");
	 if (hndl && document.getElementsByTagName("span").length>0) {
			var nS4 = new noobSlide({
				box: $('box4'),
				items: $$('#box4 div'),
				size: 850,
				handles: $$('#handles4 span'),
				onWalk: function(currentItem,currentHandle){
					//$('info4').set('html',currentItem.getFirst().innerHTML);
					this.handles.removeClass('active');
					currentHandle.addClass('active');
				}
			});
		}
		
	if($$('.mb').length > 0)//only triggered if 'mb' class found on page
	{
	  if (dir=="pagine")
	  {	var box = {};
	box = new MultiBox('mb', {descClassName: 'multiBoxDesc', useOverlay: false});	 
} else {
		var initMultiBox = new multiBox('mb', {
			descClassName: 'multiBoxDesc',//the class name of the description divs
			path: './Files/',//path to mp3 and flv players
			useOverlay: false,//use a semi-transparent background. default: false;
			maxWidth: 600,//max width (set to false to disable)
			maxHeight: 400,//max height (set to false to disable)
			addDownload: false,//do you want the files to be downloadable?
			pathToDownloadScript: './Scripts/ForceDownload.asp',//if above is true, specify download script
			addRollover: true,//add rollover fade to each multibox link
			addOverlayIcon: false,//adds overlay icons to images within multibox links
			addChain: false,//cycle through all images fading them out then in
			recalcTop: true//subtract the height of controls panel from top position
		});
	};	}
	//se c'è una form assegna inizia la validazione o per i cesti il controllo delle quantita
	var formv = document.getElementsByTagName("form");
	for(i=0;i<formv.length;i++)  
	  {
		  var nome = formv[i].getAttribute('id');
		  if(/valida/.test(formv[i].className))
		  {
			var myFormValidation = new Validate(nome,{
					errorClass: 'red'
				});
		  }
		  
	  }	
	
}

//showtrail
function gettrailobj(idt)
{
	if (document.getElementById) return document.getElementById(idt).style
	else if (document.all) return document.all.trailimagid.style
}

function truebody()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function hidetrail()
{
	document.onmousemove=""
	document.getElementById('tcont').innerHTML=""
	gettrailobj("trailimageid").visibility="hidden"
	gettrailobj("trailimageid").left=-1000
	gettrailobj("trailimageid").top=0
}


function showtrail(width,height,file)
{
	if(navigator.userAgent.toLowerCase().indexOf('opera') == -1 && navigator.userAgent.toLowerCase().indexOf('safari') == -1)
	{
		w=width
		h=height
		
		// followmouse()
	
		gettrailobj("trailimageid").visibility="visible"
		gettrailobj("trailimageid").width=gettrailobj("tcont").width//
		gettrailobj("trailimageid").height=gettrailobj("tcont").height//h+"px"
		document.getElementById('tcont').innerHTML=file
		document.onmousemove=followmouse
	}
}


function followmouse(e)
{

	if(navigator.userAgent.toLowerCase().indexOf('opera') == -1 && navigator.userAgent.toLowerCase().indexOf('safari') == -1)
	{

		var xcoord=-w
		var ycoord=-120

		if (typeof e != "undefined")
		{
			xcoord+=e.pageX
			ycoord+=e.pageY
		}
		else if (typeof window.event !="undefined")
		{
			xcoord+=truebody().scrollLeft+event.clientX
			ycoord+=truebody().scrollTop+event.clientY
		}

		var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
		var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)

		if (xcoord+w+3>docwidth)
		xcoord=xcoord-w-20

		if (ycoord-truebody().scrollTop+h>truebody().clientHeight)
		ycoord=ycoord-h-20;

		gettrailobj("trailimageid").left=xcoord+"px"
		gettrailobj("trailimageid").top=ycoord+"px"

	}

}

function popup(immagine)
{
		if (immagine == "") immagine = "trsp.jpg";
		else immagine = "piccola_"+immagine;
		document.getElementById('tcont').innerHTML = '<img src="../../upload/galleria/'+immagine+'" />'; 
	
}
//end showtrail



if (window.addEventListener)
window.addEventListener("load", init, false)
else if (window.attachEvent)
window.attachEvent("onload", init)
else if (document.getElementById)
window.onload=init

