/**
 * list.js
 *
 * list.js is the work horse for the list.htm file.  This script prepares the
 * page for dynamic content as soon as the DOM is available.
 *
 * The script relies on the jQuery 1.3.2 library, the jQuery plugin: Validation,
 * and the jQuery pluging: Thickbox.
 *
 * @author F. Tracy Farmer <tfarmer@astate.edu>
 * @version 1.0
 * @package Library Gift Program
 */

$(document).ready(							//the DOM is ready, so we can now
											//now start manipulating the various
											//elements
		function(){

			var addy = '';
		 	$("#loading").show('fast');		//display the loading animated gif


			$.getJSON( 						//use ajax to get the list of all
											//titles in the database.  the list
											//will include the donor/honoree(s)
											//pair for each item and the bib id

					"php/list.php",			//this is the server-side script name
											//that will return the opac address

					function (data) {		//callback function to process the
											//returned json serialized data

						var options = '';	//options is a string that will hold
						 					//the HTML statement to add to the
						 					//select element.  Set it to nothing.
						var title = '';
						var bibid = 0;

						for(var i=0; i<data.length;i++){
								 		//iteriate through the JSON data
								 			//json.length - 1 times.  build an
								 			//option statement for each item in
								 			//the JSON data
							options = '<p class="title_bold"><a href="' +data[i].url +'">' +data[i].title +'</a></p>';

							for(var j=0; j<data[i].dh.length;j++){
								options += '<p class="offset">donated by ' +data[i].dh[j].donor;
								if(data[i].dh[j].honoree != "No Honoree"){
									options += ' in honor of ' +data[i].dh[j].honoree;
								}
								options += '.</p>';
							}

							$("#items").append(options);
						}

					}
			);

			$("#loading").hide('fast');

	 });

