var fs = require('fs'),
    vixen = require('vixen'),

    xhr = require('./xhr');

module.exports = view;

view.defaultModel = {};
if (typeof window !== 'undefined') view.window = window;
view.readPath = fs.readFile ?
  function(path, done) {
    fs.readFile(path, {encoding:'utf8'}, done);
  } : xhr.get;


function view(opt, callback) {
  opt = opt || {};

  function done(err, html) {
    if (err) return callback(err);
    if (html != null) opt.el.innerHTML = html;
    callback(null, {
      el: opt.el,
      model: vixen(opt.el, opt.model),
      appendTo: function(to) {
        to.appendChild(this.el);
        return this;
      }
    });
  }

  // Override default view model with given model.
  opt.model = (function(a, b) {
    for (var i in b) if (!(i in a)) a[i] = b[i];
    return a;
  })(opt.model || {}, view.defaultModel);

  if (view.window && (!opt.el || typeof opt.el === 'string'))
    opt.el = view.window.document.createElement(opt.el || 'div');

  if (opt.id != null) opt.el.id = opt.id;
  if (opt.className != null) opt.el.className = opt.className;

  if (opt.path)
    view.readPath(opt.path, done);
  else
    done(null, opt.html);
}

@@ -81,233 +81,8 @@
 );%0A%0A
-module.exports = view;%0A%0Aview.defaultModel = %7B%7D;%0Aif (typeof window !== 'undefined') view.window = window;%0Aview.readPath = fs.readFile ?%0A  function(path, done) %7B%0A    fs.readFile(path, %7Bencoding:'utf8'%7D, done);%0A  %7D : xhr.get;%0A%0A%0A
 func
@@ -278,16 +278,16 @@
 opt.el,%0A
-
       mo
@@ -291,16 +291,21 @@
  model: 
+view.
 vixen(op
@@ -938,8 +938,264 @@
 tml);%0A%7D%0A
+%0Aif (typeof window !== 'undefined') view.window = window;%0A%0Aview.readPath = fs.readFile ?%0A  function(path, done) %7B%0A    fs.readFile(path, %7Bencoding:'utf8'%7D, done);%0A  %7D : xhr.get;%0A%0Aview.defaultModel = %7B%7D;%0Aview.vixen = vixen.factory();%0A%0Amodule.exports = view;%0A

Create a new vixen instance for vmvvm that is exported on the view module