/*Call this function after selecting a name*/
function onceSelected(){
	var selected = $('search').value; 
	/*grab the id in the beginning 1) Name*/
	selected_array = selected.split(")");
	film_id = selected_array[0];
	$('selected_name_title').innerHTML = "Selection: "+selected;
	grabFilmInformation(film_id);
	$('search').value = "";
	return true;
}
/*This function grabs the requested information
 * @param film_id - id of film results
 */
 function grabFilmInformation(film_id){
	 if (createLoadImage()){
		 url = 'search_details/'+film_id;
		 new Ajax.Request(url, {
			  method: 'get',
			  onSuccess: function(transport) {
			    new Effect.Highlight('results',{ duration: 1.5, beforeStart:function(){$('results').update(transport.responseText);}});
		}});
	}
	return true;
}
/*This function creates a load image
 */
 function createLoadImage(){
 	var image = new Image();
 	image.src = "../img/loading.gif";
 	$('results').innerHTML = "<div id='loader' style='text-align:center;width:100%;'>Loading Film Details...<br /><span id='load_image'></span></div>"
 	$('load_image').appendChild(image);
 	return true;
}
function init(){
	new AutoComplete('search', 'search.xml?search_param=', { delay: 0.25, onSelect: onceSelected});
}
window.onload=init;