$(function(){
	
	//vemos a donde va el focus
	$('.focus').focus();
	
	//selects que hacen submit al cambiar
	$('.submit_select').change(function(){ this.form.submit(); });
	
	//para hacer slugs!
	$('.slug').each(function(){
		var slug = $(this);
		var title = slug.attr('rel');
		$('#'+title).keyup(function(){
			slug.val(pudin.slug($(this).val()));
		});
		$('#'+title).keyup()
	});
	
});

pudin = {
	
	slug: function(title){
		return title.toLowerCase()
			.replaceAll(' ', '-')
			.replaceAll('á', 'a')
			.replaceAll('é', 'e')
			.replaceAll('í', 'i')
			.replaceAll('ó', 'o')
			.replaceAll('ú', 'u')
			.replaceAll('ñ', 'n')
			.replace(/\s+/g,'-').replace(/[^a-z0-9\-]/g,'');
	}	
	
};


/* algunos prototipos */

String.prototype.replaceAll = function(a, b){
	if(a == b) return this;
	str = this;
	while(str.indexOf(a) != -1){
		str = str.replace(a, b);
	}
	return str;	
}
