/******************************************************************************************************************/
// TICKER FUNCTIONS
/******************************************************************************************************************/

function TickerRun(i){
	$('.ticker LI').hide();
	$('.ticker LI:eq('+ i +')').fadeIn('slow');
		
	i++;
	if (i == tnum) i = 0;
	TickerTimerId = window.setTimeout('TickerRun('+ i +')', 4000);
}

function TickerInit(){
	tnum = $('.ticker LI').size(); 
	if (tnum > 1) TickerRun(0);
}

/******************************************************************************************************************/
// SLIDE FUNCTIONS
/******************************************************************************************************************/

function SlideRun(i){
	if (i == 0) {
		$('.slide LI:eq('+ i +')').animate({marginTop: '50px', opacity: 0}, 500, function(){
			$('.slide LI').css('marginTop','0px');
			$('.slide LI').animate({opacity: 1}, 500);
		});
	}
	else $('.slide LI:eq('+ i +')').animate({marginTop: '50px', opacity: 0}, 500);
		
	i--;
	if (i < 0) { i = $('.slide LI').size() - 1 };
	SlideTimerId = window.setTimeout('SlideRun('+ i +')', 4000);
}

function SlideInit(){
	snum = $('.slide LI').size();
	if (snum > 1) SlideTimerId = window.setTimeout('SlideRun('+ (snum - 1) +')', 3000);
}

/******************************************************************************************************************/
// ON DOCUMENT LOAD...
/******************************************************************************************************************/

$(function(){
	// various adjustments
	max = 0;
	$('#offers LI').each(function(){
		if ($(this).height() > max) max = $(this).height();
	});
	
	$('#offers LI').height(max);

	// Ticker
	TickerInit();
	
	// Slide
	SlideInit();

	// datepicker
	$('.datepick').datepicker({ 
		showOn: 'both',
		buttonImage: '/wp-content/themes/hotelbernard/images/icon-calendar.gif',
		buttonImageOnly: true,
		monthNames: ['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre'],
		dayNamesMin: ['Do', 'Lu', 'Ma', 'Me', 'Gi', 'Ve', 'Sa'],
		dateFormat: 'dd/mm/yy',
		currentText: 'Oggi'
	});
	
	var frm = $('#frm-booking'), interval;
	if (frm.length > 0) {

		// validation
		frm.validate({
			rules: {
				datefrom: { required: true },
				dateto: { required: true },
				persone: { required: true }
			},
			messages: {
				datefrom: '&uarr; inserire una data',
				dateto: '&uarr; inserire una data',
				persone: '&uarr; inserire il numero di persone'
			}
		});

	}

	var frm2 = $('#form-contatti form'), interval;
	if (frm2.length > 0) {

		frm2.validate({
			rules: {
				nome: { required: true },
				email: {
					required: true,
					email: true
				},
				citta: { required: true },
				messaggio: { required: true }
			},
			messages: {
				nome: '&uarr; campo obbligatorio',
				email: {
					required: '&uarr; campo obbligatorio',
					email: '&uarr; email non valida'
				},
				citta: '&uarr; campo obbligatorio',
				messaggio: '&uarr; campo obbligatorio'
			}
		});

	}
});