$(document).ready(function(){	
	
	$('#map').jmap('init', {
	   'mapType':'map',
	   'mapCenter':[42.682435398386204, 12.65625],
	   'mapZoom': 10
   });
	$("#accordion").accordion({
		autoHeight: false
	});
	$('#accordion').bind('accordionchange', function(event, ui) {
		if(ui.newHeader.text() == "dove siamo") 
			$('#map').jmap('CheckResize');
		else if(ui.newHeader.text() == "foto" && document.negozio.foto.value == "si") 
		{
			load_image(document.negozio.id_negozio.value)
		}
	});
	$("#scrollable").scrollable({                           
		interval: 5000,                        
		loop: true,  
		vertical: true,
		size: 2,     
		speed: 400,                        
		onBeforeSeek: function() {             
			this.getItems().fadeTo(300, 0.2);                 
		},                          
		onSeek: function() {             
			this.getItems().fadeTo(300, 1);         
		}     
	});    
	var validator = $("#contatti").validate({
		errorElement: "em",
		errorPlacement: function(error, element) {
			if(element.attr("id") == 'richiesta'){ 
				error.addClass("textarea"); 
			}
			error.insertAfter(element);
		},
		messages: {
			nome: "",
			cognome: "",
			email: "",
			telefono: "",
			fax: "",
			richiesta: ""
		}
	});
	var validator = $("#unisciti").validate({
		errorElement: "em",
		errorPlacement: function(error, element) {
			if(element.attr("id") == 'dati_aggiuntivi'){ 
				error.addClass("textarea"); 
			}
			error.insertAfter(element);
		},
		messages: {
			ragione_sociale: "",
			nome: "",
			cognome: "",
			email: "",
			telefono: "",
			fax: "",
			dati_aggiuntivi: ""
		}
	});
});	
function localizza_negozio(address) {
										  
	$('#map').jmap('SearchAddress', {
		'query': address,
		'returnType': 'getLocations'
	}, function(result, options) {
	
		var valid = Mapifies.SearchCode(result.Status.code);
		if (valid.success) {
			jQuery.each(result.Placemark, function(i, point){
				var customIcon = new GIcon();
				customIcon.image = "images/mapicon.png";
				customIcon.shadow = "images/mapicon_shadow.png";
				customIcon.iconSize = new GSize(12, 20);
				customIcon.shadowSize = new GSize(22, 20);
				customIcon.iconAnchor = new GPoint(6, 20);
				customIcon.infoWindowAnchor = new GPoint(5, 1);

				$('#map').jmap('AddMarker',{
					'pointLatLng':[point.Point.coordinates[1], point.Point.coordinates[0]],
					'centerMap':true,
					'pointIcon': customIcon
				});

			});
		} else {
			alert('Impossibile trovare la posizione specificata');
		}
	});
}
