$(document).ready(function(){
	//autocomplete_data = pm.autocomplete_data()
	/*
	$('#search_input').autocomplete({
		minLength: 0,
		source: autocomplete_data,
		select: function( event, ui ) {
			window.location.href = ui.item.url;
		}
	})
	.data( "autocomplete" )._renderItem = function( ul, item ) {
		return $( "<li></li>" )
			.data( "item.autocomplete", item )
			.append( "<a href='" + item.url + "'>" + item.full_name + "</a>" )
			.appendTo( ul );
		};
	*/
});

var pm = {

	show_loader: function() {
		$('.loading_container img').css({ opacity: "1"});
	},
	hide_loader: function() {
		$('.loading_container img').css({ opacity: "0"});
	},

	autocomplete_data: function() { pm.get_autocomplete() },
	
	get_autocomplete: function() {
		$.ajax({
			type: 'POST',
			url: '/people/+_autocomplete_+/',
			success:function(data) {
				return data;
			},
			error:function(){
				return null
			}
		});
	},

	ajax_error: function() {
		dialog = "<div class=pm-dialog id=ajax_error_box style=display:none;>\
		<div class=pm-dialog-header>\
		<h3>Connection Error</h3>\
		<a href=\"#\" class=pm-dialog-close id=close-box onclick=\"$('.pm_alerts').empty(); return false;\">\
		<b>×</b>\
		</a>\
		</div>\
		<div class=pm-dialog-inside>\
		<div class=pm-dialog-body clearfix>\
		<div class=pm-dialog-content>\
		<div class=pm-box-content>\
		<div class=pm-box-content-title>\
		<h2>Connection error</h2>\
		</div>\
		<b style=font-size:14px;>An error occurred while trying to get data from the server, check your internet connection and try later</b>\
		<div class=pm-button-container>\
		</div></div></div></div></div></div>";
		$('.pm_alerts').html(dialog);
		$("#ajax_error_box").draggable({ handle: "div.pm-dialog-header", cancel: "a.pm-dialog-close" });
		$('#ajax_error_box').fadeIn('fast');
		if(console) {
			console.log("Can't get data from the server");
		}
	}
};

