$(document).ready(function(){
	
	// The published URL of your Google Docs spreadsheet as CSV:
    var csvURL = 'https://spreadsheets5.google.com/pub?hl=en&hl=en&key=0ApGtL4QiLpTJdDkzOTJNa0RQdUdnY2xFVU45WnVkYnc&output=csv';
	
	// The YQL address:
	// var yqlURL = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20csv%20where%20url%3D'https%3A%2F%2Fspreadsheets.google.com%2Fpub%3Fhl%3Den%26hl%3Den%26key%3D0AiNaq8eYjUi8dDNCd1lpenVhcC1VQkRENmd6Zk82anc%26output%3Dcsv'%20and%20columns%3D'titulo%2Ctexto1%2Ctexto2'&format=json&callback=?";
	
	
	var yqlURL ="http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20csv%20where%20url%3D'https%3A%2F%2Fspreadsheets5.google.com%2Fpub%3Fhl%3Den%26hl%3Den%26key%3D0ApGtL4QiLpTJdDkzOTJNa0RQdUdnY2xFVU45WnVkYnc%26output%3Dcsv'%20and%20columns%3D'titulo%2Ctexto1%2Ctexto2'&format=json&diagnostics=true&callback=?";

	
	var x=0
	$.getJSON(yqlURL,function(msg){
		
		var texto = $('<texto>');
		
		
		// Looping through all the entries in the CSV file:
		$.each(msg.query.results.row,function(){
			
			// Sometimes the entries are surrounded by double quotes. This is why 
			// we strip them first with the replace method:
			
			var titulo = this.titulo.replace(/""/g,'"').replace(/^"|"$/g,'');
     		var texto1 = this.texto1.replace(/""/g,'"').replace(/^"|"$/g,'');
			var texto2 = this.texto2.replace(/""/g,'"').replace(/^"|"$/g,'');
			if (texto2==""){
				texto2=" "
			}
			
			// Formatting the FAQ as a definition list: dt for the question
			// and a dd for the answer.
	
			texto = ('<h1>'+titulo+'</h1><h2>'+texto1+'</h2><h2>'+texto2+'</h2>');
			
		// Appending the definition list:
		if (x==1) {
				$('#cuadrotexto').append(texto);
   			}
		if (x==2) {
				$('#banner1').append(texto);
		    }
		if (x==3) {
				$('#banner2').append(texto);
		    }
		if (x==4) {
				$('#banner3').append(texto);
		    }
			
		x+=1
		});
         

		
	});
});

