/* ------------ HOME MENU ----------------- */

//--------------------------------------------
$(function(){

		xajax_PintaDestacados ();
		
		getValoresIniciales (0);
	
		document.getElementById('marca').value=-1;
	
		document.getElementById('marca').focus();

});

//--------------------------------
function PintaEsquinas() {
	xajax_PintaEsquinasDestacados ();
}
//--------------------------------
function InicializaGaleria() {
	$("div.gallery").scrollable({ 
		next: 'div.next', 
		prev: 'div.prev',
		nextPage: 'div.nextPage',
		prevPage: 'div.prevPage',
		size: 5 
	}).mousewheel();

	if(isIE){
		addRoundedIECorners();
	}else{
		addRoundedCorners();
		
	}
}


/* ---------------- Carga los valores iniciales de la p?gina y a la vuelta del xajax---------------- */
function getValoresIniciales (tipopantalla) {
	
	$("#imagen_carga").hide();	
	$("#menu_1").click(				
		 function (){			   
			   $(this).addClass("buscar_on");
			   $(this).removeClass("buscar_off");
			   $("#menu_2").addClass("anunciar_off");
			   $("#menu_2").removeClass("anunciar_on");			   
			   $("#busc_datos").show();
			   $("#anunc_datos").hide();			  
		   }		   		
	);	
	
	$("#menu_2").click(				
		   function (){			   
			   $(this).addClass("anunciar_on");
			   $(this).removeClass("anunciar_off");
			   $("#menu_1").addClass("buscar_off");
			   $("#menu_1").removeClass("buscar_on");
			   $("#busc_datos").hide();
			   $("#anunc_datos").show();			 
		   }		   		
	);	

	
	escucha_combos();	
	
	// ----------- capas de imagen en los combos
	if (tipopantalla==0) { //oculto modelos y versiones
		$("#mmvId_1").show();
		$("#mmvSelId_1").hide();
		$("#mmvId_2").show();
		$("#mmvSelId_2").hide();
	} else if (tipopantalla==1) { //muestro modelos y oculto versiones
		$("#mmvId_1").hide();
		$("#mmvSelId_1").show();	
		$("#mmvId_2").show();
		$("#mmvSelId_2").hide();
	} else if (tipopantalla==2) { //muestro modelos y versiones
		$("#mmvId_1").hide();
		$("#mmvSelId_1").show();	
		$("#mmvId_2").hide();
		$("#mmvSelId_2").show();
	}	
	
	
	//..........................
	
	//----------------- Sliders
	$("#precioSlider").slider({
		range: true,
		min: Number($("#precio_minimo").val()),
		max: Number($("#precio_maximo").val()),
		step: 500,
		values: [Number($("#rango_precio_minimo").val()),Number($("#rango_precio_maximo").val())],
		slide: function(event, ui) {
			$("#precio_min").val(ui.values[0]);
			$("#precio_max").val(ui.values[1]);
		},
		stop: function(event, ui){
	    	$("#rango_precio_minimo").val(ui.values[0]);
	    	$("#rango_precio_maximo").val(ui.values[1]);
	    	$("#imagen_carga").show();
	    	xajax_actualizaCombos(xajax.getFormValues('buscForm'), 1);
	    }
	});

	$("#precio_min").val($("#precioSlider").slider("values", 0));
	$("#precio_max").val($("#precioSlider").slider("values", 1));

	$("#anoSlider").slider({
		range: true,
		min: Number($("#ano_minimo").val()),
		max: Number($("#ano_maximo").val()),
		values: [Number($("#rango_ano_minimo").val()),Number($("#rango_ano_maximo").val())],
		slide: function(event, ui) {
			$("#ano_min").val(ui.values[0]);
			$("#ano_max").val(ui.values[1]);
		},
		stop: function(event, ui){
	    	$("#rango_ano_minimo").val(ui.values[0]);
	    	$("#rango_ano_maximo").val(ui.values[1]);
	    	$("#imagen_carga").show();
	    	xajax_actualizaCombos(xajax.getFormValues('buscForm'), 2);
	    }
	});
	$("#ano_min").val($("#anoSlider").slider("values", 0));
	$("#ano_max").val($("#anoSlider").slider("values", 1));
	

}

/* ---------------- Cuando un combo cambia su valor llama a la funcion del xajax ---------------- */
function escucha_combos () {

	$("#tipo").change (
		function () {
			$("#marca").val("-1");
			$("#modelo").val("-1");	
			$("#version").val("-1");	
	});
	$("#marca").change (
		function () {
			$("#modelo").val("-1");	
			$("#version").val("-1");
	}) ;
	$("#modelo").change (
			function () {
				$("#version").val("-1");
		}) ;	
	$("#tipo,#marca,#modelo,#version").change(
		function () {
		$("#imagen_carga").show();
		 xajax_actualizaCombos(xajax.getFormValues('buscForm'), 0);
	 });
}

/* -------------------------------- */
function selected_combo(combo, valor) {
	if (valor == '')
		valor = '-1'; // Por si acaso...
	var etiqueta = 'select#' + combo;
	$(etiqueta).val(valor);
}

/* --------------- Gallery Setup ----------------- */




function showCarInfo(id,whatId,total){	
	/*
		1 - show 
		2 - hide
	*/	
	if(whatId == '1'){
		for (var i=1;i<=total;i++)
		{
			document.getElementById('carInfo_'+i).style.display="none";
		}	
		
		document.getElementById('carInfo_'+id).style.display="block";
	}else if(whatId == '2'){
		for (var i=1;i<=total;i++)
		{
			document.getElementById('carInfo_'+i).style.display="none";
		}	
	}	
	return false;
}

function showOfertaInfo(id,whatId,total){	
	/*
		1 - show 
		2 - hide
	*/	
	if(whatId == '1'){
		for (var i=1;i<=total;i++)
		{
			document.getElementById('ofertaInfo_'+i).style.display="block";
		}	
		
		document.getElementById('ofertaInfo_'+id).style.display="none";
	}else if(whatId == '2'){
		for (var i=1;i<=total;i++)
		{
			document.getElementById('ofertaInfo_'+i).style.display="block";
		}	
	}	
	return false;
}


function showNoticiasInfo(id,whatId){	
	/*
		1 - show 
		2 - hide
	*/	
	if(whatId == '1'){
		document.getElementById(id).style.display="block";
	}else if(whatId == '2'){	
		document.getElementById(id).style.display="none";
	}	
	return false;
}

function goToFicha(id)
{
	document.location.href = id;
	return false;
}


function MostrarPublicar() {
	   $("#menu_2").addClass("anunciar_on");
	   $("#menu_2").removeClass("anunciar_off");
	   $("#menu_1").addClass("buscar_off");
	   $("#menu_1").removeClass("buscar_on");
	   $("#busc_datos").hide();
	   $("#anunc_datos").show();
}


function reg_particular(){
	goToFicha("/anuncio.php");
	return false;
}

function reg_profesional(){
	goToFicha("/registro.php");
	return false;
}


