module.exports = {
    id: "blackberry",
    initialize:function() {
        var cordova = require('cordova'),
            exec = require('cordova/exec'),
            channel = require('cordova/channel'),
            blackberryManager = require('cordova/plugin/blackberry/manager'),
            app = require('cordova/plugin/blackberry/app');

        // TODO: is there a better way to do this? build-time
        // convention? how can we save the few bytes from
        // cordova/plugin/Entry + DirectoryEntry that will get
        // overridden?
        // Override File API's Entry + children's prototype methods
        var BB_Entry = require('cordova/plugin/blackberry/Entry'),
            BB_DirectoryEntry = require('cordova/plugin/blackberry/DirectoryEntry');

        Entry.prototype.remove = BB_Entry.remove;
        Entry.prototype.getParent = BB_Entry.getParent;

        DirectoryEntry.prototype.getDirectory = BB_DirectoryEntry.getDirectory;
        DirectoryEntry.prototype.getFile = BB_DirectoryEntry.getFile;

        // Mapping of button events to BlackBerry key identifier.
        var buttonMapping = {
            'backbutton'         : blackberry.system.event.KEY_BACK,
            'conveniencebutton1' : blackberry.system.event.KEY_CONVENIENCE_1,
            'conveniencebutton2' : blackberry.system.event.KEY_CONVENIENCE_2,
            'endcallbutton'      : blackberry.system.event.KEY_ENDCALL,
            'menubutton'         : blackberry.system.event.KEY_MENU,
            'startcallbutton'    : blackberry.system.event.KEY_STARTCALL,
            'volumedownbutton'   : blackberry.system.event.KEY_VOLUMEDOWN,
            'volumeupbutton'     : blackberry.system.event.KEY_VOLUMEUP
        };

        // Generates a function which fires the specified event.
        var fireEvent = function(event) {
            return function() {
                cordova.fireDocumentEvent(event, null);
            };
        };

        var eventHandler = function(event) {
            return { onSubscribe : function() {
                // If we just attached the first handler, let native know we
                // need to override the back button.
                if (this.handlers.length === 1) {
                    blackberry.system.event.onHardwareKey(
                            buttonMapping[event], fireEvent(event));
                }
            },
            onUnsubscribe : function() {
                // If we just detached the last handler, let native know we
                // no longer override the back button.
                if (this.handlers.length === 0) {
                    blackberry.system.event.onHardwareKey(
                            buttonMapping[event], null);
                }
            }}
        }

        // Inject listeners for buttons on the document.
        for (var button in buttonMapping) {
            if (buttonMapping.hasOwnProperty(button)) {
                cordova.addDocumentEventHandler(button, eventHandler(button));
            }
        }

        // Fires off necessary shite to pause/resume app
        var resume = function() {
            cordova.fireDocumentEvent('resume');
            blackberryManager.resume();
        };
        var pause = function() {
            cordova.fireDocumentEvent('pause');
            blackberryManager.pause();
        };

        /************************************************
         * Patch up the generic pause/resume listeners. *
         ************************************************/

        // Unsubscribe handler - turns off native backlight change
        // listener
        var onUnsubscribe = function() {
            if (channel.onResume.handlers.length === 0 && channel.onPause.handlers.length === 0) {
                exec(null, null, 'App', 'ignoreBacklight', []);
            }
        };

        // Native backlight detection win/fail callbacks
        var backlightWin = function(isOn) {
            if (isOn === true) {
                resume();
            } else {
                pause();
            }
        };
        var backlightFail = function(e) {
            console.log("Error deteching backlight on/off.");
        };

        // Override stock resume and pause listeners so we can trigger
        // some native methods during attach/remove
        channel.onResume = channel.create('onResume', {
            onSubscribe:function() {
                // If we just attached the first handler and there are
                // no pause handlers, start the backlight system
                // listener on the native side.
                if (channel.onResume.handlers.length === 1 && channel.onPause.handlers.length === 0) {
                    exec(backlightWin, backlightFail, "App", "detectBacklight", []);
                }
            },
            onUnsubscribe:onUnsubscribe
        });
        channel.onPause = channel.create('onPause', {
            onSubscribe:function() {
                // If we just attached the first handler and there are
                // no resume handlers, start the backlight system
                // listener on the native side.
                if (channel.onResume.handlers.length === 0 && channel.onPause.handlers.length === 1) {
                    exec(function(isOn) {
                        if (isOn === true) {
                            resume();
                        } else {
                            pause();
                        }
                    }, function(e) {
                        console.log("Error deteching backlight on/off.");
                    }, "App", "detectBacklight", []);
                }
            },
            onUnsubscribe:onUnsubscribe
        });

        // Fire resume event when application brought to foreground.
        blackberry.app.event.onForeground(resume);

        // Fire pause event when application sent to background.
        blackberry.app.event.onBackground(pause);

        // Trap BlackBerry WebWorks exit. Allow plugins to clean up before exiting.
        blackberry.app.event.onExit(app.exitApp);
    },
    objects: {
        navigator: {
            children: {
                device: {
                    path: "cordova/plugin/blackberry/device"
                },
                app: {
                    path: "cordova/plugin/blackberry/app"
                }
            }
        },
        device: {
            path: "cordova/plugin/blackberry/device"
        }
    }
};

@@ -333,24 +333,678 @@
 rry/app');%0A%0A
+        // BB OS 5 does not define window.console.%0A        if (typeof window.console === 'undefined') %7B%0A            window.console = %7B%7D;%0A        %7D%0A%0A        // Override console.log with native logging ability.%0A        // BB OS 7 devices define console.log for use with web inspector%0A        // debugging. If console.log is already defined, invoke it in addition%0A        // to native logging.%0A        var origLog = window.console.log;%0A        window.console.log = function(msg) %7B%0A            if (typeof origLog === 'function') %7B%0A                origLog.call(window.console, msg);%0A            %7D%0A            org.apache.cordova.Logger.log(''+msg);%0A        %7D%0A%0A
         // T
@@ -1053,16 +1053,16 @@
 ld-time%0A
-
         
@@ -3705,12 +3705,11 @@
 ary 
-shit
+cod
 e to
@@ -4786,33 +4786,33 @@
 log(%22Error detec
-h
+t
 ing backlight on
@@ -4987,26 +4987,41 @@
  = c
-hannel.create('onR
+ordova.addDocumentEventHandler('r
 esum
@@ -5551,26 +5551,41 @@
  = c
-hannel.create('onP
+ordova.addDocumentEventHandler('p
 ause
@@ -5943,293 +5943,21 @@
 xec(
-function(isOn) %7B%0A                        if (isOn === true) %7B%0A                            resume();%0A                        %7D else %7B%0A                            pause();%0A                        %7D%0A                    %7D, function(e) %7B%0A                        console.log(%22Error deteching
+backlightWin,
  bac
@@ -5966,41 +5966,12 @@
 ight
- on/off.%22);%0A                    %7D
+Fail
 , %22A

Add console.log functionality. Fix backlight detection.