/**
  * JTheFactoryApplication::Initialize()
  *  loads some "magic" files like defines.php,loads the main helper file (APP_PREFIX.php)
  *  loads other helpers (through helper::loadHelperclasses)
  *  loads the needed Controller
  *  adds htmlelements and formelements to path (admin)
  *  adds tables to paths
  * 
  * @return void
  */
 function Initialize($task = null)
 {
     jimport('joomla.application.component.controller');
     if (!$this->frontpage) {
         JFormHelper::addFieldPath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'formelements');
     }
     JHtml::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'htmlelements');
     JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
     if (file_exists(JPATH_COMPONENT_SITE . DS . 'defines.php')) {
         require_once JPATH_COMPONENT_SITE . DS . 'defines.php';
     }
     if (file_exists(JPATH_COMPONENT_SITE . DS . 'helpers' . DS . strtolower($this->appname) . '.php')) {
         require_once JPATH_COMPONENT_SITE . DS . 'helpers' . DS . strtolower($this->appname) . '.php';
     }
     $class_name = ucfirst($this->appname) . 'Helper';
     call_user_func(array($class_name, 'loadHelperClasses'));
     JTheFactoryEventsHelper::triggerEvent('onBeforeExecuteTask', array(&$this->_stopexecution));
     if ($this->_stopexecution) {
         return;
     }
     if (!$task) {
         $task = JRequest::getCmd('task');
     }
     $this->_controller = JTheFactoryHelper::loadController($task);
     //Try to load Framework controllers
     if (!$this->_controller) {
         $controllerClass = JRequest::getWord('controller');
         if (!$controllerClass && strpos($task, '.') !== FALSE) {
             $task = explode('.', $task);
             $controllerClass = $task[0];
         }
         if ($controllerClass) {
             $path = JPATH_COMPONENT . DS . 'controllers' . DS . basename($controllerClass) . '.php';
             file_exists($path) ? require_once $path : JError::raiseError(500, JText::_('ERROR_CONTROLLER_NOT_FOUND'));
             $controllerClass = 'J' . ucfirst($this->appname) . ($this->frontpage ? "" : "Admin") . 'Controller' . $controllerClass;
             $this->_controller = new $controllerClass();
         } else {
             $this->_controller = JControllerLegacy::getInstance('J' . ucfirst($this->appname) . ($this->frontpage ? "" : "Admin"));
         }
     }
 }