function modifyQuantity(action, form, input)
{
	var el = document.forms[form][input];
	
	if(action == 'add')	{
		el.value++;
	} else {
		if(el.value>2) {
			el.value--;
		} else {
			el.value = 1;
		}
	}
}

//=============================== SCROLL PRODOTTI HOME E OFFERTE
$(document).ready(function(){
	if ($('.prodotti.home li').length > 5) {
		$('.prodotti.home ul li:last').remove().prependTo('.prodotti.home ul');
		$('.prodotti.home ul').css('left','-128px');
	}
	if ($('.prodotti.offerte li').length > 3) {
		$('.prodotti.offerte ul li:last').remove().prependTo('.prodotti.offerte ul');
		$('.prodotti.offerte ul').css('left','-214px');
	}
	
	$('.next').click(function(){
		gallery = $(this).prev('div').children('ul');
		offset = gallery.children('li').outerWidth(true);
		if (!gallery.is(':animated')) {
			gallery.stop(true).animate({'margin-left':'-'+offset},600,function(){
				$('.countDownWrap').countdown('pause');															   	
				var temp = gallery.children('li:first').clone(true);
				gallery.children('li:first').remove();
				temp.appendTo(gallery);
				$('.countDownWrap').countdown('resume');
				gallery.css('margin-left','0px');
			});
		}
	});
	
	$('.prev').click(function(){
		gallery = $(this).next('div').children('ul');
		offset = gallery.children('li').outerWidth(true);
		elemWidth = gallery.children('li').width();
		if (!gallery.children('li:first').is(':animated')) {
			$('.countDownWrap').countdown('pause');
			var ptemp = gallery.children('li:last').css({'width':'0px', 'padding':'0px', 'overflow':'hidden'}).clone(true);
			gallery.children('li:last').css({'width':'0px', 'padding':'0px', 'overflow':'hidden'}).remove();
			ptemp.prependTo(gallery);
			$('.countDownWrap').countdown('resume');
			gallery.children('li:first').stop(true).animate({width:elemWidth, 'paddingLeft':'10px', 'paddingRight':'10px'},600);
		}
	});
	
	if($('.countDownWrap').length > 0) { // init countdown box offerte
		$('.countDownWrap').each(function(index) {
			$(this).fadeOut(0);
			date = $('strong',$(this)).html();			
			expDate = date.split('/');
			fdate = new Date(expDate[2]*1,(expDate[1]*1)-1,expDate[0]*1,23,59,59); 
			$(this).removeClass('noJs');
			$(this).html('');
			$(this).countdown({until: fdate, compact: true, layout:''+ cdText +': <strong>{d<}{dn}{dl} {d>}'+'{hn}{hl} {mn}{ml} {sn}{sl}</strong>'}); 
			$(this).fadeIn(500);

		});
	}
	
	/*$('#catalog').accordion({
		header: 'li[class*=cat] > a',
		collapsible: true,
		event: 'mouseover',
		active: 'li.active a'
	 });*/
	 
	/*var menu = $('#catalog');
	
	// accordion menu
	$('li ul', menu).hide();						// nasconde tutti i menu di secondo livello
	$('li[class*=active] > ul', menu).show();		// mostra i menu attivi
	
	$('li > a', menu).hover(function(){										// quando clicco su un collegamento
		$(this).next().filter(':not(:animated)').slideDown('normal');									// apro il sottomenu corrispondente e...
		$(this).parent().siblings('li').children('ul').filter(':not(:animated)').slideUp('normal');	// ...nascondo gli altri menu
		return false;
	});*/
	// fine accordion menu
});


// FUNZIONI PER LA MAPPA V3
var infowindow,maps;var setDirection={options:{dirContainer:document.getElementById('dirContainer'),dirService:"",dirRenderer:"",myMarker:"",mapId:"",zoom:"",mapType:"",showCursor:""},set:function(mapId,optiones,zoom,mapType,showCursor){setDirection.options.mapId=mapId;setDirection.options.zoom=zoom;setDirection.options.mapType=mapType;setDirection.options.showCursor=showCursor;setDirection.options.myMarker=new Array();for(names in optiones)setDirection.options.myMarker[names]=optiones[names];setDirection.options.myMarker['infowindow']='<div id="ballon"><h5>'+setDirection.options.myMarker['labelTitle']+'</h5>'+setDirection.options.myMarker['infowindow']+'<br /><br />'+setDirection.options.myMarker['labelCalculate']+'<br /><a href="javascript:;" onclick="setDirection.init(\'<h5>'+setDirection.options.myMarker['labelTitle']+'</h5><br />'+setDirection.options.myMarker['labelCalculate']+'\', \''+setDirection.options.myMarker['labelFrom']+'\', \''+setDirection.options.myMarker['labelTo']+'\', \'FROM\', \''+setDirection.options.myMarker['lat']+', '+setDirection.options.myMarker['lon']+'\');" title="'+setDirection.options.myMarker['labelCalculate']+'"><strong>'+setDirection.options.myMarker['labelFrom']+'</strong></a> - <a href="javascript:;" onclick="setDirection.init(\'<h5>'+setDirection.options.myMarker['labelTitle']+'</h5><br />'+setDirection.options.myMarker['labelCalculate']+'\', \''+setDirection.options.myMarker['labelFrom']+'\', \''+setDirection.options.myMarker['labelTo']+'\', \'TO\', \''+setDirection.options.myMarker['lat']+', '+setDirection.options.myMarker['lon']+'\');" title="'+setDirection.options.myMarker['labelCalculate']+'"><strong>'+setDirection.options.myMarker['labelTo']+'</strong></a></div>';setDirection.openMap();},openMap:function(){var latlng=new google.maps.LatLng(setDirection.options.myMarker['lat'],setDirection.options.myMarker['lon']);if(setDirection.options.mapType==undefined)setDirection.options.mapType="ROADMAP";if(setDirection.options.showCursor==undefined)setDirection.options.showCursor=false;var myOptions={disableDefaultUI:setDirection.options.showCursor,mapTypeControl:false,mapTypeControlOptions:{style:google.maps.MapTypeControlStyle.DROPDOWN_MENU},zoom:setDirection.options.zoom,center:latlng,mapTypeId:google.maps.MapTypeId[setDirection.options.mapType]};maps=new google.maps.Map(document.getElementById(setDirection.options.mapId),myOptions);var myLatLng=new google.maps.LatLng(setDirection.options.myMarker['lat'],setDirection.options.myMarker['lon']);var marker=new google.maps.Marker({position:myLatLng,map:maps,icon:setDirection.options.myMarker['icon'],zIndex:10000});if(setDirection.options.myMarker['infowindow']!=""){infowindow=new google.maps.InfoWindow({content:setDirection.options.myMarker['infowindow'],maxWidth:350,position:myLatLng,zIndex:100});infowindow.open(maps,infowindow);google.maps.event.addListener(marker,"click",function(){infowindow.open(maps,infowindow);});}},init:function(myText,from,to,direction,latLan){if(document.getElementById('ballon')){setDirection.options.dirService=new google.maps.DirectionsService();setDirection.options.dirRenderer=new google.maps.DirectionsRenderer();var myFormDirection,textDirection;if(direction=="FROM"){myFormDirection='<form name="direction" action="javascript:;" method="get"><input id="from-input" type="hidden" value="'+latLan+'" />';myFormDirection+='<input id="to-input" type="text" value="" class="inputE" />';myFormDirection+='<input class="inputB" onclick="setDirection.getDirections(document.getElementById(\'from-input\').value, document.getElementById(\'to-input\').value);" type="button" value=">" /></form>';textDirection=myText+'<br /><strong>'+from+'</strong> - <a href="javascript:;" onclick="setDirection.init(\''+myText+'\', \''+from+'\', \''+to+'\', \'TO\', \''+latLan+'\');"><strong>'+to+'</strong></a>'+myFormDirection;}else{myFormDirection='<form name="direction" action="javascript:;" method="get"><input id="from-input" type="text" value="" class="inputE" />';myFormDirection+='<input id="to-input" type="hidden" value="'+latLan+'" />';myFormDirection+='<input class="inputB" onclick="setDirection.getDirections(document.getElementById(\'from-input\').value, document.getElementById(\'to-input\').value);" type="button" value=">" /></form>';textDirection=myText+'<br /><a href="javascript:;" onclick="setDirection.init(\''+myText+'\', \''+from+'\', \''+to+'\', \'FROM\', \''+latLan+'\');"><strong>'+from+'</strong></a> - <strong>'+to+'</strong>'+myFormDirection;}document.getElementById('ballon').innerHTML=textDirection;}},getDirections:function(fromStr,toStr){var dirRequest={origin:fromStr,destination:toStr,travelMode:google.maps.DirectionsTravelMode.DRIVING,unitSystem:google.maps.DirectionsUnitSystem.METRIC,provideRouteAlternatives:true};setDirection.options.dirService.route(dirRequest,setDirection.showDirections);},showDirections:function(dirResult,dirStatus){if(dirStatus!=google.maps.DirectionsStatus.OK){if(typeof(dirStatusErrora)!=undefined){alert(dirStatusError+"\n(Google reports: "+dirStatus+")");}else{alert("The address entered was not found\n(Google reports: "+dirStatus+")");}return;}setDirection.openMap();$('html,body').animate({scrollTop:$('#'+setDirection.options.mapId).offset().top-20},1000);setDirection.options.dirRenderer.setMap(null);setDirection.options.dirRenderer.setMap(maps);$('#dirContainer').html('');setDirection.options.dirRenderer.setPanel(document.getElementById('dirContainer'));setDirection.options.dirRenderer.setDirections(dirResult);}}
// FINE MAPPA
