var os = require('os');
var path = require('path');

var FFI = require('ffi');
var ref = require('ref');

var LIBRARY_PATHS = [];

switch (os.platform()) {
  case 'darwin':
    LIBRARY_PATHS.push('/Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib');
    LIBRARY_PATHS.push(path.join(process.env.HOME, 'Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib'));
    break;
  case 'win32':
    if (process.env['ProgramFiles(x86)']) {
      LIBRARY_PATHS.push(path.join('',
        process.env['ProgramFiles(x86)'],
        'VideoLAN',
        'VLC',
        'libvlc.dll'
      ));
    }
    LIBRARY_PATHS.push(path.join(
      process.env['ProgramFiles'],
      'VideoLAN',
      'VLC',
      'libvlc.dll'
    ));
    break;
  default:
    LIBRARY_PATHS.push('/usr/lib/libvlc.so');
    LIBRARY_PATHS.push('/usr/lib/libvlc.5.so');
    break;
}

exports.LIBRARY_PATHS = LIBRARY_PATHS;

var lib, MediaPlayer, Media, VLM;

var VLC = function (args) {
  if (!(this instanceof VLC)) {
    return new VLC(args);
  }

  if (!lib) {
    lib = require('./lib/libvlc').initialize(LIBRARY_PATHS);
    MediaPlayer = require('./lib/mediaplayer');
    Media = require('./lib/media');
    VLM = require('./lib/vlm');
  }

  var mediaplayer, vlm;
  var released = false;

  var cargs = new Buffer(ref.sizeof.pointer * args.length);
  for (var i = 0; i < args.length; i++) {
    cargs.writePointer(ref.allocCString(args[i]), i * ref.sizeof.pointer);
  }

  instance = lib.libvlc_new(args.length, cargs);

  Object.defineProperty(this, 'mediaplayer', {
    get: function () {
      if (!mediaplayer) {
        mediaplayer = new MediaPlayer(instance);
      }
      return mediaplayer;
    },
  });

  Object.defineProperty(this, 'vlm', {
    get: function () {
      if (!vlm) {
        vlm = new VLM(instance);
      }
      return vlm;
    },
  });

  this.release = function () {
    if (!released) {
      if (mediaplayer) {
        mediaplayer.release();
      }
      if (vlm) {
        vlm.release();
      }
      lib.libvlc_release(instance);
      released = true;
    }
  };

  this.mediaFromFile = function (path) {
    return new Media(instance, undefined, { path: path });
  };
  
  this.mediaFromUrl = function(url){
    return new Media(instance, undefined, { url: url });
  };

  this.mediaFromFd = function(fd){
    return new Media(instance, undefined, { fd: fd });
  };

  this.mediaFromNode = function(node){
    return new Media(instance, undefined, node);
  };

  this.mediaFields = require('./lib/media_enum').metaEnum;
};

module.exports = VLC;

@@ -819,12 +819,12 @@
 vlc.
-5.
 so
+.5
 ');%0A

fix unix so naming