/*
 * asciimo.js 
 * 
 * Copyright (c) 2010 Marak Squires
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 * http://github.com/marak/figlet-js
 * Figlet JS 
 * 
 * Copyright (c) 2010 Scott González
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 * 
 * http://github.com/scottgonzalez/figlet-js
 */


(function() {

// Remark : not a very good env check
var fontPath;
if(typeof __dirname == 'undefined'){
  fontPath = './fonts/';
}
else{
  fontPath = __dirname + '/../fonts/';
}

var Figlet = (typeof exports !== "undefined" ? exports : window).Figlet = {
  fonts: {},
  
  parseFont: function(name, fn) { //        debug.log('parseFont', name);  
    if (name in Figlet.fonts) {
      fn();
    }
    Figlet.loadFont(name, function(defn) {          
      Figlet._parseFont(name, defn, fn);
    });
  },
  
  _parseFont: function(name, defn, fn) {
    var lines = defn.split("\n"),
      header = lines[0].split(" "),
      hardblank = header[0].charAt(header[0].length - 1),
      height = +header[1],
      comments = +header[5];
    
    Figlet.fonts[name] = {
      defn: lines.slice(comments + 1),
      hardblank: hardblank,
      height: height,
      char: {}
    };
    fn();
  },
  
  parseChar: function(char, font) { // debug.log('parseChar');
    var fontDefn = Figlet.fonts[font];
    if (char in fontDefn.char) {
      return fontDefn.char[char];
    }
    
    var height = fontDefn.height,
      start = (char - 32) * height,
      charDefn = [],
      i;
    for (i = 0; i < height; i++) {
      charDefn[i] = fontDefn.defn[start + i]
        .replace(/@/g, "")
        .replace(RegExp("\\" + fontDefn.hardblank, "g"), " ");
    }
    return fontDefn.char[char] = charDefn;
  },

  write: function(str, font, fn) {
    Figlet.parseFont(font, function() { // debug.log('parseFont');
      var chars = [],
        result = "";
      for (var i = 0, len = str.length; i < len; i++) {
        chars[i] = Figlet.parseChar(str.charCodeAt(i), font);
      }
      for (i = 0, height = chars[0].length; i < height; i++) {
        for (var j = 0; j < len; j++) {
          result += chars[j][i];
        }
        result += "\n";
      }
      fn(result, font);
    });
  },
  
  loadFont: function(name, fn) {
    if(typeof exports != 'undefined'){
      var util = require('util');
      require("fs").readFile(fontPath + name + ".flf", "utf-8", function(err, contents) {
        if (err) {
          util.puts(err);
        }
        else {
          fn(contents);
        }
      });
    }
    else{
      $.get(fontPath + name+ '.flf',function(contents){
        fn(contents);
      });
    }   
  }
};

})();


@@ -9,21 +9,19 @@
 ciimo.js
- 
 %0A *
- 
 %0A * Copy
@@ -186,21 +186,19 @@
 iglet JS
- 
 %0A *
- 
 %0A * Copy
@@ -317,17 +317,16 @@
 nses.%0A *
- 
 %0A * http
@@ -532,16 +532,54 @@
 name
+.substring(0, __dirname.lastIndexOf(%22/%22))
  + '/
-../
 font
@@ -675,18 +675,16 @@
 ts: %7B%7D,%0A
-  
 %0A  parse
@@ -749,18 +749,16 @@
 , name);
-  
 %0A    if 
@@ -842,26 +842,16 @@
 (defn) %7B
-          
 %0A      F
@@ -897,18 +897,16 @@
 );%0A  %7D,%0A
-  
 %0A  _pars
@@ -1123,20 +1123,16 @@
 der%5B5%5D;%0A
-    
 %0A    Fig
@@ -1277,18 +1277,16 @@
 );%0A  %7D,%0A
-  
 %0A  parse
@@ -1453,20 +1453,16 @@
 ;%0A    %7D%0A
-    
 %0A    var
@@ -1726,24 +1726,25 @@
 %22 %22);%0A    %7D%0A
+%0A
     return f
@@ -2266,18 +2266,16 @@
 );%0A  %7D,%0A
-  
 %0A  loadF
@@ -2349,20 +2349,19 @@
     var 
-util
+sys
  = requi
@@ -2364,20 +2364,19 @@
 equire('
-util
+sys
 ');%0A    
@@ -2494,12 +2494,11 @@
     
-util
+sys
 .put
@@ -2683,19 +2683,16 @@
 );%0A    %7D
-   
 %0A  %7D%0A%7D;%0A

Corrected the path to fonts