//Definisci le variabili
var animTime = 200;	var delay = 100;	var t1, t2, t3, t4, t5, t6; 
var t = new Array('t1','t2','t3','t4','t5','t6');

//Slideshow sfondo
jQuery.noConflict();
jQuery(document).ready(function() {
	jQuery('#slideshow').cycle({
		fx: 'fade',	
		speed: 1000,			// speed of the transition 
		continuous: 0,    		// true to start next transition immediately after current one completes 
		timeout: 8000	 		// milliseconds between slide transitions
	});
	
	// Gestisci il menu a scomparsa
	//menu('1');	menu('2');	menu('3');			// Thumb Group 1  - Disabilitato perche ci sono solo prodotti vuoti
	menu(4);	menu(5);	menu(6);	// Thumb Group 2
});

// Gestisce tutte le azioni sul singolo menu
function menu(id){	
	var p = id-1; //x gli array	
	
	// JCarousel lite
	jQuery("#panel"+id+" div.box div.item div.slider").jCarouselLite({ btnNext: "#panel" + id + " div.box div.item span.slider_next", btnPrev: "#panel" + id + " div.box div.item span.slider_prev", visible: 1 });
	jQuery("#panel"+id+" div.label div.slider").jCarouselLite({ btnNext: "#panel" + id + " div.box div.item span.slider_next", btnPrev: "#panel" + id + " div.box div.item span.slider_prev", visible: 1 });
	
	//Mouse Events
	jQuery("#panel"+id).mouseleave(function() { t[p] = setTimeout(function() { jQuery("#panel" + id + " div.box div.item").animate({ top: '-112px' }, animTime);  }, delay); scambia(id,false); });
	jQuery("#panel"+id +" div.label").mouseenter(function() { clearTimeout(t[p]); jQuery("#panel" + id + " div.box div.item").animate({ top: '0px' }, animTime); scambia(id,true); });
	jQuery("#panel"+id +" div.box div.item").mouseenter(function() { clearTimeout(t[p]); jQuery("#panel" + id + " div.box div.item").animate({ top: '0px' }, animTime); scambia(id,true); });
	
	scambia(id,false);
}

//Scambia le labels delle categorie con i titoli scorrevoli
function scambia(id,b){	
	jQuery("#panel"+id+" div.label div.slider").css('display', b ? 'block' : 'none'); 
	jQuery("#panel"+id+" div.label span.sez").css('display', b ? 'none' : 'block'); 	
}

// Gestisce gli slider nelle pagine prodotti	
function scorri(bool,th){
	if(th==null){ th = 4; }
	var inc = 35 * th; // change thumbs number will increase the sliding gap
	var doc = document.getElementById('thumbs');
	var no = doc.getElementsByTagName('a').length;
	var left = parseFloat(jQuery(doc).css('left'), 10);
	
	// calculate values 				
	var a =	((280 - left + inc)  > (35*no) ? (280-(35*no)) : (left - inc))+"px";
	var b =	((left + inc) < 0 ? (left + inc) : 0)+"px";
	
	// apply values in jQuery animate	
	jQuery.noConflict(); jQuery("#thumbs").animate({ left: (bool ? a : b) },750);
} 	
	
//UTILITÀ
// Disabilita la selezione
function noSelect(){ 
	document.onselectstart = function() {return false;} // ie
	document.onmousedown = function() {return false;} // mozilla
	document.oncontextmenu = function() {return false;}
}

// Gallerie
function stand(){	
	path = "images/eventi/fiera";	
	var x  = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15');
	var arr = new Array();	//iter
    for(i = 0 ; i != x.length; i++){ 
		arr.push({
			player: 'img',
			content: path + "/" + x[i] + '.jpg',
			title:'Fiera di Venticano'
		}); 
	}		     
	Shadowbox.open(arr);
}

function meeting(){	
	path = "images/eventi/meeting";	
	var x  = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13');
	var arr = new Array();	//iter
    for(i = 0 ; i != x.length; i++){ 
		arr.push({
			player: 'img',
			content: path + "/" + x[i] + '.jpg',
			title:'Meeting \"Active for a better life\" presso Vigna La Corte '
		}); 
	}		     
	Shadowbox.open(arr);
}

//Verifica form contatti
function verify(form){	
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;	
	if (document.form.nome.value == ""){
		alert('Non hai compilato il campo \"Nome\".');
		return false;
	} else if (document.form.mail.value == ""){
		alert('Non hai compilato il campo \"E-Mail\".');
		return false;
	} else if (!email_reg_exp.test(document.form.mail.value)){
		alert('Controlla che tua e-mail sia corretta');
		return false;
	} else if (document.form.messaggio.value == ""){
		alert('Non hai compilato il campo \"Messaggio\".');
		return false;
	}	return true;
}	