/**
  * Get instance of Zo2Profile by name
  * @staticvar array $profiles
  * @param type $profile
  * @return \Zo2Profile
  */
 public static function getProfile($profile = null)
 {
     static $profiles = array();
     $profileName = 'default';
     if ($profile === null) {
         if (JFactory::getApplication()->isSite()) {
             $profileName = Zo2Framework::getInstance()->template->params->get('profile', 'default');
             $profileName = JFactory::getApplication()->input->get('profile', $profileName);
         } else {
             $profileName = JFactory::getApplication()->input->get('profile');
             if (empty($profileName)) {
                 $profileName = Zo2Framework::getInstance()->template->params->get('profile', 'default');
             }
         }
     } else {
         if (is_string($profile)) {
             $profileName = $profile;
         } elseif ($profile instanceof Zo2Profile) {
             $profileName = $profile->name;
         }
     }
     if (!is_string($profileName) || empty($profileName)) {
         $profileName = 'default';
     }
     if (!isset($profiles[$profileName])) {
         $profile = new Zo2Profile();
         $profile->load($profileName);
         $profiles[$profileName] = $profile;
     }
     return $profiles[$profileName];
 }
 /**
  * 
  * @param string $dir
  * @return array Zo2Profile
  */
 private function _getProfiles($dir)
 {
     $profiles = array();
     if (JFolder::exists($dir)) {
         $files = JFolder::files($dir);
         if ($files) {
             foreach ($files as $file) {
                 if (JFile::getExt($file) == 'json') {
                     $profile = new Zo2Profile();
                     $profile->load(JFile::stripExt($file));
                     if ($profile->isValid()) {
                         $profiles[$profile->name] = $profile;
                     }
                 }
             }
         }
     }
     return $profiles;
 }