function initgallery() {
	if(jQuery("#gallery").length){

		// Declare variables
		var totalImages = jQuery("#gallery > li").length,
			imageWidth = jQuery("#gallery > li:first").outerWidth(true),
			totalWidth = imageWidth * totalImages,
			visibleImages = Math.round(jQuery("#gallery-wrap").width() / imageWidth),
			visibleWidth = visibleImages * imageWidth,
			stopPosition = (visibleWidth - totalWidth);

		jQuery("#gallery").width(totalWidth);

		jQuery("#gallery-prev").click(function(){
			if(jQuery("#gallery").position().left < 0 && !jQuery("#gallery").is(":animated")){
				jQuery("#gallery").animate({left : "+=" + (imageWidth*3) + "px"},1000);
			}
			return false;
		});

		jQuery("#gallery-next").click(function(){
			if(jQuery("#gallery").position().left > stopPosition && !jQuery("#gallery").is(":animated")) {
				jQuery("#gallery").animate({left : "-=" + (imageWidth*3) + "px"},1000);
			}
			return false;
		});
	}
}
function initcartina(lat,long,titolo,nome) {
	if (lat == 0 || long  == 0) {
		lat = 43.229195113965005;
		long = 12.3046875;
		$("#cartina").gMap({
					mapTypeControl:         true,
					zoomControl:            true,
					panControl:             true,
					scaleControl:           true,
					streetViewControl:      true,
					scrollwheel: 			true,
					latitude: lat,
					longitude: long,
					zoom: 5
		});
	} else {
		$("#cartina").gMap({
					mapTypeControl:         true,
					zoomControl:            true,
					panControl:             true,
					scaleControl:           true,
					streetViewControl:      true,
					scrollwheel: 			true,
					markers: [
						{
							latitude: lat,
							longitude: long,
							html: nome,
							title: titolo,
							popup: false
						}
					],
					icon: {
						image: 'images/gmap_pin.png',
						iconsize: [26, 46],
						iconanchor: [12, 46],
						infowindowanchor: [12, 0]
					},
					zoom: 10
		});
	}
}

function verificanews(lingua) {
		if (document.newsform.nome.value == '' || document.newsform.email.value == '') {
			if (lingua == 1) alert('Si prega di compilare tutti i campi');
			if (lingua == 2) alert('Please, fill in all field');
			return false;
		} else if (!document.newsform.privacy.checked) {
			if (lingua == 1) alert("Per ottenere il servizio, e\' obbligatorio accettare il trattamento dei dati personali");
			if (lingua == 2) alert("You must agree with the privacy policy");
			return false;
		} else {
			return true;
		}	

}
function goform(num) {
	if (num == 1) {
		if(document.ricerca.obj.value == '0' && !document.ricerca.tipo[0].checked && !document.ricerca.tipo[1].checked && document.ricerca.loc.value == '0') {
			alert('Compilare almeno un campo per la ricerca');
			return false;
		} else {
			qs = '';
			if(document.ricerca.obj.value != '0') qs += '&ccat='+document.ricerca.obj.value;
			if(document.ricerca.tipo[0].checked) qs += '&ctype=0';
			if(document.ricerca.tipo[1].checked) qs += '&ctype=1';
			if(document.ricerca.loc.value != '0') qs += '&cloc='+document.ricerca.loc.value;
			document.location.href = 'catalogo.php?type=1'+qs;
			return false;
		}
	} else if (num == 2) {
		if(document.modulo.nome.value == '' || document.modulo.cognome.value == '' || document.modulo.citta.value == '') {
			alert('Si prega di compilare i campi obbligatori');
			return false;
		} else if(document.modulo.telefono.value == '' && document.modulo.mobile.value == '' && document.modulo.fax.value == '' && document.modulo.email.value == '') {
			alert('Si prega di fornire uno tra: telefono, mobile, fax, email');
			return false;
		} else if(!document.modulo.privacy[0].checked && !document.modulo.privacy[1].checked) {
			alert('Senza il consenso sul trattamento dati non sara\' possibile fornire il servizio richiesto');
			return false;
		} else {
			return true;
		}
	}

}
function goform_en(num) {
	if (num == 1) {
		if(document.ricerca.obj.value == '0' && !document.ricerca.tipo[0].checked && !document.ricerca.tipo[1].checked && document.ricerca.loc.value == '0') {
			alert('Please fill in at least one field to search');
			return false;
		} else {
			qs = '';
			if(document.ricerca.obj.value != '0') qs += '&ccat='+document.ricerca.obj.value;
			if(document.ricerca.tipo[0].checked) qs += '&ctype=0';
			if(document.ricerca.tipo[1].checked) qs += '&ctype=1';
			if(document.ricerca.loc.value != '0') qs += '&cloc='+document.ricerca.loc.value;
			document.location.href = 'catalogue.php?type=1'+qs;
			return false;
		}
	} else if (num == 2) {
		if(document.modulo.nome.value == '' || document.modulo.cognome.value == '' || document.modulo.citta.value == '') {
			alert('Please, fill in all mandatory field');
			return false;
		} else if(document.modulo.telefono.value == '' && document.modulo.mobile.value == '' && document.modulo.fax.value == '' && document.modulo.email.value == '') {
			alert('Please provide one of: phone, mobile, fax, email');
			return false;
		} else if(!document.modulo.privacy[0].checked && !document.modulo.privacy[1].checked) {
			alert('Without the agreement of the privacy policy we will not be able to provide the requested service');
			return false;
		} else {
			return true;
		}
	}

}
function sfoglia() {
	w = 900;
	h = 565;
	l = (screen.width - w) / 2;
	t = (screen.height - h) / 2;
	newwindow = window.open('brochure.html','catalogo','width='+w+',height='+h+',top='+t+',left='+l+',status=no,toolbar=no,menubar=no,location=no,directories=no,resizable=yes,scrollbars=no');	
}
