
$(function() {
    
    var statusNamesJSON = $("#statusJSONlist").html();
    
    var statusNames = $.parseJSON(statusNamesJSON);
    
    var classNamesJSON = $("#statusClassNames").html();
    
    var classNames = $.parseJSON(classNamesJSON);
    

    $('.status').editable('/enquiries/update_status', {
        id : 'data[Enquiry][id]',
        name: 'data[Enquiry][status_id]',

        data   : $("#statusJSONlist").html(),
        type   : 'select',
        indicator : 'Saving...',
        submit : 'Update Status',
        cssclass: 'MER-inplace-select',
        callback : function(value, settings) {
            var thisStatusID = value;
            
            var newName = statusNames[thisStatusID];
          
            var id = $(this).attr('id');
            $(this).html(newName);
            
            var newClass = classNames[thisStatusID];
           
            $("#row"+id).removeClass().addClass(newClass);
          
        }
    });


	//Hide archived Enquiries
	$('*[data-archived="1"]').hide();

	$("#show").click(function() {
		$('*[data-archived="1"]').show();
	});

	$("#hide").click(function() {
		$('*[data-archived="1"]').hide(); //No DRY anywhere!
	});

});
