// JavaScript Document
 $(document).ready(function(){  	
  
 	$("img.rollOver").mouseover(function (){this.src = this.src.replace("_0","_1");});
	$("img.rollOver").mouseout(function (){this.src = this.src.replace("_1","_0");});	
 
 });

function contrai (idLayer) {
	$("#" + idLayer).slideToggle("fast");
}

function submitForm(formName, onSuccess){
	
	var option = { 		   
		dataType : 		'json',			
		success:      onSuccess
	};
	
	$('#' + formName).ajaxForm(option);
	$('#' + formName).submit();
	
}

function contraiTracked (idLayer) {
	if (idLayer!=Opened){
		if (Opened!="") {
			$("#cat" + Opened).slideToggle("fast");
			$("#img" + Opened).hide();
		}
		$("#cat" + idLayer).slideToggle("fast");
		$("#img" + idLayer).show();
		Opened = idLayer;
	}else {
		$("#cat" + idLayer).slideToggle("fast");
		$("#img" + idLayer).hide();
		Opened = "";
	}
}

function setDida (txt, id){
	
	if (id == 0) $("#leftArrow").attr('src','/img/fake.jpg');
	else $("#leftArrow").attr('src','/img/leftGallery.jpg');
	
	if (id == (fotoBig.length -1 )) $("#rightArrow").hide();
	else $("#rightArrow").show();
	
	$("#didascalia").html(txt);
	fotoSelected = id;
	$("#imgBig").fadeOut(500, function(){ 
								$("#imgBig").attr('src','/files/photo/img2/' + fotoBig[id]);								
							});
}

function changeFoto (passo){
	
	toGo  = fotoSelected + passo;
	if (toGo < 0) toGo = (fotoBig.length - 1);
	if (toGo >= fotoBig.length) toGo = 0;
		
	setDida (dida[toGo], toGo);
	
	
}

// Iscrizione alla newsletter

function sendSubscribe (){
	
	var valido = $("#iscritto").valid();
	
	if (valido) {
	
		$('#msgAlert').html("Wait please ...");
		$('#msgAlert').fadeIn();
		submitForm ('iscritto', onSendedIscrizione);
	
	}
	
}

function onSendedIscrizione(responseText, statusText){
	
		$('#iscritto').resetForm();
		$('#msgAlert').html(responseText.msg);
		c = setInterval(function() { $('#msgAlert').fadeOut(); clearInterval(c);}, 1500);

}
