/**
 * @fileoverview Loads generic modules required for all widgets.
 *
 * <pre>
 * Copyright (c) 2006 by SouthProjects
 * http://www.southprojects.com
 * Santiago, Chile,
 * Version 1.2 Dec 2006.
 * All rights reserved.
 * </pre>
 */

/* $Id: southprojects.js 4908 2006-10-25 15:19:32Z alex $ */

if (typeof southprojects == 'undefined') {
  /**
   * Namespace definition.
   * @constructor
   */
  southprojects = function() {};
}

/**
 * southprojects Suite version.
 * @private
 */
southprojects.version = '2.1.comp';

/**
 * Path to main southprojects script.
 * @private
 */
southprojects.southprojectsPath = function() {
  // Get all script elements
  var arrScripts = document.getElementsByTagName('script');
  // Find the script in the list
  for (var iScript = arrScripts.length - 1; iScript >= 0; iScript--) {
    var strSrc = arrScripts[iScript].getAttribute('src');
    if (!strSrc) {
      continue;
    }
    var arrTokens = strSrc.split('/');
    // Remove last token
    var strLastToken;
    if (Array.prototype.pop) {
      strLastToken = arrTokens.pop();
    } else {
      // IE 5
      strLastToken = arrTokens[arrTokens.length - 1];
      arrTokens.length -= 1;
    }
    if (strLastToken == 'southprojects.js') {
      return arrTokens.length ? arrTokens.join('/') + '/' : '';
    }
  }
  // Not found
  return '';
} ();

// For backward compatibility
if (southprojects.version == '2.1.comp') {
  southprojects.southprojectsPath = southprojects.southprojectsPath.replace(/utils\/$/, '../utils/');
}

/**
 * Simply writes script tag to the document.
 *
 * <pre>
 * If special southprojects.doNotInclude flag is set, this function does nothing.
 * </pre>
 *
 * @private
 * @param {string} strSrc Src attribute value of the script element
 * @param {string} strId Optional. Id of the script element
 */
southprojects.include = function(strSrc, strId) {
  // Check flag
  if (southprojects.doNotInclude) {
    return;
  }
  // Include file
  document.write('<script type="text/javascript" src="' + 
   strSrc + (typeof strId == 'string' ? '" id="' + strId : '') + '"></script>');
};

// Include required scripts
southprojects.include(southprojects.southprojectsPath + 'utils.js', 'southprojects.Utils');
southprojects.include(southprojects.southprojectsPath + 'zpeventdriven.js', 'southprojects.EventDriven');
southprojects.include(southprojects.southprojectsPath + 'transport.js', 'southprojects.Transport');
southprojects.include(southprojects.southprojectsPath + 'zpwidget.js', 'southprojects.Widget');
