//$(document).ready(
	//function()



function SearchUsedBoatsReady(bt,bn,lf,lt,pf,pt,startWithLoad)
{	
	var currentBoatType = bt;
	var currentBoatTypelabel = bn;
	
	
	var content = $('.BoatsContents');
	var sliders = true;
	var patent = true;
	
	$('a.BoatType2').css({color:"#C2004A"});

	$('a.BoatType').click(
		function()
		{
			var currentType = $(this).attr('boatType');
			$('a.BoatType').css({color:"#004E90"});
			$(this).css({color:"#C2004A"});
			currentBoatType = currentType;
			RefreshFields();
		}
	);
	
	$("#slider-price").slider(
	{
		range: true,
		min: 0,
		max: 300000,
		step: 500,
		values: [pf, pt],
		animate: true,
		slide: function(event, ui)
		{
			RefreshFields();
		}
	}
	);

	$("#slider-lenght").slider(
	{
		range: true,
		min: 3,
		max: 20,
		step: 1,
		values: [lf, lt],
		animate: true,
		slide: function(event, ui)
		{
			RefreshFields();
		}
	}
	);
		
	function ShowLoading()
	{
		var loading = $('#Loading');
		loading.css({display:"none"});
		loading.css({visibility:"visible"}).css({opacity:"1"}).css({display:"block"});
		
		$('.ConfiguratorContainer').css({display:"none"});
	}
		
	function HideLoading()
	{
		content.fadeTo(1000, 1);
		var loading = $('#Loading');
		loading.fadeTo(1000, 0);
	}

	function ProcessAfterLoad()
	{
		HideLoading();
		$('a.BackToSearch').click(
			function()
			{
				$('.ConfiguratorContainer').css({display:"block"});
				$('.SearchBoatsResult').css({display:"none"});
				$('.BoatsContents').css({display:"none"});

				return;
			}
		);
	}
			
	function RefreshFields()
	{
		$("#lenght").html($("#slider-lenght").slider("values", 0) + ' m - ' + $("#slider-lenght").slider("values", 1) + ' m');
		$("#price").html($("#slider-price").slider("values", 0) + ',00 &euro; - ' + $("#slider-price").slider("values", 1) + ',00 &euro;');

		if (currentBoatType == 2)
			currentBoatTypelabel = "Imbarcazioni";
		
		if (currentBoatType == 1)
			currentBoatTypelabel = "Gommoni";
		

		if (currentBoatType == 1 || currentBoatType == 2)
		{
			sliders = true;
			patent = true;
			$('.sliderContainer').css({display:"block"});
			$('.patentContainer').css({display:"block"});
		}
		
		if (currentBoatType == 3)
		{
			currentBoatTypelabel = "Motori";
			sliders = false;
			patent = false;
			$('.sliderContainer').css({display:"none"});
			$('.patentContainer').css({display:"none"});
		}
		
		if (currentBoatType == 4)
		{
			currentBoatTypelabel = "Rimorchi";
			sliders = false;
			patent = true;
			$('.sliderContainer').css({display:"none"});
			$('.patentContainer').css({display:"block"});
			
			
			var cur_label = $('#labelWithPatent');
			
			$('#labelWithPatent').html("Fino a 1500Kg");
			$('#labelWithOutPatent').html("Oltre a 1500Kg");
		}
		else
		{
			$('#labelWithPatent').html("Con Patente");
			$('#labelWithOutPatent').html("Senza Patente");
		}
	}

			
	function LoadBoats()
	{
		$("#lenght").html($("#slider-lenght").slider("values", 0) + ' m - ' + $("#slider-lenght").slider("values", 1) + ' m');
		$("#price").html($("#slider-price").slider("values", 0) + ',00 &euro; - ' + $("#slider-price").slider("values", 1) + ',00 &euro;');
		//$("#type").html($("input[@name='typeRadio']:checked").val());
		
		
		var toload = "/includes/modules/loadUsedBoats.cfm";
		
		
		
		toload += "?type=" + currentBoatTypelabel;//$("input[@name='typeRadio']:checked").val();
		toload += "&type_id=" + currentBoatType;
		//patente
		var with_patent = $('input[name=chcWithPatent]').is(':checked');
		var without_patent = $('input[name=chcWithOutPatent]').is(':checked');
		
		toload += "&withpatent=" + with_patent;
		toload += "&withoutpatent=" + without_patent;

		//usata - miglia zero
		var used_arg = $('input[name=chcUsedBoats]').is(':checked');
		var zeromiles_arg = $('input[name=chcZeroMiles]').is(':checked');

		toload += "&used=" + used_arg;
		toload += "&zeromiles=" + zeromiles_arg;
			
		

		if(sliders)
		{
			toload += "&lenght_from=" + $("#slider-lenght").slider("values", 0);
			toload += "&lenght_to=" + $("#slider-lenght").slider("values", 1);

			toload += "&price_from=" + $("#slider-price").slider("values", 0);
			toload += "&price_to=" + $("#slider-price").slider("values", 1);
		}
		
		ShowLoading();
		content.load(toload, {},ProcessAfterLoad);
	}
			
			
	$('#SearchBoats').click(
	function(event)
	{
		LoadBoats();
	}
	);
			
	//LoadBoats();
	RefreshFields();
	
	
	if (startWithLoad)
	{
		LoadBoats();
	}
	
}
//);


