function renderImage(event){
	var reader = new FileReader();
  var elementId = event.target.id;
  var file = event.target.files[0];
	reader.onload = function(event){
		the_url = event.target.result;
    var canvas, context, img, width, height;
    if (elementId === 'camera-input-camera') {
      getService('Camera').loadImage('camera-preview-camera-canvas', event.target.result);
    } else if (elementId === 'camera-input-album') {
      getService('Camera').loadImage('camera-preview-album-canvas', event.target.result);
    }
	}
  
  //when the file is read it triggers the onload event above.
	reader.readAsDataURL(file);
}
require(
		[ "dojo/dom", "dijit/registry" ],
		function(dom, registry) {

			addService(
					"Camera",
					function() {
						var cameraDir = "";
						var curCameraImage = "";
						var curAlbumImage = "";
						//var cameraFile = null;

						// Public
						// Set image to return for camera
						this.setCameraImage = function(image) {
							curCameraImage = image;
							dom.byId("cameraSelectedId").src = cameraDir
									+ curCameraImage;
							dom.byId("cameraSizeId").innerHTML = image;
						};

						// Public
						// Set image to return for library
						this.setAlbumImage = function(image) {
							curAlbumImage = image;
							dom.byId("albumSelectedId").src = cameraDir
									+ curAlbumImage;
							dom.byId("albumSizeId").innerHTML = image;
						};

						// Get image for camera or library
						var getImage = function(destinationType, source, encodingType) {
              var elementId = source === 1 ? 'camera-preview-camera-canvas' : 
                'camera-preview-album-canvas';
              var dataUrl = document.getElementById(elementId).toDataURL();
              if (dataUrl.match(/^data:.*,.*$/)) {
                // Get only the data part of the data URI 
                dataUrl = dataUrl.split(",")[1];
              }
              return dataUrl;
						};

						// Public
						// Handle requests
						this.exec = function(action, args, callbackId, uuid) {
							// [quality, destinationType, sourceType,
							// targetWidth, targetHeight,
							// encodingType]
							if (action == 'takePicture') {
								var r = null;
								r = getImage(args[1], args[2], args[5]);
								return new PluginResult(callbackId,
										PluginResultStatus.OK, r, false);
							}
							if (action == 'cleanup') {
								var platformID = getSimByUUID(uuid).device.platformID;
								var isiOS = platformID.toString().indexOf(
										".ios.") != -1;
								if (isiOS)
									return new PluginResult(callbackId,
											PluginResultStatus.OK, "", false);
								else
									return new PluginResult(callbackId,
											PluginResultStatus.INVALID_ACTION,
											"", false);
							}
							return new PluginResult(callbackId,
									PluginResultStatus.INVALID_ACTION);
						};

            this.loadImage = function(elementId, imageSrc) {
              var img = new Image();
              img.src = imageSrc;
              img.onload = function(){
                var canvas = document.getElementById(elementId);
                var context = canvas.getContext('2d');
                var scale = 1;
                canvas.width = img.width * scale;
                canvas.height = img.height * scale;
                context.drawImage(img, 0, 0, img.width * scale, img.height * scale);
              }
            }

						// Initialization
						{
              this.loadImage('camera-preview-camera-canvas', 'sim/camera/camera1_s.png');
              this.loadImage('camera-preview-album-canvas', 'sim/camera/album1_s.png');
						}
					});
		});
