diff --git a/e107_plugins/gallery/admin_gallery.php b/e107_plugins/gallery/admin_gallery.php
index 7d6799ccc..0b3e091c8 100644
--- a/e107_plugins/gallery/admin_gallery.php
+++ b/e107_plugins/gallery/admin_gallery.php
@@ -1,21 +1,18 @@
 <?php
-/*
+
+/**
  * e107 website system
  *
  * Copyright (C) 2008-2009 e107 Inc (e107.org)
  * Released under the terms and conditions of the
  * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
  *
+ * @author e107coders
  *
- *
- * $Source: /cvs_backup/e107_0.8/e107_plugins/download/admin_download.php,v $
- * $Revision: 12639 $
- * $Date: 2012-04-20 00:28:53 -0700 (Fri, 20 Apr 2012) $
- * $Author: e107coders $
+ * @file
+ * Class installations to handle configuration forms on Admin UI.
  */
 
-// TODO: prefs for prettyPhoto library, e.g. theme settings
-
 $eplug_admin = true;
 
 require_once("../../class2.php");
@@ -32,15 +29,25 @@ e107::lan('gallery', true, true);
 $e_sub_cat = 'gallery';
 
 
+/**
+ * Class plugin_gallery_admin.
+ */
 class plugin_gallery_admin extends e_admin_dispatcher
 {
 
 	/**
-	 * Format: 'MODE' => array('controller' =>'CONTROLLER_CLASS'[, 'index' => 'list', 'path' => 'CONTROLLER SCRIPT PATH', 'ui' => 'UI CLASS NAME child of e_admin_ui', 'uipath' => 'UI SCRIPT PATH']);
-	 * Note - default mode/action is autodetected in this order:
-	 * - $defaultMode/$defaultAction (owned by dispatcher - see below)
-	 * - $adminMenu (first key if admin menu array is not empty)
-	 * - $modes (first key == mode, corresponding 'index' key == action)
+	 * Required (set by child class).
+	 *
+	 * Controller map array in format.
+	 * @code
+	 *  'MODE' => array(
+	 *      'controller' =>'CONTROLLER_CLASS_NAME',
+	 *      'path' => 'CONTROLLER SCRIPT PATH',
+	 *      'ui' => 'UI_CLASS', // extend of 'comments_admin_form_ui'
+	 *      'uipath' => 'path/to/ui/',
+	 *  );
+	 * @endcode
+	 *
 	 * @var array
 	 */
 	protected $modes = array(
@@ -59,8 +66,23 @@ class plugin_gallery_admin extends e_admin_dispatcher
 	);
 
 	/**
-	 * Format: 'MODE/ACTION' => array('caption' => 'Menu link title'[, 'url' => '{e_PLUGIN}release/admin_config.php', 'perm' => '0']);
-	 * Additionally, any valid e107::getNav()->admin() key-value pair could be added to the above array
+	 * Optional (set by child class).
+	 *
+	 * Required for admin menu render. Format:
+	 * @code
+	 *  'mode/action' => array(
+	 *      'caption' => 'Link title',
+	 *      'perm' => '0',
+	 *      'url' => '{e_PLUGIN}plugname/admin_config.php',
+	 *      ...
+	 *  );
+	 * @endcode
+	 *
+	 * Note that 'perm' and 'userclass' restrictions are inherited from the $modes, $access and $perm, so you don't
+	 * have to set that vars if you don't need any additional 'visual' control.
+	 *
+	 * All valid key-value pair (see e107::getNav()->admin function) are accepted.
+	 *
 	 * @var array
 	 */
 	protected $adminMenu = array(
@@ -68,33 +90,89 @@ class plugin_gallery_admin extends e_admin_dispatcher
 	);
 
 	/**
-	 * Navigation menu title
+	 * Optional (set by child class).
+	 *
 	 * @var string
 	 */
 	protected $menuTitle = LAN_PLUGIN_GALLERY_TITLE;
 
+	/**
+	 * Initial function.
+	 */
 	function init()
 	{
 		if(E107_DEBUG_LEVEL > 0)
 		{
-			$this->adminMenu['main/list'] = array('caption' => LAN_CATEGORY, 'perm' => 'P');
+			$this->adminMenu['main/list'] = array(
+				'caption' => LAN_CATEGORY,
+				'perm'    => 'P',
+			);
 		}
 	}
+
 }
 
 
+/**
+ * Class gallery_cat_admin_ui.
+ */
 class gallery_cat_admin_ui extends e_admin_ui
 {
 
+	/**
+	 * Could be LAN constant (multi-language support).
+	 *
+	 * @var string plugin name
+	 */
 	protected $pluginTitle = LAN_PLUGIN_GALLERY_TITLE;
-	protected $pluginName  = 'gallery';
-	protected $table       = "core_media_cat";
-	protected $pid         = "media_cat_id";
-	protected $perPage     = 10; // No limit.
-	protected $listOrder   = 'media_cat_order';
 
-	protected $listQry = "SELECT * FROM `#core_media_cat` WHERE media_cat_owner = 'gallery' "; // Without any Order or Limit.
+	/**
+	 * Plugin name.
+	 *
+	 * @var string
+	 */
+	protected $pluginName = 'gallery';
 
+	/**
+	 * Plugin table.
+	 *
+	 * @var string
+	 */
+	protected $table = "core_media_cat";
+
+	/**
+	 * Primary key in plugin table.
+	 *
+	 * @var string
+	 */
+	protected $pid = "media_cat_id";
+
+	/**
+	 * Default (db) limit value.
+	 *
+	 * @var integer
+	 */
+	protected $perPage = 10;
+
+	/**
+	 * SQL order, false to disable order, null is default order.
+	 *
+	 * @var string
+	 */
+	protected $listOrder = 'media_cat_order';
+
+	/**
+	 * SQL query for listing. Without any Order or Limit.
+	 *
+	 * @var string
+	 */
+	protected $listQry = "SELECT * FROM `#core_media_cat` WHERE media_cat_owner = 'gallery' ";
+
+	/**
+	 * UI field data.
+	 *
+	 * @var array
+	 */
 	protected $fields = array(
 		'checkboxes'         => array(
 			'title'   => '',
@@ -104,15 +182,6 @@ class gallery_cat_admin_ui extends e_admin_ui
 			'thclass' => 'center',
 			'class'   => 'center',
 		),
-		/*
-		'media_cat_id'       => array(
-			'title'    => LAN_ID,
-			'type'     => 'number',
-			'width'    => '5%',
-			'forced'   => true,
-			'readonly' => true,
-		),
-		*/
 		'media_cat_image'    => array(
 			'title'     => LAN_IMAGE,
 			'type'      => 'image',
@@ -188,163 +257,96 @@ class gallery_cat_admin_ui extends e_admin_ui
 		),
 	);
 
+	/**
+	 * Referenced from $prefs property per field - 'tab => xxx' where xxx is the tab key (identifier).
+	 *
+	 * Example:
+	 * @code
+	 *  array(
+	 *      '0' => 'Tab label',
+	 *      '1' => 'Another label',
+	 *  );
+	 * @endcode
+	 *
+	 * @var array
+	 *  Edit/create form tabs.
+	 */
+	protected $preftabs = array(
+		LAN_GALLERY_ADMIN_02,
+		LAN_GALLERY_ADMIN_03,
+		LAN_GALLERY_ADMIN_32,
+	);
 
-	public function beforeCreate($new_data)
-	{
-
-		$replace = array("_", " ", "'", '"', "."); //FIXME Improve
-		$new_data['media_cat_category'] = strtolower(str_replace($replace, "", $new_data['media_cat_title']));
-		return $new_data;
-	}
-
-	function galleryPage()
-	{
-		$mes = e107::getMessage();
-		$tp = e107::getParser();
-
-		$x = LAN_PLUGIN_GALLERY_TITLE;
-		$y = "<a href='" . e_ADMIN . "image.php'>" . LAN_MEDIAMANAGER . "</a>";
-
-		$message = $tp->lanVars(LAN_GALLERY_ADMIN_01, array($x, $y), true);
-		$mes->addInfo($message);
-	}
-
-	protected $preftabs = array(LAN_GALLERY_ADMIN_02, LAN_GALLERY_ADMIN_03);
-
+	/**
+	 * Plugin Preference description array.
+	 *
+	 * @var array
+	 */
 	protected $prefs = array(
-		'popup_w'            => array(
+		'popup_w'                    => array(
 			'title' => LAN_GALLERY_ADMIN_04,
 			'tab'   => 0,
 			'type'  => 'text',
 			'data'  => 'int',
 			'help'  => LAN_GALLERY_ADMIN_05,
-			// 'validate' => 'regex',
-			// 'rule' => '#^[\d]+$#i',
-			// 'help' => 'allowed characters are a-zA-Z and underscore',
 		),
-		'popup_h'            => array(
+		'popup_h'                    => array(
 			'title' => LAN_GALLERY_ADMIN_06,
 			'tab'   => 0,
 			'type'  => 'text',
 			'data'  => 'int',
 			'help'  => LAN_GALLERY_ADMIN_07,
-			// 'validate' => 'regex',
-			// 'rule' => '#^[\d]+$#i',
-			// 'help' => 'allowed characters are a-zA-Z and underscore',
 		),
-		'downloadable'       => array(
+		'downloadable'               => array(
 			'title' => LAN_GALLERY_ADMIN_08,
 			'tab'   => 0,
 			'type'  => 'boolean',
 			'data'  => 'int',
 			'help'  => LAN_GALLERY_ADMIN_09,
-			// 'validate' => 'regex',
-			// 'rule' => '#^[\d]+$#i',
-			// 'help' => 'allowed characters are a-zA-Z and underscore',
 		),
-		'slideshow_category' => array(
+		'slideshow_category'         => array(
 			'title' => LAN_GALLERY_ADMIN_10,
 			'tab'   => 1,
 			'type'  => 'dropdown',
 			'data'  => 'str',
 			'help'  => LAN_GALLERY_ADMIN_11,
-			// 'validate' => 'regex',
-			// 'rule' => '#^[\d]+$#i',
-			// 'help' => 'allowed characters are a-zA-Z and underscore',
 		),
-		/*
-		'slideshow_thumb_w'  => array(
-			'title' => 'Thumbnail Width',
-			'type'  => 'number',
-			'data'  => 'integer',
-			'help'  => 'Width in px',
-			// 'validate' => 'regex',
-			// 'rule' => '#^[\d]+$#i',
-			// 'help' => 'allowed characters are a-zA-Z and underscore',
-		),
-		*/
-		/*
-		'slideshow_thumb_h'  => array(
-			'title' => 'Thumbnail Height',
-			'type'  => 'number',
-			'data'  => 'integer',
-			'help'  => 'Height in px',
-			// 'validate' => 'regex',
-			// 'rule' => '#^[\d]+$#i',
-			// 'help' => 'allowed characters are a-zA-Z and underscore',
-		),
-		*/
-		/*
-		'slideshow_perslide' => array(
-			'title' => 'Images per slide',
-			'type'  => 'number',
-			'data'  => 'integer',
-			'help'  => 'Number of images to show per slide.',
-			// 'validate' => 'regex',
-			// 'rule' => '#^[\d]+$#i',
-			// 'help' => 'allowed characters are a-zA-Z and underscore',
-		),
-		*/
-		'slideshow_duration' => array(
+		'slideshow_duration'         => array(
 			'title' => LAN_GALLERY_ADMIN_12,
 			'type'  => 'number',
 			'tab'   => 1,
 			'data'  => 'integer',
 			'help'  => LAN_GALLERY_ADMIN_13,
-			// 'validate' => 'regex',
-			// 'rule' => '#^[\d]+$#i',
-			// 'help' => 'allowed characters are a-zA-Z and underscore',
 		),
-		'slideshow_auto'     => array(
+		'slideshow_auto'             => array(
 			'title' => LAN_GALLERY_ADMIN_14,
 			'type'  => 'boolean',
 			'tab'   => 1,
 			'data'  => 'integer',
 			'help'  => LAN_GALLERY_ADMIN_15,
 		),
-		'slideshow_freq'     => array(
+		'slideshow_freq'             => array(
 			'title' => LAN_GALLERY_ADMIN_16,
 			'type'  => 'number',
 			'tab'   => 1,
 			'data'  => 'integer',
 			'help'  => LAN_GALLERY_ADMIN_17,
-			// 'validate' => 'regex',
-			// 'rule' => '#^[\d]+$#i',
-			// 'help' => 'allowed characters are a-zA-Z and underscore',
 		),
-		/*
-		'slideshow_circular' => array(
-			'title' => 'Slide circular-mode',
-			'type'  => 'boolean',
-			'data'  => 'integer',
-			'help'  => 'By default when the first/last slide is reached, calling prev/next does nothing. If you want the effect to continue enable this option.',
-		),
-		*/
-		'slideshow_effect'   => array(
+		'slideshow_effect'           => array(
 			'title' => LAN_GALLERY_ADMIN_18,
 			'type'  => 'dropdown',
 			'tab'   => 1,
 			'data'  => 'str',
 			'help'  => LAN_GALLERY_ADMIN_19
 		),
-		/*
-		'slideshow_transition' => array(
-			'title' => 'Slide transition',
-			'type'  => 'dropdown',
-			'data'  => 'str',
-			'help'  => 'Type of transition.',
-		),
-		*/
-		'perpage'            => array(
+		'perpage'                    => array(
 			'title' => LAN_GALLERY_ADMIN_20,
 			'tab'   => 0,
 			'type'  => 'number',
 			'data'  => 'int',
 			'help'  => LAN_GALLERY_ADMIN_21,
-			// 'rule' => '#^[\d]+$#i',
-			// 'help' => 'allowed characters are a-zA-Z and underscore',
 		),
-		'orderby'            => array(
+		'orderby'                    => array(
 			'title'      => LAN_GALLERY_ADMIN_22,
 			'tab'        => 0,
 			'type'       => 'dropdown',
@@ -360,9 +362,221 @@ class gallery_cat_admin_ui extends e_admin_ui
 				),
 			),
 		),
+		'pp_global'                  => array(
+			'title'      => LAN_GALLERY_ADMIN_70,
+			'type'       => 'boolean',
+			'data'       => 'int',
+			'writeParms' => array(
+				'default' => 1,
+			),
+			'tab'        => 2,
+		),
+		'pp_hook'                    => array(
+			'title'      => LAN_GALLERY_ADMIN_71,
+			'type'       => 'text',
+			'data'       => 'str',
+			'writeParms' => array(
+				'default' => 'data-gal',
+			),
+			'tab'        => 2,
+		),
+		'pp_animation_speed'         => array(
+			'title'      => LAN_GALLERY_ADMIN_33,
+			'type'       => 'dropdown',
+			'data'       => 'str',
+			'writeParms' => array(
+				'optArray' => array(
+					'fast'   => LAN_GALLERY_ADMIN_62,
+					'slow'   => LAN_GALLERY_ADMIN_63,
+					'normal' => LAN_GALLERY_ADMIN_64,
+				),
+			),
+			'tab'        => 2,
+		),
+		'pp_slideshow'               => array(
+			'title'      => LAN_GALLERY_ADMIN_34,
+			'type'       => 'text',
+			'data'       => 'int',
+			'writeParms' => array(
+				'default' => 5000,
+			),
+			'tab'        => 2,
+		),
+		'pp_autoplay_slideshow'      => array(
+			'title'      => LAN_GALLERY_ADMIN_35,
+			'type'       => 'boolean',
+			'data'       => 'int',
+			'writeParms' => array(
+				'default' => 0,
+			),
+			'tab'        => 2,
+		),
+		'pp_opacity'                 => array(
+			'title'      => LAN_GALLERY_ADMIN_36,
+			'help'       => LAN_GALLERY_ADMIN_37,
+			'type'       => 'text',
+			'data'       => 'int',
+			'writeParms' => array(
+				'default' => 0.80,
+			),
+			'tab'        => 2,
+		),
+		'pp_show_title'              => array(
+			'title'      => LAN_GALLERY_ADMIN_38,
+			'type'       => 'boolean',
+			'data'       => 'int',
+			'writeParms' => array(
+				'default' => 1,
+			),
+			'tab'        => 2,
+		),
+		'pp_allow_resize'            => array(
+			'title'      => LAN_GALLERY_ADMIN_39,
+			'help'       => LAN_GALLERY_ADMIN_40,
+			'type'       => 'boolean',
+			'data'       => 'int',
+			'writeParms' => array(
+				'default' => 1,
+			),
+			'tab'        => 2,
+		),
+		'pp_default_width'           => array(
+			'title'      => LAN_GALLERY_ADMIN_41,
+			'type'       => 'text',
+			'data'       => 'int',
+			'writeParms' => array(
+				'default' => 500,
+			),
+			'tab'        => 2,
+		),
+		'pp_default_height'          => array(
+			'title'      => LAN_GALLERY_ADMIN_42,
+			'type'       => 'text',
+			'data'       => 'int',
+			'writeParms' => array(
+				'default' => 344,
+			),
+			'tab'        => 2,
+		),
+		'pp_counter_separator_label' => array(
+			'title'      => LAN_GALLERY_ADMIN_43,
+			'help'       => LAN_GALLERY_ADMIN_44,
+			'type'       => 'text',
+			'data'       => 'str',
+			'writeParms' => array(
+				'default' => '/',
+			),
+			'tab'        => 2,
+		),
+		'pp_theme'                   => array(
+			'title'      => LAN_GALLERY_ADMIN_45,
+			'type'       => 'dropdown',
+			'data'       => 'str',
+			'writeParms' => array(
+				'optArray' => array(
+					'pp_default'    => LAN_DEFAULT,
+					'light_rounded' => LAN_GALLERY_ADMIN_65,
+					'dark_rounded'  => LAN_GALLERY_ADMIN_66,
+					'light_square'  => LAN_GALLERY_ADMIN_67,
+					'dark_square'   => LAN_GALLERY_ADMIN_68,
+					'facebook'      => LAN_GALLERY_ADMIN_69,
+				),
+			),
+			'tab'        => 2,
+		),
+		'pp_horizontal_padding'      => array(
+			'title'      => LAN_GALLERY_ADMIN_46,
+			'help'       => LAN_GALLERY_ADMIN_47,
+			'type'       => 'text',
+			'data'       => 'int',
+			'writeParms' => array(
+				'default' => 20,
+			),
+			'tab'        => 2,
+		),
+		'pp_hideflash'               => array(
+			'title'      => LAN_GALLERY_ADMIN_48,
+			'help'       => LAN_GALLERY_ADMIN_49,
+			'type'       => 'boolean',
+			'data'       => 'int',
+			'writeParms' => array(
+				'default' => 0,
+			),
+			'tab'        => 2,
+		),
+		'pp_wmode'                   => array(
+			'title'      => LAN_GALLERY_ADMIN_50,
+			'help'       => LAN_GALLERY_ADMIN_51,
+			'type'       => 'text',
+			'data'       => 'str',
+			'writeParms' => array(
+				'default' => 'opaque',
+			),
+			'tab'        => 2,
+		),
+		'pp_autoplay'                => array(
+			'title'      => LAN_GALLERY_ADMIN_52,
+			'type'       => 'boolean',
+			'data'       => 'int',
+			'writeParms' => array(
+				'default' => 1,
+			),
+			'tab'        => 2,
+		),
+		'pp_modal'                   => array(
+			'title'      => LAN_GALLERY_ADMIN_53,
+			'help'       => LAN_GALLERY_ADMIN_54,
+			'type'       => 'boolean',
+			'data'       => 'int',
+			'writeParms' => array(
+				'default' => 0,
+			),
+			'tab'        => 2,
+		),
+		'pp_deeplinking'             => array(
+			'title'      => LAN_GALLERY_ADMIN_55,
+			'help'       => LAN_GALLERY_ADMIN_56,
+			'type'       => 'boolean',
+			'data'       => 'int',
+			'writeParms' => array(
+				'default' => 0,
+			),
+			'tab'        => 2,
+		),
+		'pp_overlay_gallery'         => array(
+			'title'      => LAN_GALLERY_ADMIN_57,
+			'help'       => LAN_GALLERY_ADMIN_58,
+			'type'       => 'boolean',
+			'data'       => 'int',
+			'writeParms' => array(
+				'default' => 1,
+			),
+			'tab'        => 2,
+		),
+		'pp_keyboard_shortcuts'      => array(
+			'title'      => LAN_GALLERY_ADMIN_59,
+			'help'       => LAN_GALLERY_ADMIN_60,
+			'type'       => 'boolean',
+			'data'       => 'int',
+			'writeParms' => array(
+				'default' => 1,
+			),
+			'tab'        => 2,
+		),
+		'pp_ie6_fallback'            => array(
+			'title'      => LAN_GALLERY_ADMIN_61,
+			'type'       => 'boolean',
+			'data'       => 'int',
+			'writeParms' => array(
+				'default' => 1,
+			),
+			'tab'        => 2,
+		),
 	);
 
-
+	/**
+	 * Initial function.
+	 */
 	function init()
 	{
 		$effects = array(
@@ -374,11 +588,6 @@ class gallery_cat_admin_ui extends e_admin_ui
 		$this->prefs['slideshow_effect']['writeParms'] = $effects;
 		$this->prefs['slideshow_effect']['readParms'] = $effects;
 
-		//	$transitions = array('sinoidal'=>'sinoidal','spring'=>'spring');
-
-		//	$this->prefs['slideshow_transition']['writeParms'] 	= $transitions;
-		//	$this->prefs['slideshow_transition']['readParms'] 	= $transitions;
-
 		$categories = e107::getMedia()->getCategories('gallery');
 		$cats = array();
 		foreach($categories as $k => $var)
@@ -400,6 +609,34 @@ class gallery_cat_admin_ui extends e_admin_ui
 		$mes->addInfo($message);
 	}
 
+	/**
+	 * User defined pre-create logic, return false to prevent DB query execution.
+	 *
+	 * @param $new_data
+	 *  Posted data.
+	 * @param $old_data
+	 *
+	 * @return boolean
+	 */
+	public function beforeCreate($new_data, $old_data)
+	{
+		$replace = array("_", " ", "'", '"', "."); // FIXME Improve.
+		$new_data['media_cat_category'] = strtolower(str_replace($replace, "", $new_data['media_cat_title']));
+		return $new_data;
+	}
+
+	function galleryPage()
+	{
+		$mes = e107::getMessage();
+		$tp = e107::getParser();
+
+		$x = LAN_PLUGIN_GALLERY_TITLE;
+		$y = "<a href='" . e_ADMIN . "image.php'>" . LAN_MEDIAMANAGER . "</a>";
+
+		$message = $tp->lanVars(LAN_GALLERY_ADMIN_01, array($x, $y), true);
+		$mes->addInfo($message);
+	}
+
 }
 
 
@@ -409,8 +646,8 @@ class gallery_cat_admin_form_ui extends e_admin_form_ui
 	// Override the default Options field.
 	public function gallery_category_parent($curVal, $mode)
 	{
-		// TODO - catlist combo without current cat ID in write mode, parents only for batch/filter 
-		// Get UI instance
+		// TODO - catlist combo without current cat ID in write mode, parents only for batch/filter.
+		// Get UI instance.
 		$controller = $this->getController();
 		switch($mode)
 		{
@@ -428,6 +665,7 @@ class gallery_cat_admin_form_ui extends e_admin_form_ui
 				break;
 		}
 	}
+
 }
 
 
diff --git a/e107_plugins/gallery/controllers/index.php b/e107_plugins/gallery/controllers/index.php
index 979e95204..9ccaf7c68 100644
--- a/e107_plugins/gallery/controllers/index.php
+++ b/e107_plugins/gallery/controllers/index.php
@@ -22,10 +22,12 @@
  */
 /*
  * THIS SCRIPT IS HIGHLY EXPERIMENTAL. USE AT OWN RISK.
- *
  */
 
 
+/**
+ * Class plugin_gallery_index_controller.
+ */
 class plugin_gallery_index_controller extends eControllerFront
 {
 
@@ -65,11 +67,6 @@ class plugin_gallery_index_controller extends eControllerFront
 	public function init()
 	{
 		e107::plugLan('gallery', 'front');
-
-		e107::library('load', 'jquery.prettyPhoto');
-		e107::css('gallery', 'css/gallery.css');
-		e107::js('gallery', 'js/gallery.js');
-
 		$this->catList = e107::getMedia()->getCategories('gallery');
 	}
 
diff --git a/e107_plugins/gallery/e_header.php b/e107_plugins/gallery/e_header.php
index bc92835f0..46c02e2e8 100644
--- a/e107_plugins/gallery/e_header.php
+++ b/e107_plugins/gallery/e_header.php
@@ -20,3 +20,12 @@ if(USER_AREA)
 margin-left:0;
 }", 'jquery');
 }
+
+$plugPrefs = e107::getPlugConfig('gallery')->getPref();
+
+if(vartrue($plugPrefs['pp_global'], false))
+{
+	e107_require_once(e_PLUGIN . 'gallery/includes/gallery_load.php');
+	// Load prettyPhoto settings and files.
+	gallery_load_prettyphoto();
+}
diff --git a/e107_plugins/gallery/e_shortcode.php b/e107_plugins/gallery/e_shortcode.php
index a62f54ad8..c15d2abf3 100644
--- a/e107_plugins/gallery/e_shortcode.php
+++ b/e107_plugins/gallery/e_shortcode.php
@@ -25,26 +25,23 @@ class gallery_shortcodes extends e_shortcode
 	public  $sliderCat    = 1;
 	public  $slideMode    = false;
 	public  $slideCount   = 1;
-	private $downloadable = false;
 	private $attFull      = null;
 
 	function init()
 	{
-		$this->downloadable = e107::getPlugPref('gallery', 'downloadable');
 		$prefW = e107::getPlugPref('gallery', 'pop_w');
 		$prefH = e107::getPlugPref('gallery', 'pop_h');
 		$pop_w = vartrue($prefW, 1024);
 		$pop_h = vartrue($prefH, 768);
 		$this->attFull = array('w' => $pop_w, 'h' => $pop_h, 'x' => 1, 'crop' => 0); // 'w='.$pop_w.'&h='.$pop_h.'&x=1';
-
-		e107::library('load', 'jquery.prettyPhoto');
-		e107::js('gallery', 'js/gallery.js');
 	}
 
 	function sc_gallery_caption($parm = '')
 	{
+		$plugPrefs = e107::getPlugConfig('gallery')->getPref();
+		$hook = varset($plugPrefs['pp_hook'], 'data-gal');
 		$tp = e107::getParser();
-		$text = "<a class='gallery-caption' title='" . $tp->toAttribute($this->var['media_caption']) . "' href='" . $tp->thumbUrl($this->var['media_url'], $this->attFull) . "' data-gal='prettyPhoto[slide]' >";     // Erase  rel"lightbox.Gallery2"  - Write "prettyPhoto[slide]"
+		$text = "<a class='gallery-caption' title='" . $tp->toAttribute($this->var['media_caption']) . "' href='" . $tp->thumbUrl($this->var['media_url'], $this->attFull) . "' " . $hook . "='prettyPhoto[slide]' >";     // Erase  rel"lightbox.Gallery2"  - Write "prettyPhoto[slide]"
 		$text .= $this->var['media_caption'];
 		$text .= "</a>";
 		return $text;
@@ -81,6 +78,9 @@ class gallery_shortcodes extends e_shortcode
 	 */
 	function sc_gallery_thumb($parm = '')
 	{
+		$plugPrefs = e107::getPlugConfig('gallery')->getPref();
+		$hook = varset($plugPrefs['pp_hook'], 'data-gal');
+
 		$tp = e107::getParser();
 		$parms = eHelper::scParams($parm);
 
@@ -88,8 +88,7 @@ class gallery_shortcodes extends e_shortcode
 		$h = vartrue($parms['h']) ? $parms['h'] : $tp->thumbHeight(); // 130;
 
 		$class = ($this->slideMode == true) ? 'gallery-slideshow-thumb img-responsive img-rounded' : varset($parms['class'], 'gallery-thumb img-responsive');
-		//	$rel 		= ($this->slideMode == TRUE) ? 'lightbox.SlideGallery' : 'lightbox.Gallery';
-		$rel = ($this->slideMode == true) ? 'prettyPhoto[slide]' : 'prettyPhoto[gal]';
+		$rel = ($this->slideMode == true) ? 'prettyPhoto[pp_gal]' : 'prettyPhoto[pp_gal]';
 
 		//$att        = array('aw'=>$w, 'ah'=>$h, 'x'=>1, 'crop'=>1);
 		$caption = $tp->toAttribute($this->var['media_caption']);
@@ -116,12 +115,9 @@ class gallery_shortcodes extends e_shortcode
 			return $tp->replaceConstants($this->var['media_url'], 'full');
 		}
 
+		$description = $tp->toAttribute($this->var['media_description']);
 
-		$description = ($this->downloadable) ? " <a class='btn btn-xs btn-default btn-mini e-tip' title='" . LAN_GALLERY_FRONT_01 . "' href='" . $srcFull . "'>" . LAN_DOWNLOAD . "</a>" : "";
-		$description .= $tp->toAttribute($this->var['media_description']);
-
-		$text = "<a class='" . $class . "' title=\"" . $description . "\" href='" . $srcFull . "'  data-gal='{$rel}'  >";
-
+		$text = "<a class='" . $class . "' title='" . $description . "' href='" . $srcFull . "' " . $hook . "='" . $rel . "'>";
 		$text .= $tp->toImage($this->var['media_url'], $att);
 		$text .= "</a>";
 
@@ -295,7 +291,7 @@ class gallery_shortcodes extends e_shortcode
 
 	function sc_gallery_jumper($parm)
 	{
-		// echo "SlideCount=".$this->slideCount;
+		// echo "SlideCount=".$this->slideCount; 
 		if($this->slideCount == 1 && deftrue('E107_DBG_BASIC'))
 		{
 			return "gallery-jumper must be loaded after Gallery-Slides";
diff --git a/e107_plugins/gallery/gallery.php b/e107_plugins/gallery/gallery.php
index 5f4cf369e..16b0bb46d 100644
--- a/e107_plugins/gallery/gallery.php
+++ b/e107_plugins/gallery/gallery.php
@@ -1,24 +1,14 @@
 <?php
-/*
+
+/**
  * e107 website system
  *
  * Copyright (C) 2008-2012 e107 Inc (e107.org)
  * Released under the terms and conditions of the
  * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
  *
- * Cron Administration
- *
- * $URL: https://e107.svn.sourceforge.net/svnroot/e107/trunk/e107_0.8/e107_admin/cron.php $
- * $Id: cron.php 12492 2011-12-30 16:09:10Z e107steved $
- *
- */
-
-/**
- *
- * @package     e107
- * @subpackage    frontend
- * @version     $Id: cron.php 12492 2011-12-30 16:09:10Z e107steved $
- *    Ultra-simple Image-Gallery
+ * @file
+ * Render gallery pages.
  */
 
 require_once("../../class2.php");
@@ -29,16 +19,22 @@ if(!e107::isInstalled('gallery'))
 	exit;
 }
 
+e107_require_once(e_PLUGIN . 'gallery/includes/gallery_load.php');
+
 // [PLUGINS]/gallery/languages/[LANGUAGE]/[LANGUAGE]_front.php
 e107::lan('gallery', false, true);
 
-e107::library('load', 'jquery.prettyPhoto');
 e107::css('gallery', 'css/gallery.css');
-e107::js('gallery', 'js/gallery.js');
+
+// Load prettyPhoto settings and files.
+gallery_load_prettyphoto();
 
 require_once(HEADERF);
 
 
+/**
+ * Class gallery.
+ */
 class gallery
 {
 
diff --git a/e107_plugins/gallery/gallery_setup.php b/e107_plugins/gallery/gallery_setup.php
index 652a90e3d..f0c7d6673 100644
--- a/e107_plugins/gallery/gallery_setup.php
+++ b/e107_plugins/gallery/gallery_setup.php
@@ -1,53 +1,78 @@
 <?php
-/*
-* e107 website system
-*
-* Copyright (C) 2008-2012 e107 Inc (e107.org)
-* Released under the terms and conditions of the
-* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
-*
-* Custom download install/uninstall/update routines
-*
-* $Source: /cvs_backup/e107_0.8/e107_plugins/download/download_setup.php,v $
-* $Revision: 12639 $
-* $Date: 2012-04-20 00:28:53 -0700 (Fri, 20 Apr 2012) $
-* $Author: e107coders $
-*
-*/
 
+/**
+ * e107 website system
+ *
+ * Copyright (C) 2008-2012 e107 Inc (e107.org)
+ * Released under the terms and conditions of the
+ * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
+ *
+ * @file
+ * Custom install/uninstall/update routines.
+ */
+
+
+/**
+ * Class gallery_setup.
+ */
 class gallery_setup
 {
-	
+
+	/**
+	 * This function is called before plugin table has been created by the
+	 * [PLUGIN]_sql.php file.
+	 *
+	 * @param array $var
+	 */
 	function install_pre($var)
 	{
-		// print_a($var);
-		$mes = eMessage::getInstance();
-		// $mes->add("custom install 'pre' function.", E_MESSAGE_SUCCESS);
+
 	}
 
+	/**
+	 * This function is called after plugin table has been created by the
+	 * [PLUGIN]_sql.php file.
+	 *
+	 * @param array $var
+	 */
 	function install_post($var)
 	{
-		$sql = e107::getDb();
-		$mes = eMessage::getInstance();
-		// $mes->add("custom install 'post' function.", E_MESSAGE_SUCCESS);
+
 	}
 
 	function uninstall_pre($var)
 	{
-		$sql = e107::getDb();
-		$mes = eMessage::getInstance();
-		// $mes->add("custom uninstall 'pre' function.", E_MESSAGE_SUCCESS);
+
 	}
 
-
-	// IMPORTANT : This function below is for modifying the CONTENT of the tables only, NOT the table-structure. 
-	// To Modify the table-structure, simply modify your {plugin}_sql.php file and an update will be detected automatically. 
-	/*
-	 * @var $needed - true when only a check for a required update is being performed.
-	 * Return: Reason the upgrade is required, otherwise set it to return FALSE. 
-	 */
-	function upgrade_post($needed)
+	function uninstall_options()
 	{
-	
 	}
+
+	function uninstall_post($var)
+	{
+	}
+
+	/**
+	 * Trigger an upgrade alert or not.
+	 *
+	 * @param array $var
+	 *
+	 * @return bool
+	 *  True to trigger an upgrade alert, and false to not.
+	 */
+	function upgrade_required($var)
+	{
+		return false;
+	}
+
+	function upgrade_pre($var)
+	{
+	}
+
+	function upgrade_post($var)
+	{
+
+	}
+
 }
diff --git a/e107_plugins/gallery/includes/gallery_load.php b/e107_plugins/gallery/includes/gallery_load.php
new file mode 100644
index 000000000..1f4954ecf
--- /dev/null
+++ b/e107_plugins/gallery/includes/gallery_load.php
@@ -0,0 +1,77 @@
+<?php
+
+/**
+ * e107 website system
+ *
+ * Copyright (C) 2008-2012 e107 Inc (e107.org)
+ * Released under the terms and conditions of the
+ * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
+ *
+ * @file
+ * Helper functions for "gallery" plugin.
+ */
+
+/**
+ * Helper function to load prettyPhoto library's settings and files.
+ */
+function gallery_load_prettyphoto()
+{
+	// Re-use the statically cached value to save memory. Load settings and files only once!!!
+	static $gallery_load_prettyphoto;
+
+	if(!isset($gallery_load_prettyphoto['loaded']) || !$gallery_load_prettyphoto['loaded'])
+	{
+		$tp = e107::getParser();
+		$plugPref = e107::getPlugConfig('gallery')->getPref();
+		$template = e107::getTemplate('gallery');
+
+		// Load prettyPhoto library.
+		e107::library('load', 'jquery.prettyPhoto');
+
+		$settings = array(
+			'prettyphoto' => array(
+				'hook'                    => $tp->toText(varset($plugPref['pp_hook'], 'data-gal')),
+				'animation_speed'         => $tp->toText(varset($plugPref['pp_animation_speed'], 'fast')),
+				'slideshow'               => (int) varset($plugPref['pp_slideshow'], 5000),
+				'autoplay_slideshow'      => (bool) varset($plugPref['pp_autoplay_slideshow'], false),
+				'opacity'                 => (float) varset($plugPref['pp_opacity'], 0.80),
+				'show_title'              => (bool) varset($plugPref['pp_show_title'], true),
+				'allow_resize'            => (bool) varset($plugPref['pp_allow_resize'], true),
+				'default_width'           => (int) varset($plugPref['pp_default_width'], 500),
+				'default_height'          => (int) varset($plugPref['pp_default_height'], 344),
+				'counter_separator_label' => $tp->toText(varset($plugPref['pp_counter_separator_label'], '/')),
+				'theme'                   => $tp->toText(varset($plugPref['pp_theme'], 'pp_default')),
+				'horizontal_padding'      => (int) varset($plugPref['pp_horizontal_padding'], 20),
+				'hideflash'               => (bool) varset($plugPref['pp_hideflash'], false),
+				'wmode'                   => $tp->toText(varset($plugPref['pp_wmode'], 'opaque')),
+				'autoplay'                => (bool) varset($plugPref['pp_autoplay'], true),
+				'modal'                   => (bool) varset($plugPref['pp_modal'], false),
+				'deeplinking'             => (bool) varset($plugPref['pp_deeplinking'], false),
+				'overlay_gallery'         => (bool) varset($plugPref['pp_overlay_gallery'], true),
+				'keyboard_shortcuts'      => (bool) varset($plugPref['pp_keyboard_shortcuts'], true),
+				'ie6_fallback'            => (bool) varset($plugPref['pp_ie6_fallback'], true),
+				'markup'                  => str_replace(array("\r", "\n", "\t"), '', $template['prettyphoto']['markup']),
+				'gallery_markup'          => str_replace(array("\r", "\n", "\t"), '', $template['prettyphoto']['gallery_markup']),
+				'image_markup'            => str_replace(array("\r", "\n", "\t"), '', $template['prettyphoto']['image_markup']),
+				'flash_markup'            => str_replace(array("\r", "\n", "\t"), '', $template['prettyphoto']['flash_markup']),
+				'quicktime_markup'        => str_replace(array("\r", "\n", "\t"), '', $template['prettyphoto']['quicktime_markup']),
+				'iframe_markup'           => str_replace(array("\r", "\n", "\t"), '', $template['prettyphoto']['iframe_markup']),
+				'inline_markup'           => str_replace(array("\r", "\n", "\t"), '', $template['prettyphoto']['inline_markup']),
+				'custom_markup'           => str_replace(array("\r", "\n", "\t"), '', $template['prettyphoto']['custom_markup']),
+				'social_tools'            => str_replace(array("\r", "\n", "\t"), '', $template['prettyphoto']['social_tools']),
+			),
+		);
+
+		if(vartrue($plugPref['downloadable'], false))
+		{
+			$settings['prettyphoto']['image_markup'] .= '<span class="download-btn">';
+			$settings['prettyphoto']['image_markup'] .= '<a class="btn btn-default btn-xs" href="{path}">' . LAN_DOWNLOAD . '</a>';
+			$settings['prettyphoto']['image_markup'] .= '</span>';
+		}
+
+		e107::js('settings', array('gallery' => $settings));
+		e107::js('gallery', 'js/gallery.js');
+
+		$gallery_load_prettyphoto['loaded'] = true;
+	}
+}
diff --git a/e107_plugins/gallery/js/gallery.js b/e107_plugins/gallery/js/gallery.js
index e3e3c55c5..4f20312f0 100644
--- a/e107_plugins/gallery/js/gallery.js
+++ b/e107_plugins/gallery/js/gallery.js
@@ -11,14 +11,47 @@ var e107 = e107 || {'settings': {}, 'behaviors': {}};
 	e107.behaviors.gallery = {
 		attach: function (context, settings)
 		{
-			$(context).find("a[data-gal^='prettyPhoto']").once('gallery-prettyPhoto').each(function ()
+			var pPhoto = settings.gallery.prettyphoto || {};
+			var pPhook = pPhoto.hook || 'data-gal';
+
+			$(context).find("a[" + pPhook + "^='prettyPhoto']").once('gallery-prettyPhoto').each(function ()
 			{
 				$(this).prettyPhoto(
 					{
-						hook: 'data-gal',
-						theme: 'pp_default', /* pp_default , light_rounded , dark_rounded , light_square , dark_square ,facebook */
-						overlay_gallery: false,
-						deeplinking: false
+						hook: pPhook,
+						animation_speed: pPhoto.animation_speed || 'fast', // fast/slow/normal
+						slideshow: pPhoto.slideshow || 5000, // false OR interval time in ms
+						autoplay_slideshow: pPhoto.autoplay_slideshow || false, // true/false
+						opacity: pPhoto.opacity || 0.80, // Value between 0 and 1
+						show_title: pPhoto.show_title || true, // true/false
+						allow_resize: pPhoto.allow_resize || true, // Resize the photos bigger than viewport. true/false
+						default_width: pPhoto.default_width || 500,
+						default_height: pPhoto.default_height || 344,
+						counter_separator_label: pPhoto.counter_separator_label || '/', // The separator for the gallery counter 1 "of" 2
+						theme: pPhoto.theme || 'pp_default', // light_rounded / dark_rounded / light_square / dark_square / facebook
+						horizontal_padding: pPhoto.horizontal_padding || 20, // The padding on each side of the picture
+						hideflash: pPhoto.hideflash || false, // Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto
+						wmode: pPhoto.wmode || 'opaque', // Set the flash wmode attribute
+						autoplay: pPhoto.autoplay || true, // Automatically start videos: true/false
+						modal: pPhoto.modal || false, // If set to true, only the close button will close the window
+						deeplinking: pPhoto.deeplinking || false, // Allow prettyPhoto to update the url to enable deeplinking.
+						overlay_gallery: pPhoto.overlay_gallery || true, // If set to true, a gallery will overlay the fullscreen image on mouse over
+						keyboard_shortcuts: pPhoto.keyboard_shortcuts || true, // Set to false if you open forms inside prettyPhoto
+						ie6_fallback: pPhoto.ie6_fallback || true, // true/false
+						markup: pPhoto.markup || null,
+						gallery_markup: pPhoto.gallery_markup || null,
+						image_markup: pPhoto.image_markup || null,
+						flash_markup: pPhoto.flash_markup || null,
+						quicktime_markup: pPhoto.quicktime_markup || null,
+						iframe_markup: pPhoto.iframe_markup || null,
+						inline_markup: pPhoto.inline_markup || null,
+						custom_markup: pPhoto.custom_markup || null,
+						social_tools: pPhoto.social_tools || null,
+						changepicturecallback: function ()
+						{
+							var $ppContent = $(".pp_content");
+							$ppContent.css("height", $ppContent.height() + jQuery(".download-btn").outerHeight() + 10);
+						}
 					}
 				);
 			});
diff --git a/e107_plugins/gallery/languages/English/English_admin.php b/e107_plugins/gallery/languages/English/English_admin.php
index 63b0c4795..65fd10074 100644
--- a/e107_plugins/gallery/languages/English/English_admin.php
+++ b/e107_plugins/gallery/languages/English/English_admin.php
@@ -36,3 +36,47 @@ define("LAN_GALLERY_ADMIN_28", "Media Caption DESC");
 define("LAN_GALLERY_ADMIN_29", "slide left");
 define("LAN_GALLERY_ADMIN_30", "slide down");
 define("LAN_GALLERY_ADMIN_31", "fade");
+
+define("LAN_GALLERY_ADMIN_32", "prettyPhoto settings");
+define("LAN_GALLERY_ADMIN_33", "Animation speed");
+define("LAN_GALLERY_ADMIN_34", "Slideshow: Interval time");
+define("LAN_GALLERY_ADMIN_35", "Slideshow: Autoplay");
+define("LAN_GALLERY_ADMIN_36", "Opacity");
+define("LAN_GALLERY_ADMIN_37", "Value between 0 and 1.");
+define("LAN_GALLERY_ADMIN_38", "Show title");
+define("LAN_GALLERY_ADMIN_39", "Allow resize");
+define("LAN_GALLERY_ADMIN_40", "Resize the photos bigger than viewport.");
+define("LAN_GALLERY_ADMIN_41", "Default width");
+define("LAN_GALLERY_ADMIN_42", "Default height");
+define("LAN_GALLERY_ADMIN_43", "Counter separator label");
+define("LAN_GALLERY_ADMIN_44", "The separator for the gallery counter 1 \"of\" 2");
+define("LAN_GALLERY_ADMIN_45", "Theme");
+define("LAN_GALLERY_ADMIN_46", "Horizontal padding");
+define("LAN_GALLERY_ADMIN_47", "The padding on each side of the picture.");
+define("LAN_GALLERY_ADMIN_48", "Hide flash");
+define("LAN_GALLERY_ADMIN_49", "Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto.");
+define("LAN_GALLERY_ADMIN_50", "Wmode");
+define("LAN_GALLERY_ADMIN_51", "Set the flash wmode attribute.");
+define("LAN_GALLERY_ADMIN_52", "Autoplay videos");
+define("LAN_GALLERY_ADMIN_53", "Modal close");
+define("LAN_GALLERY_ADMIN_54", "If set to true, only the close button will close the window.");
+define("LAN_GALLERY_ADMIN_55", "Deep-linking");
+define("LAN_GALLERY_ADMIN_56", "Allow prettyPhoto to update the url to enable deep-linking.");
+define("LAN_GALLERY_ADMIN_57", "Overlay gallery");
+define("LAN_GALLERY_ADMIN_58", "If set to true, a gallery will overlay the fullscreen image on mouse over.");
+define("LAN_GALLERY_ADMIN_59", "Keyboard shortcuts");
+define("LAN_GALLERY_ADMIN_60", "Set to false if you open forms inside prettyPhoto.");
+define("LAN_GALLERY_ADMIN_61", "IE6 fallback");
+
+define("LAN_GALLERY_ADMIN_62", "fast");
+define("LAN_GALLERY_ADMIN_63", "slow");
+define("LAN_GALLERY_ADMIN_64", "normal");
+
+define("LAN_GALLERY_ADMIN_65", "Light rounded");
+define("LAN_GALLERY_ADMIN_66", "Dark rounded");
+define("LAN_GALLERY_ADMIN_67", "Light square");
+define("LAN_GALLERY_ADMIN_68", "Dark square");
+define("LAN_GALLERY_ADMIN_69", "Facebook");
+
+define("LAN_GALLERY_ADMIN_70", "Load prettyPhoto globally");
+define("LAN_GALLERY_ADMIN_71", "prettyPhoto attribute (hook)");
diff --git a/e107_plugins/gallery/plugin.xml b/e107_plugins/gallery/plugin.xml
index 5e412ec23..60aec9d1f 100644
--- a/e107_plugins/gallery/plugin.xml
+++ b/e107_plugins/gallery/plugin.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<e107Plugin name="Gallery" lan="LAN_PLUGIN_GALLERY_TITLE" version="1.0" date="2012-08-01" compatibility="2.0" installRequired="true">
+<e107Plugin name="Gallery" lan="LAN_PLUGIN_GALLERY_TITLE" version="1.1" date="2016-03-30" compatibility="2.0" installRequired="true">
 	<author name="e107 Inc." url="http://e107.org" />
 	<description lan="LAN_PLUGIN_GALLERY_DIZ">A simple image gallery</description>
 	<category>content</category>
@@ -24,5 +24,26 @@
 		<pref name="slideshow_effect">scrollHorz</pref>	
 		<pref name="perpage">12</pref>
 		<pref name="orderby">media_id DESC</pref>
+		<pref name="pp_global">1</pref>
+		<pref name="pp_hook">data-gal</pref>
+		<pref name="pp_animation_speed">fast</pref>
+		<pref name="pp_slideshow">5000</pref>
+		<pref name="pp_autoplay_slideshow">0</pref>
+		<pref name="pp_opacity">0.80</pref>
+		<pref name="pp_show_title">1</pref>
+		<pref name="pp_allow_resize">1</pref>
+		<pref name="pp_default_width">500</pref>
+		<pref name="pp_default_height">344</pref>
+		<pref name="pp_counter_separator_label">/</pref>
+		<pref name="pp_theme">pp_default</pref>
+		<pref name="pp_horizontal_padding">20</pref>
+		<pref name="pp_hideflash">0</pref>
+		<pref name="pp_wmode">opaque</pref>
+		<pref name="pp_autoplay">1</pref>
+		<pref name="pp_modal">0</pref>
+		<pref name="pp_deeplinking">0</pref>
+		<pref name="pp_overlay_gallery">1</pref>
+		<pref name="pp_keyboard_shortcuts">1</pref>
+		<pref name="pp_ie6_fallback">1</pref>
 	</pluginPrefs>
 </e107Plugin>
diff --git a/e107_plugins/gallery/slideshow_menu.php b/e107_plugins/gallery/slideshow_menu.php
index 0e690d8af..8e833f477 100644
--- a/e107_plugins/gallery/slideshow_menu.php
+++ b/e107_plugins/gallery/slideshow_menu.php
@@ -1,25 +1,33 @@
 <?php
-/*
-* Copyright (c) 2012 e107 Inc e107.org, Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
-* $Id: e_shortcode.php 12438 2011-12-05 15:12:56Z secretr $
-*
-* Gallery Template 
-*/
+
+/**
+ * e107 website system
+ *
+ * Copyright (C) 2008-2012 e107 Inc (e107.org)
+ * Released under the terms and conditions of the
+ * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
+ *
+ * @file
+ * Render gallery menu.
+ */
 
 if(!defined('e107_INIT'))
 {
 	exit;
 }
 
+e107_require_once(e_PLUGIN . 'gallery/includes/gallery_load.php');
+
 e107::plugLan('gallery', 'front');
 
 $gp = e107::getPlugPref('gallery');
 
-e107::library('load', 'jquery.cycle');
-e107::library('load', 'jquery.prettyPhoto');
-
 e107::css('gallery', 'css/gallery.css');
-e107::js('gallery', 'js/gallery.js');
+
+// Load prettyPhoto settings and files.
+gallery_load_prettyphoto();
+
+e107::library('load', 'jquery.cycle');
 e107::js('gallery', 'js/gallery.cycle.js');
 
 $settings = array(
diff --git a/e107_plugins/gallery/templates/gallery_template.php b/e107_plugins/gallery/templates/gallery_template.php
index 337870fc5..12c758969 100644
--- a/e107_plugins/gallery/templates/gallery_template.php
+++ b/e107_plugins/gallery/templates/gallery_template.php
@@ -1,83 +1,181 @@
 <?php
-/*
-* Copyright (c) 2012 e107 Inc e107.org, Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
-* $Id: e_shortcode.php 12438 2011-12-05 15:12:56Z secretr $
-*
-* Gallery Template 
-*/
+
+/**
+ * Copyright (c) 2012 e107 Inc e107.org, Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
+ *
+ * @file
+ * Templates for "gallery" plugin.
+ */
 
 
 $GALLERY_TEMPLATE['list_caption'] = LAN_PLUGIN_GALLERY_TITLE;
-  
-$GALLERY_TEMPLATE['list_start'] = 
-	'{GALLERY_BREADCRUMB}
-	<div class="row gallery">
-	';
 
-		
-$GALLERY_TEMPLATE['list_item'] =  '
- <div class="span2 col-xs-6 col-md-3">
-	<div class="thumbnail">
-		{GALLERY_THUMB=w=300&h=200}
-		<h5>{GALLERY_CAPTION}</h5>
+$GALLERY_TEMPLATE['list_start'] = '{GALLERY_BREADCRUMB}
+<div class="row gallery">
+';
+
+$GALLERY_TEMPLATE['list_item'] = '
+	<div class="span2 col-xs-6 col-md-3">
+		<div class="thumbnail">
+			{GALLERY_THUMB=w=300&h=200}
+			<h5>{GALLERY_CAPTION}</h5>
+		</div>
 	</div>
-</div>';
+';
 
-$GALLERY_TEMPLATE['list_end'] = 
-	"</div>
-	<div class='center' >
-		<div class='gallery-list-nextprev'>{GALLERY_NEXTPREV}</div>
-		<div class='gallery-list-back'><a class='btn btn-default' href='{GALLERY_BASEURL}'>".LAN_BACK."</a></div>
+$GALLERY_TEMPLATE['list_end'] = '
+</div>
+<div class="center">
+	<div class="gallery-list-nextprev">{GALLERY_NEXTPREV}</div>
+	<div class="gallery-list-back">
+		<a class="btn btn-default" href="{GALLERY_BASEURL}">' . LAN_BACK . '</a>
 	</div>
-";
-	
-// Bootstrap3 Compatible. 	
+</div>
+';
 
+// Bootstrap3 Compatible.
 $GALLERY_TEMPLATE['cat_caption'] = LAN_PLUGIN_GALLERY_TITLE;
 
-$GALLERY_TEMPLATE['cat_start'] = 
-	'{GALLERY_BREADCRUMB}
-	<div class="row gallery-cat">';
-	
-	    
+$GALLERY_TEMPLATE['cat_start'] = '{GALLERY_BREADCRUMB}
+<div class="row gallery-cat">
+';
+
 $GALLERY_TEMPLATE['cat_item'] = '
- <div class="span3 col-xs-6 col-md-3">
-	<div >
-		{GALLERY_CAT_THUMB}
-		<h3>{GALLERY_CAT_TITLE}</h3>
+	<div class="span3 col-xs-6 col-md-3">
+		<div>
+			{GALLERY_CAT_THUMB}
+			<h3>{GALLERY_CAT_TITLE}</h3>
+		</div>
 	</div>
-</div>';
+';
 
-
-$GALLERY_TEMPLATE['cat_end'] = 
-	"</div>
-	";	
-	
-	
+$GALLERY_TEMPLATE['cat_end'] = '
+</div>
+';
 
 // {GALLERY_SLIDESHOW=X}  X = Gallery Category. Default: 1 (ie. 'gallery_1') Overrides preference in admin. 
 // {GALLERY_SLIDES=X}  X = number of items per slide. 
 // {GALLERY_JUMPER=space} will remove numbers and just leave spaces. 
 
 $GALLERY_TEMPLATE['slideshow_wrapper'] = '
-			
-			<div id="gallery-slideshow-wrapper">
-			    <div id="gallery-slideshow-content" >
-			        {GALLERY_SLIDES=4}
-			    </div>
-			</div>
-			
-			<div class="gallery-slideshow-controls">		
-            	<a href="#" class="gallery-control gal-next btn btn-xs btn-default" style="float: right">Next {GLYPH=fa-chevron-right}</a>           
-                <a href="#" class="gallery-control gal-prev btn btn-xs btn-default" >{GLYPH=fa-chevron-left} Previous</a>
-                <span class="gallery-slide-jumper-container">{GALLERY_JUMPER}</span>
-            </div>
-         
-            
-		';	
+<div id="gallery-slideshow-wrapper">
+	<div id="gallery-slideshow-content">
+		{GALLERY_SLIDES=4}
+	</div>
+</div>
+
+<div class="gallery-slideshow-controls">
+	<a href="#" class="gallery-control gal-next btn btn-xs btn-default pull-right">
+		' . LAN_NEXT . ' {GLYPH=fa-chevron-right}
+	</a>
+	<a href="#" class="gallery-control gal-prev btn btn-xs btn-default">
+		{GLYPH=fa-chevron-left} ' . LAN_PREVIOUS . '
+	</a>
+	<span class="gallery-slide-jumper-container">
+		{GALLERY_JUMPER}
+	</span>
+</div>
+';
 
 $GALLERY_TEMPLATE['slideshow_slide_item'] = '<span class="gallery-slide-item">{GALLERY_THUMB: w=150&h=120}</span>';
 
-		
+$GALLERY_TEMPLATE['prettyphoto']['markup'] = '
+<div class="pp_pic_holder">
+	<div class="ppt">&nbsp;</div>
+	<div class="pp_top">
+		<div class="pp_left"></div>
+		<div class="pp_middle"></div>
+		<div class="pp_right"></div>
+	</div>
+	<div class="pp_content_container">
+		<div class="pp_left">
+			<div class="pp_right">
+				<div class="pp_content">
+					<div class="pp_loaderIcon"></div>
+					<div class="pp_fade">
+						<a href="#" class="pp_expand" title="Expand the image">' . LAN_EXPAND . '</a>
+						<div class="pp_hoverContainer">
+							<a class="pp_next" href="#">' . LAN_NEXT . '</a>
+							<a class="pp_previous" href="#">' . LAN_PREVIOUS . '</a>
+						</div>
+						<div id="pp_full_res"></div>
+						<div class="pp_details">
+							<div class="pp_nav">
+								<a href="#" class="pp_arrow_previous">' . LAN_PREVIOUS . '</a>
+								<p class="currentTextHolder">0/0</p>
+								<a href="#" class="pp_arrow_next">' . LAN_NEXT . '</a>
+							</div>
+							<p class="pp_description"></p>
+							{pp_social}
+							<a class="pp_close" href="#">' . LAN_CLOSE . '</a>
+						</div>
+					</div>
+				</div>
+			</div>
+		</div>
+	</div>
+	<div class="pp_bottom">
+		<div class="pp_left"></div>
+		<div class="pp_middle"></div>
+		<div class="pp_right"></div>
+	</div>
+</div>
+<div class="pp_overlay"></div>
+';
 
-?>
\ No newline at end of file
+$GALLERY_TEMPLATE['prettyphoto']['gallery_markup'] = '
+<div class="pp_gallery">
+	<a href="#" class="pp_arrow_previous">' . LAN_PREVIOUS . '</a>
+	<div>
+		<ul>
+			{gallery}
+		</ul>
+	</div>
+	<a href="#" class="pp_arrow_next">' . LAN_NEXT . '</a>
+</div>
+';
+
+$GALLERY_TEMPLATE['prettyphoto']['image_markup'] = '
+<img id="fullResImage" src="{path}" />
+';
+
+$GALLERY_TEMPLATE['prettyphoto']['flash_markup'] = '
+<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{width}" height="{height}">
+	<param name="wmode" value="{wmode}" />
+	<param name="allowfullscreen" value="true" />
+	<param name="allowscriptaccess" value="always" />
+	<param name="movie" value="{path}" />
+	<embed src="{path}" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="{width}" height="{height}" wmode="{wmode}"></embed>
+</object>
+';
+
+$GALLERY_TEMPLATE['prettyphoto']['quicktime_markup'] = '
+<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="{height}" width="{width}">
+	<param name="src" value="{path}">
+	<param name="autoplay" value="{autoplay}">
+	<param name="type" value="video/quicktime">
+	<embed src="{path}" height="{height}" width="{width}" autoplay="{autoplay}" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed>
+</object>
+';
+
+$GALLERY_TEMPLATE['prettyphoto']['iframe_markup'] = '
+<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>
+';
+
+$GALLERY_TEMPLATE['prettyphoto']['inline_markup'] = '
+<div class="pp_inline">{content}</div>
+';
+
+$GALLERY_TEMPLATE['prettyphoto']['custom_markup'] = '';
+
+$GALLERY_TEMPLATE['prettyphoto']['social_tools'] = '
+<div class="pp_social">
+	<div class="twitter">
+		<a href="http://twitter.com/share" class="twitter-share-button" data-count="none">' . LAN_SHARE . '</a>
+		<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
+	</div>
+	<div class="facebook">
+		<iframe src="http://www.facebook.com/plugins/like.php?locale=en_US&href=\'+location.href+\'&amp;layout=button_count&amp;show_faces=true&amp;width=500&amp;action=like&amp;font&amp;colorscheme=light&amp;height=23" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:23px;" allowTransparency="true"></iframe>
+	</div>
+</div>
+';
diff --git a/e107_plugins/gallery/url/rewrite_url.php b/e107_plugins/gallery/url/rewrite_url.php
index b5859b01e..1899cef6d 100644
--- a/e107_plugins/gallery/url/rewrite_url.php
+++ b/e107_plugins/gallery/url/rewrite_url.php
@@ -4,7 +4,7 @@
 /*
  * Copyright (C) e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
  * $Id$
- * 
+ *
  * System routing config
  */
 
@@ -31,7 +31,7 @@ class plugin_gallery_rewrite_url extends eUrlConfig
 			// rule set array
 			'rules'  => array(
 				'/'                  => 'index/category',
-				// allow only mapped vars - cat and frm parameters to be passed 
+				// allow only mapped vars - cat and frm parameters to be passed
 				'<cat:{galleryCat}>' => array('index/list', 'mapVars' => array('media_cat_sef' => 'cat', 'from' => 'frm')),
 			)
 		);
diff --git a/e107_plugins/gallery/url/url.php b/e107_plugins/gallery/url/url.php
index 21459a6c3..0704cb1f4 100644
--- a/e107_plugins/gallery/url/url.php
+++ b/e107_plugins/gallery/url/url.php
@@ -4,7 +4,7 @@
 /*
  * Copyright (C) e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
  * $Id$
- *
+ * 
  * System routing config
  */