$(document).ready(function(){
	 var ajax_load = "<img src='img/loader.gif' width='220' height='19' class='preload' />";  
	 $('#loading').ajaxStart(function() {
        jQuery(this).show();
    });

    $('#loading').ajaxError(function(e, xhr, opts, error) {
        alert('La petición a la página ' + opts.url + ' ha devuelto el siguiente error: ' + xhr.status + ' - ' + error);
    });

    $('#loading').ajaxStop(function() {
        jQuery(this).hide();
    });
	
	$('.ajax').click(function(){  
    id_categoria=this.name; //guardo el nombre de la categoria al clickear
	$('#content2')  
        .html(ajax_load)  
        .load(this.href, 'ajax=true');
		return false;  
	});
	
	$('.ajax2').click(function(){  
	$('#content2')  
        .html(ajax_load)  
        .load(this.href, 'ajax=true');
		return false;  
	});
	
	$('#btnsubmit').click(function(){  
    busq=encodeURI(document.getElementById('busqueda').value);
	//busq=document.getElementById('busqueda').value;
	$('#content2')  
        .html(ajax_load)  
        .load('anuncios.php?busq='+busq+'&idioma='+idioma, 'ajax=true');
		return false;  
	}); 
	
	$('#busqueda').keypress(function(e){  
	tecla = (document.all) ? e.keyCode : e.which;
	if (tecla=="13") {
		 busq=encodeURI(document.getElementById('busqueda').value);
		$('#content2')  
			.html(ajax_load)  
			.load('anuncios.php?busq='+busq+'&idioma='+idioma, 'ajax=true');
			return false;
	}
	}); 
	
	//el nombre de la categoria viene de la variable global id_categoria
	if (location.pathname=="/")					{ $('#content2').load('anuncios.php?idc='+id_categoria+'&idioma=1', 'ajax=true'); }
	if (location.pathname=="/principal_es.php")	{ $('#content2').load('anuncios.php?idc='+id_categoria+'&idioma=1', 'ajax=true'); }
	if (location.pathname=="/principal_en.php")	{ $('#content2').load('anuncios.php?idc='+id_categoria+'&idioma=2', 'ajax=true'); }
	if (location.pathname=="/principal_al.php")	{ $('#content2').load('anuncios.php?idc='+id_categoria+'&idioma=3', 'ajax=true'); }
	
});

