
$(document).ready(function (){
	$( ".autocomplete_input").each(function (i,n){
		$(n).autocomplete({
			source		: function( request, response ) {
				// this is by default takes the name
				// unless rel is provided, this is useful when
				// you need to get same data for different fields
				// e.g. "your occupation" and "cohab's occupation" hold same list of data 
				// such as lawyer, web dev,nurse,teacher, etc...
				var name = $(n).attr('name');
					name = $(n).attr('rel')||name;
				//assoc allows you to use a relative to another fields value
				//e.g. only show 
				var assoc= $(n).attr('data-assoc');
					assoc= $('#'+assoc).val();
				$.ajax({
					url			: site_url+"home/autocom/"+name+"/",
					type		: 'POST',
					dataType	: "json",
					data		: {	q: request.term,assoc:assoc	},
					success		: function( data ) {
						response( $.map( data, function( item ) {
							return {label: item.title,value: item.value}
						}));
					}
				});
			},
			minLength	: 1,
			delay		: 1,//delay 1 milisecond 1/1,000 of a second to allow smoothness
			select		: function( event, ui ) {	},
			open		: function() {
				$( n ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
			},
			close		: function() {
				$( n ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
			}
		});
	});
});
