var searchCanStart = false;

$(document).ready(function() {
	$('.moreDetailsBg, .moreDetailsLine').click(function(){
		var tr1 = $(this).parent().parent().parent();
		if(tr1.hasClass('resultOpen')) {
			tr1.hide();
			tr1.next().hide();
			tr1.prev().show();
		} else {
			tr1.hide();
			tr1.next().show();
			tr1.next().next().show();
		}
		
		return false;
	});
	
	$('.rateOpen').hover(
			function(){
				$(this).css('background-color', '#e1f4be');
				$(this).next('.optOpen').css('background-color', '#e1f4be');	
				return false;
			},
			function() {
				
				if($(this).hasClass('even3')) {
					$(this).css('background-color', '#ffffff');
					$(this).next('.optOpen').css('background-color', '#ffffff');
				}
				else {
					$(this).css('background-color', '#eef8dc');
					$(this).next('.optOpen').css('background-color', '#eef8dc');	
				}
			}
	);
	
	$('.optOpen').hover(
			function(){
				$(this).css('background-color', '#e1f4be');
				$(this).prev('.rateOpen').css('background-color', '#e1f4be');	
				return false;
			},
			function() {
				
				if($(this).hasClass('even3')) {
					$(this).css('background-color', '#ffffff');
					$(this).prev('.rateOpen').css('background-color', '#ffffff');
				}
				else {
					$(this).css('background-color', '#eef8dc');
					$(this).prev('.rateOpen').css('background-color', '#eef8dc');	
				}
			}
	);


	$('.priceInfo').hover(function() {
	//$('.priceBg').hover(function() {
		$(this).parent().find('.priceTooltip').show();
	}, function() {
		$(this).parent().find('.priceTooltip').hide();
	});
	
});

function startMobileSearch() {
	if(!searchCanStart) {
		return;
	}
	var loading = $('#mobileLoading');
	var inner_offset = $('.mainRight_res').offset();
	var outer_offset = $('.container').offset();
	
	loading.css({
		'position': 'absolute',
		'left': (inner_offset.left - outer_offset.left) + 125,
		'top': inner_offset.top + 150
	});
	
	loading.fadeIn();
}

function uncheckAllProviderFilters() {
	var link = $('#filterCheckLink');
	link.text('Seleziona tutti');
	link.parent().parent().parent().find('input[type=checkbox]:checked').each(function() {
		$('label[for="'+this.id+'"]').trigger('click');
		this.checked = false;
	});
	link[0].onclick = checkAllProviderFilters;
}

function checkAllProviderFilters() { 
	var link = $('#filterCheckLink');
	link.text('Deseleziona tutti');
	//*
	link.parent().parent().parent().find('input[type=checkbox]:not(:checked)').each(function() {
		$('label[for="'+this.id+'"]').trigger('click');
		this.checked = true;
	});
	//*/
	
	link[0].onclick = uncheckAllProviderFilters;
}

function applyFilters() {
	$('#mobileSearchForm').submit();
	startMobileSearch();
}
