galleries = self::GetData();
		$this->GenerateOutput();
	}
	/**
	 * Determine if the gallery page is hidden or deleted
	 *
	 */
	public function GalleryVisible( $title, $info ){
		global $gp_index, $gp_menu, $gp_titles;
		if( !isset($gp_index[$title]) ){
			unset($this->galleries[$title]);
			$this->title_removed = true;
			return false;
		}
		$index			= $gp_index[$title];
		$title_info		= $gp_titles[$index];
		if( (isset($info['visibility']) && $info['visibility'] == 'hide') || isset($title_info['vis']) ){
			$this->not_visible[$title] = $info;
			return false;
		}
		return true;
	}
	// save the galleries index file
	public function PostSave(){
		if( !$this->title_removed ){
			return;
		}
		self::SaveIndex($this->galleries);
	}
	/**
	 * Get Gallery Index
	 *
	 * @static
	 */
	public static function GetData(){
		$galleries = \gp\tool\Files::Get('_site/galleries');
		if( !$galleries ){
			return array();
		}
		if( version_compare(\gp\tool\Files::$last_version,'2.2','<=') ){
			self::UpdateData($galleries);
		}
		return $galleries;
	}
	/**
	 * Add visibility settings according to old method for handling gallery visibility
	 * @static
	 */
	public static function UpdateData(&$galleries){
		global $gp_index, $gp_menu;
		foreach($galleries as $title => $info){
			if( isset($info['visibility']) ){
				continue;
			}
			$id = $gp_index[$title];
			if( !isset($gp_menu[$id]['level']) ){
				$galleries[$title]['visibility'] = 'hide';
			}else{
				$galleries[$title]['visibility'] = 'show';
			}
		}
	}
	public function GenerateOutput(){
		global $langmessage;
		\gp\tool::ShowingGallery();
		echo '
';
		echo '
';
		echo \gp\tool\Output::ReturnText('galleries');
		echo '
';
		$wrap = \gp\admin\Tools::CanEdit($this->page->gp_index);
		if( $wrap ){
			echo \gp\tool\Output::EditAreaLink($edit_index,'Admin/Galleries',$langmessage['edit']);
			echo '';
		}
		$this->PostSave();
    echo '';
	}
	/*
	Updating Functions
		The galleries.php file needs to  be updated when changes are made to pages with galleries
		When a page is...
			... renamed:				RenamedGallery()
			... edited:					UpdateGalleryInfo()
			... added:					do nothing, there won't be any images yet, wait till edited
			... deleted:				RemovedGallery()
			... restored from trash:	UpdateGalleryInfo() via RestoreFile() in gp\admin\Content\Trash
	*/
	/**
	 * Extract information about the gallery from it's html: img_count, icon_src
	 *
	 * @static
	 */
	public static function UpdateGalleryInfo($title,$file_sections){
		$content = '';
		$has_gallery = false;
		foreach($file_sections as $section_data){
			if( $section_data['type'] == 'gallery' ){
				$content .= $section_data['content'];
				$has_gallery = true;
			}
		}
		if( !$has_gallery ){
			self::RemovedGallery($title);
			return;
		}
		$new_count = preg_match_all('#(rel|class)="gallery_gallery"#',$content,$matches);
		//first image
		$new_icon = '';
		$first_img = preg_match('#
]*src="([^>"]*)"[^>]*>#',$content,$match); //uploaded file's names are stripped of " and >
		if( $first_img === 1 ){
			$new_icon = $match[1];
			$pos = strpos($new_icon,'/data/_uploaded');
			if( $pos !== false ){
				$new_icon = substr($new_icon,$pos+15);
			}
		}
		$galleries = self::GetData();
		$orig_icon = $orig_count = false;
		$orig_info = array();
		if( isset($galleries[$title]) && is_array($galleries[$title]) ){
			$orig_info = $galleries[$title];
			$orig_icon = $orig_info['icon'];
			$orig_count = $orig_info['count'];
		}
		if( ($orig_icon == $new_icon ) && ($orig_count == $new_count) ){
			return;
		}
		$orig_info['icon'] = $new_icon;
		$orig_info['count'] = $new_count;
		$galleries[$title] = $orig_info;
		self::SaveIndex($galleries);
	}
	/**
	 * Handle the removal of a gallery page for \gp\admin\Menu\Tools.php
	 *
	 */
	public static function RemovedGallery($title){
		$galleries = self::GetData();
		if( !isset($galleries[$title]) ){
			return;
		}
		unset($galleries[$title]);
		self::SaveIndex($galleries);
	}
	/**
	 * Handle the renaming of galleries for \gp\admin\Menu\Tools.php
	 *
	 * @static
	 *
	 */
	public static function RenamedGallery($old_title,$new_title){
		$galleries = self::GetData();
		if( !isset($galleries[$old_title]) ){
			return;
		}
		if( \gp\tool\Files::ArrayInsert($old_title,$new_title,$galleries[$old_title],$galleries,0,1) ){
			self::SaveIndex($galleries);
		}
	}
	public static function SaveIndex($galleries){
		global $dataDir;
		$file = $dataDir.'/data/_site/galleries.php';
		return \gp\tool\Files::SaveData($file,'galleries',$galleries);
	}
}