/**
  * Creates a new RSG2 instance and executes it.
  *
  * @static
  * @param	array	$instance		What parameters to use for the new instance.  Your options are:
  * array			A custom array.
  * 'request'	Use the request array (default).
  * @param boolean show a template or not.
  */
 function instance($newInstance = 'request', $showTemplate = true)
 {
     static $instanceStack = array();
     $stacked = false;
     // if rsg2 is already instanced then push the current instance to be pop'd later
     if ($GLOBALS['_RSGINSTANCE']) {
         $stacked = true;
         if (count($instanceStack) > 9) {
             JError::raiseError('9', 'RSGallery2 instance stack exceeds 9.  Probable endless recursion, $instanceStack:<pre>' . print_r($instanceStack, 1) . '</pre>');
         }
         // push current instance on stack
         array_push($instanceStack, $GLOBALS['_RSGINSTANCE']);
     }
     $GLOBALS['_RSGINSTANCE'] = $newInstance;
     if ($showTemplate) {
         // execute a frontend template based instance
         require_once JPATH_RSGALLERY2_SITE . '/main.rsgallery2.php';
         rsgInstance::mainSwitch();
     }
     if ($stacked) {
         $GLOBALS['_RSGINSTANCE'] = array_pop($instanceStack);
     }
 }