// Rogaska javascript code


$(document).ready(function(){

	// Accordion for Services
	$('.service-title + div, .service-title + p').hide();
	$('.service-title + div, .service-title + p').addClass('details');
	$('.service-title .actual').show();
	$('#services .service-title').click(function(event) {
		if ( $(this).next('.details').is('.actual') ) {
			$('.service-title').removeClass('actual');
			$('.details').removeClass('actual');
			$(this).next('.details').slideUp('fast');
		} else {
			$('.details').slideUp('fast');
			$('.service-title').removeClass('actual');
			$('.details').removeClass('actual');
			$(this).addClass('actual');
			$(this).next().addClass('actual');
			$(this).next().slideDown('fast');
		};
	});

	$('html body #controls-wrapper').appendTo("#slideshow-control");
	
	// Menu Animation
	$('#menu-site li').hover(function() {
		$(this).find('a').stop().animate({ top: 0 }, 200 );
		}, function() {
		$(this).find('a').stop().animate({ top: -22 }, 200 );
	});

	// Hotel Menu Animation
	$('#menu-hotels li').not('.prenota-online,.menu-offers').hover(function() {
		$(this).find('a').stop().animate({ width: 200 }, 150 )
			.animate({ width: 226 }, 150 );
		}, function() {
		$(this).find('a').stop().animate({ width: 226 }, 150 );
	});
	
	
	// Javascript validation of Contact Choice
	
	// First, change the field on click
	$('#phone-number').hide();
	$('#email input').addClass('requerido');
	$('input[value="Telefono"]').click(function(event) {
		$('#phone-number').show();
		$('#email').hide();
		$('#phone-number input').addClass('requerido');
		$('#email input').removeClass('requerido');
	});
	$('input[value="Email"]').click(function(event) {
		$('#email').show();
		$('#phone-number').hide();
		$('#email input').addClass('requerido');
		$('#phone-number input').removeClass('requerido');
	});
	
	/* Works, but still not sure if useful
	$('input.requerido').blur(function() {
		if( !$(this).val() ) {
			$(this).parents('p').prepend('<span class="form-tip">Compila tutti i campi richiesti. Grazie</span>');
			$(this).focus();
		};
	});
	*/
	
	// Validate the required field on submit
	/* DOESNT WORK DUE TO CONFLICT WITH PLUGIN JS (attempting blur instead -above-)
	$('input.wpcf7-submit').submit(function(event) {
		event.preventDefault();
		alert('form submitted');
		var self = this;
		//if ( !$('input[value="Telefono"]:checked').val() ) {
		// alert('Telefono is not checked');
		//} else {
		// alert('Telefono is checked');
		//};
		if( !$('input.requerido').val() ) {
			//$('input.requerido').parents('p').prepend('<span class="form-tip">Compila tutti i campi richiesti. Grazie</span>');
			//$('input.requerido').focus();
		} else {
		self.submit();
		}
	});
	*/

	// Load Tweet Button Script
	var e = document.createElement('script');
	e.type="text/javascript"; e.async = true;
	e.src = 'http://platform.twitter.com/widgets.js';
	document.getElementsByTagName('head')[0].appendChild(e);

	// Load Plus One Button
	var e = document.createElement('script');
	e.type="text/javascript"; e.async = true;
	e.src = 'https://apis.google.com/js/plusone.js';
	document.getElementsByTagName('head')[0].appendChild(e);
	
	//Tabs in Ospitalita
	$('.tabbed-content').hide();
	$('.default-tab').show();
	$('#menu-ospitalita li a').click(function (event) {
		event.preventDefault();
		var target = $(this).attr('href');
		$(this).parent().siblings().removeClass('selected');
		$(this).parent().addClass('selected'); 
		$(target).siblings('.tabbed-content').hide();
		$(target).show();
    });


	//Applying jQuery Cycle to offers
	$('.oferte').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		speed: '600',
		timeout:  '5000' 
	});
	
	$('.offer-banners-container').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		speed: '600',
		timeout:  '5000' 
	});
	
	// --- Hotel Galleries in Ospitalita ---
	
	// applying jQuery Cycle to thumbs container
	$('#hotel1 .hotel-gallery ul').cycle({ 
		fx:     'scrollHorz', 
		speed:  '300', 
		timeout: 0, 
		next:   '#next1', 
		prev:   '#prev1' 
	});
	
	$('#hotel2 .hotel-gallery ul').cycle({ 
		fx:     'scrollHorz', 
		speed:  '300', 
		timeout: 0, 
		next:   '#next2', 
		prev:   '#prev2' 
	});
	
	$('#hotel3 .hotel-gallery ul').cycle({ 
		fx:     'scrollHorz', 
		speed:  '300', 
		timeout: 0, 
		next:   '#next3', 
		prev:   '#prev3' 
	});
	
	$('.home .hotel-gallery ul').cycle({ 
		fx:     'scrollHorz', 
		speed:  '300', 
		timeout: 0, 
		next:   '#next4', 
		prev:   '#prev4' 
	});
	
	// animating prev and next in thumbs gallery
	$('.hotel-gallery a.previous').css({'left' : '-30px', 'opacity' : '0'});
	$('.hotel-gallery a.next').css({'right' : '-30px', 'opacity' : '0'});
	$('.hotel-gallery').hover(
		function () {
			$('.hotel-gallery a.previous').animate({
				left: '0',
				opacity: 1,
			}, 100, function() {
			// Animation complete.
			});
			$('.hotel-gallery a.next').animate({
				right: '0',
				opacity: 1,
			}, 100, function() {
			// Animation complete.
			});
		}, 
		function () {
			$('.hotel-gallery a.previous').animate({
				left: '-30px',
				opacity: 0,
			}, 200, function() {
			// Animation complete.
			});
			$('.hotel-gallery a.next').animate({
				right: '-30px',
				opacity: 0,
			}, 200, function() {
			// Animation complete.
			});
		}
	);

	
	// Applying  jQuery Colorbox to gallery links
	$('a[rel="gallery-donat"]').colorbox({transition:"fade", maxHeight:"85%", current:"{current} / {total}"});
	$('a[rel="gallery-rogaska"]').colorbox({transition:"fade", maxHeight:"85%", current:"{current} / {total}"});
	$('a[rel="gallery-sava"]').colorbox({transition:"fade", maxHeight:"85%", current:"{current} / {total}"});
	$('a[rel="gallery-home"]').colorbox({transition:"fade", maxHeight:"85%", current:"{current} / {total}"});
	
	// Applying jQueryUI datePicker to date inputs
	$('#check-in-date').datepicker({
		showOn: "both",
		buttonImage: 'http://www.rogaska.com/terme-spa/wp-content/themes/rogaska/img/calendar.png',
		buttonImageOnly: true,
		minDate: '0',
		maxDate: '+6M',
		onSelect: function(dateStr) {
			var min = $(this).datepicker('getDate'); // Get selected date
			$('#check-out-date').datepicker('option', 'minDate', min || '0'); // Set other min, default to today
		}
	});
	$('#check-out-date').datepicker({
		showOn: "both",
		buttonImage: 'http://www.rogaska.com/terme-spa/wp-content/themes/rogaska/img/calendar.png',
		buttonImageOnly: true,
		minDate: '0',
		maxDate: '+6M',
		onSelect: function(dateStr) {
			var max = $(this).datepicker('getDate'); // Get selected date
			$('#check-in-date').datepicker('option', 'maxDate', max || '+1Y+6M'); // Set other max, default to +18 months
		}
	});
	
	
	






});
