$(document).ready(function(){

	var $number = $('#number');
	var $text = $('#text');
	var totalParagraphs = 40;

	$('#type, #number').change(function(){
		$text.val('');
	});

	$('#go').click(function(){
		// how many paragraphs did the user want?
		var num = $number.val();
		// what greek text type did the user request?
		var type = $('#type').val();
		// make ajax call for the selected greek text
		$.ajax({
			type: "get",
			url: type+'.html',
			// set up the error handler
			error: function(e){
				$text.val('The text you requested could not be found, please select another.');
			},
			// as well as the success method
			success: function(data){
				var finalStr = '';
				// split out the desired content from the rest of the page, dump it into an array
				var contentArr = data.replace(/\t/gi,'').split('<br /><br />').slice(0,num);
				// loop over the array, put it into string format
				for (r=0 ; r < contentArr.length; r++) {
					var finalStr = finalStr + contentArr[r];
				}
				// pour the final string into the textarea, removing
				// the first line break at the beginning of the string
				$text.val(finalStr.replace(/\r\n/,''));
			}
		});

	});

	$('a.select, #text').click(function(){
		$text.select();
		return false;
	});


});