var util = require('util');
var async = require('async');
var mongoose = require('mongoose')
var utils = rekuire('/lib/utils')
var extend = require('util')._extend
var SectionGrup = mongoose.model('SectionGrup');
var SectionType = mongoose.model('SectionType')
var Section = mongoose.model('Section');
var User = mongoose.model('User');

exports.model = mongoose.model('Document');
exports.title = 'Elderwand';
exports.singularName = 'document';
exports.pluralName = 'documents';
var BaseController = require('elderwand').BaseController;
BaseController.inherit(exports);

exports.super.loadRelatedData = exports.loadRelatedData
 exports.loadRelatedData = function(data, req, res, callback){  
  exports.super.loadRelatedData(data, req, res, function(newData){
    async.parallel([
      function(next){
        Section.list({}, function(err, result){
          newData.sections = result;
          next()
        });
      },
      function(next){
        SectionGrup.list({}, function(err, result){
          newData.sectionGrups = result;
          next()
        });
      },
      function(next){
        SectionType.list({}, function(err, result){
          newData.sectionTypes = result;
          next()
        });
      }
    ], function(err){
      callback(newData); 
    }) 
  });
 }

