/**
 *  Owl
 */

Baseref = document.location.href.substring(0, document.location.href.lastIndexOf('/') + 1);

//Baseref = "/";
 
var Owl = {

  /**
   * Application description variables
   * @type {string} name
   * @type {string} version number
   * @type {string} author(s)
   * @type {string} copyright
   */
  AppName:   'Owl',
  Version:   '0.1.0',
  Authors:   'Dave Furfero, Marya Doery',
  Copyright: 'Copyright © 2006 Owl Multimedia, Inc. All rights reserved.',

  /**
   * Global configuration variables
   * @type {object}
   */
  config: {

    /**
     * Activate/deactivate debugging
     * @type {boolean}
     */
    debug: false,

    /**
     * Initially use setTimeout when calling play_url,
     * but after first call, do not use setTimeout
     * @type {boolean}
     */
    playTimeout: true,

    /**
     * Initially use setTimeout when calling analyze,
     * but after first call, do not use setTimeout
     * @type {boolean}
     */
    analyzeTimeout: true,

    /**
     * Absolute path to album artwork image files
     * @type {string}
     */
    artwork_dir: '/',

    /**
     * Relative path to register script
     * @type {string}
     */
    register_url: Baseref + 'music/register',

    /**
     * Relative path to login script
     * @type {string}
     */
    login_url: Baseref + 'music/login',

    /**
     * Relative path to logout script
     * @type {string}
     */
    logout_url: Baseref + 'music/logout',

    /**
     * Relative path to play script
     * @type {string} 
     */
    play_url: 'music/play1_obf',

    /**
     * Relative path to search script
     * @type {string}
     */
    search_url: Baseref + 'music/search_061227_nostyle',
    
    /**
     * Relative path to tag script
     * @type {string}
     */
    tag_url: Baseref + '/music/tag_user_clip',

    /**
     * Relative path to user clip tags script
     * @type {string}
     */
    get_user_clip_tags_url: Baseref + 'music/get_user_clip_tags',

    /**
     * Default number of user tags to display
     * @type {integer}
     */
    n_user_tags: 50,

    /**
     * Relative path to user tags script
     * @type {string}
     */
    get_user_tags_url: Baseref + 'music/get_user_tags',

    /**
     * Relative path to delete user tag script
     * @type {string}
     */
    delete_user_tag_url: Baseref + 'music/delete_user_tag',

    /**
     * Relative path to tag search script
     * @type {string}
     */
    search_by_tag_url: Baseref + 'music/search_061227_nostyle',

    /**
     * Relative path to Keysounds script
     * @type {string}
     */
    keysounds_url: Baseref + 'music/keysounds1',

    /**
     * Default number of Keysound ads to display
     * @type {integer}
     */
    n_keysounds: 5,

    /**
     * Maximum number of results to request
     * @type {integer}
     */
    max_results: 1000,

    /**
     * Number of search results to display per page
     * @type {integer}
     */
    results_per_page: 10,

    /**
     * Default result clip duration
     * @type {float}
     */
    default_clip_duration: 10.0026,
        
    /**
     * Minimum required version of Java
     * @type {float}
     */
    required_java_version: 1.42
    
  },

  /**
   * List of Javascript libraries to load at startup
   * (libraries must be located in the same directory as this file)
   * @type {array}
   */
  libraries: [
		'collection',
		'cookie',
		'creativeCommons',
		'error',
		'filter',
		'intelligentElement',
		'iTunesPlugin',
		'keysounds',
		'logger',
		'messenger',
		'model',
		'playerElements',
		'resultPlayer',
		'searchPlayer',
		'search',
		'tag',
		'tutorial',
		'user',
		'utility'
	],

  /**
   * Application initialization routine
   */
  initialize: function() {
    var libs = this.libraries;
    if (libs.length > 0) {
      var lib_dir = this.getLibDir();
      libs.each(
        function(lib) {
          Owl.require(lib_dir + lib + '.js');
        }
      );
    }
  },

  /**
   * Dynamically load a Javascript library
   * @param {string} path to library
   */
  require: function(path) {
    var str = '<script type="text/javascript" src="' + path + '"></script>';
    document.write(str);
  },

  /**
   * Parse the path to the library directory from the path of this script
   * @return {string} path to Owl Javascript library directory
   */
  getLibDir: function() {
    var re = /owl\.js$/;
    return $A(document.getElementsByTagName('script')).find(
      function(s) { return (s.src && s.src.match(re)); }
    ).src.replace(re, '');
  }
};
Owl.initialize();


/* Need a home */
Owl.page = 1;
Owl.searchPlayerOffset = 0;
Owl.isPlaying = null;


Owl.reload = function()
{
  document.location.href = document.location.href;

  Owl.Logger.log({
    type:       'action',
    action:     'Owl.reload',
    parameters: {}
  });
}
