jQuery.extend(jQuery.validator.messages, {
    required: "Questo campo e' obbligatorio.",
    remote: "Si prega di correggere questo campo.",
    email: "Inserire un indirizzo email valido.",
    url: "Inserire un URL valido.",
    date: "Inserire una data valida.",
    dateISO: "Inserire una data valida (ISO).",
    number: "Inserire un numero valido.",
    digits: "Inserire solo cifre.",
    creditcard: "Inserire un numero di carta di credito.",
    equalTo: "Inserire lo stesso valore di nuovo.",
    accept: "Inserire un valore con un'estensione valida.",
    maxlength: jQuery.validator.format("Inserire non piu' di {0} caratteri."),
    minlength: jQuery.validator.format("Inserire non meno di {0} caratteri."),
    rangelength: jQuery.validator.format("Inserire un valore tra {0} e {1} caratteri di lunghezza."),
    range: jQuery.validator.format("Inserire un valore compreso tra {0} e {1}."),
    max: jQuery.validator.format("Inserire un valore inferiore o uguale a {0}."),
    min: jQuery.validator.format("Inserire un valore maggiore o uguale a {0}.")
});
$(function(){
    $("#dialog").dialog({
        autoOpen: false,
        modal: true
    });
    $(".open-dialog").click(function(){
        var url = $(this).attr("rel");
        $("#dialog").dialog({
    		resizable: false,
    		height:140
    	});
        $("#dialog").find(".dialog-container").html('Confermi operazione?');
        $("#dialog").dialog("open");
    });
	// Accordion
	$(".accordion").accordion({ header: "h3" });
	// Tabs
	$('.tabs').tabs();
	// Dialog			
	$('.dialog').dialog({
		autoOpen: false,
		width: 600,
		buttons: {
			"Ok": function() { 
				$(this).dialog("close"); 
			}, 
			"Cancel": function() { 
				$(this).dialog("close"); 
			} 
		}
	});
	// Datepicker
	$('.datepicker').datepicker({
		inline: true, 
        dateFormat: 'dd-mm-yy'
	});
	$(".autocomplete-search-cosa").each(function(){
		var w = $(this).width() + 22; 
		$(this).autocomplete("/ajax/searchAutocompleteCosa.php", {
			width: w,
			selectFirst: false
		});
	});
	$(".autocomplete-search-dove").each(function(){
		var w = $(this).width() + 22; 
		$(this).autocomplete("/ajax/searchAutocompleteDove.php", {
			width: w,
			selectFirst: false
		});
	});
    $('a.scrollTop').click(function(){
        $('html, body').animate({
            scrollTop: 0
        }, 'slow');
        return false
    });
    // FANCYBOX
    $(".fancybox").fancybox({
		'titleShow'		: true,
        'titleFormat'	: formatTitle,
        'titlePosition'	: 'inside',
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
    // TIPSY
    $(".tooltip").tipsy({
        fade: true,
        delayIn: 500, 
        delayOut: 1000
    });
    $(".tooltip.n").tipsy({
        gravity: 'n'
    });
    $(".tooltip.e").tipsy({
        gravity: 'e'
    });
    $(".tooltip.s").tipsy({
        gravity: 's'
    });
    $(".tooltip.w").tipsy({
        gravity: 'w'
    });
    // input[maxlength] length control
    $('input[maxlength]').each(function(){
        var maxchar = $(this).attr("maxlength");
        var id = $(this).attr("id");
        $("#for_"+id).html(maxchar);
        $(this).keyup(function(){
            var id = $(this).attr('id');
            charCounter(id);
        });
    });
    // from validation
    $("form").each(function(){ // per avere piu' form distinti nella stessa pagina
    	$(this).validate();
    });
});
// per farlo funzinare su chrome ed i browser webkit in generale
$(window).load(function(){
	// news in evidenza
    $(".carousel").cycle({ 
	    fx: 'scrollLeft',
	    delay: -500,
	    pager: '.news-pager',
	    pause: 1/*,
	    after: onAfter*/
	});
});
/*
 * per lo scroll delle news in evidenza
 function onAfter(curr, next, opts, fwd) {
	var index = opts.currSlide;
	$('#prev,#prev2,#prev3,#prev4,#prev5')[index == 0 ? 'hide' : 'show']();
	$('#next,#next2,#next3,#next4,#next5')[index == opts.slideCount - 1 ? 'hide' : 'show']();
	//get the height of the current slide
	var $ht = $(this).height();
	//set the container's height to that of the current slide
	$(this).parent().animate({height: $ht});
}*/
// for fancybox
function formatTitle(title, currentArray, currentIndex, currentOpts) {
    return '<div>' + (title && title.length ? '<b>' + title + '</b>' : '' ) + '<br />Immagine ' + (currentIndex + 1) + ' di ' + currentArray.length + '</div>';
}
