/* Copyright 2009 Palm, Inc.  All rights reserved. */
/*global Mojo, Class, $L, Template, WordAssistant, ExcelAssistant, PowerPointAssistant */
/*jslint rhino:true, undef:true */

var RecentAssistant = Class.create({

    appMenuModel: 
    {
        label: $L('PDF View'),
        items: [
                 {
                   label: $L('Help...'),
                   command: Mojo.Menu.helpCmd,
                   disabled: true
                 }
               ]
    },

    GetFileExtension: function (fileinput)
    {
        if (fileinput.length === 0) {
            return '';
        }

        var dot = fileinput.lastIndexOf('.');

        if (dot === -1) {
            return '';
        }

        var extension = fileinput.substr(dot + 1, fileinput.length);

        if (extension.length === 4) {
            extension = extension.substr(0, 3);
        }

        return extension;
    },

    checkFileType: function (fileinput)
    {
        var ext = this.GetFileExtension(fileinput);
        return ext.toLowerCase() == 'pdf';
    },

    setup: function() 
	{

        // Doesn't appear to be overridding the filepicker system menus
        this.controller.setupWidget(Mojo.Menu.appMenu,
                                    { omitDefaultItems: true },
                                    this.appMenuModel);
    },

    activate: function() 
	{
        //Mojo.Log.info("RecentAssistant: activate");

        var params = {
            // Only show files
            kind: 'file',

            extensions: ['pdf'],

            onSelect: function(file){
                //Mojo.Log.info("onSelect: '%s'", file.fullPath);

                if (this.checkFileType(file.fullPath))
                {
                    // Push the new document scene
                    var args = { name: 'document', disableSceneScroller: true };
                    var params = { hidemode: 'none', filename: file.fullPath };

                    this.controller.stageController.swapScene(args, params);
                }
            }.bind(this)
        };

        Mojo.FilePicker.pickFile(params, this.controller.stageController);

    },

    initialize: function() 
	{
        //Mojo.Log.info("RecentAssistant: initialize");
    },

    ready: function() 
	{
        //Mojo.Log.info("RecentAssistant: ready");
    },

    cleanup: function() 
	{
        //Mojo.Log.info("RecentAssistant: cleanup");
    },

    deactivate: function() 
	{
        //Mojo.Log.info("RecentAssistant: deactivate");
    }

});



