<?

/*
FlexCMS (http://www.flexcms.com)
Flexible, Powerful, Affordable.

Contents of this file are protected by the copyright
notice found at http://www.flexcms.com/flex/pages/copyright.html,
and its usage is subject to the terms of the licensing agreement 
available at http://www.flexcms.com/flex/pages/license.html
*/



	// ========================================================================================
	// main photo gallery script
	// ========================================================================================
	
	$query = "select * from `".$Settings['DBPrefix']."pg-Settings`";
	$result = mysql_query($query) or die (mysql_error());
	while ($row = mysql_fetch_array($result)) {
		$pgSettings[$row['Name']] = $row['Value'];
	}
	
	if ($pgSettings['StorageLocationHTTP'] == '') {
		$pgSettings['StorageLocationHTTP'] = $BaseURL.'/pg_images';
	}
	if ($pgSettings['StorageLocationLocal'] == '') {
		$pgSettings['StorageLocationLocal'] = './pg_images';
	}
	
	
	$AlignmentCodes[''] = 'left';
	$AlignmentCodes['L'] = 'left';
	$AlignmentCodes['C'] = 'center';
	$AlignmentCodes['R'] = 'right';
	
	
	$Extensions[1] = '.gif';
	$Extensions[2] = '.jpg';
	$Extensions[3] = '.png';
			
	$ThumbExtensions[1] = '-thumb.gif';
	$ThumbExtensions[2] = '-thumb.jpg';
	$ThumbExtensions[3] = '-thumb.png';
	
	
	
	if (substr($pgSettings['StorageLocationHTTP'],0,1) == '/') {
		$ImageBaseHTTP = $BaseURL.$pgSettings['StorageLocationHTTP'];
	}
	else {
		$ImageBaseHTTP = $pgSettings['StorageLocationHTTP'];
	}
	
	
	
	if ($Arguments2 == 'image') {
		
		$Arguments3 = intval($Arguments3);
		
		$query = "select * from `".$Settings['DBPrefix']."pg-Images` where RecordNumber='".$Arguments3."' limit 1";
		$result = mysql_query($query) or die (mysql_error());
		$row = mysql_fetch_array($result);
		
		$query2 = "select * from `".$Settings['DBPrefix']."pg-Galleries` where RecordNumber='".$row['GalleryNumber']."' limit 1";
		$result2 = mysql_query($query2) or die (mysql_error());
		$row2 = mysql_fetch_array($result2);
		
		if ($row2['MinLevel'] <= $UserLevel && $row2['RecordNumber'] > 0 && $row['RecordNumber'] > 0) {
		
			if ($row['ImageTitle'] != '') {
				$BrowserTitle = $row['ImageTitle'].' -- '.$row2['GalleryTitle'];
			}
			else {
				$BrowserTitle = $MsgText[3][6].' -- '.$row2['GalleryTitle'];
			}
			
			
			$SlideshowRunning = "false";
			if ($Arguments4 == 1) {
				$SlideshowRunning = "true";
			}
			
			
			$query5 = "select * from `".$Settings['DBPrefix']."pg-Images` where GalleryNumber=".$row2['RecordNumber']." ORDER BY ImageTitle ASC, RecordNumber ASC";
			$result5 = mysql_query($query5) or die (mysql_error());
			while ($row5 = mysql_fetch_array($result5)) {
				$ImageIDs[] = $row5['RecordNumber'];			
			}
			
			$ArrayLength = count($ImageIDs);
			
			if ($ArrayLength > 1) {
			
				for ($x = 0; $x < $ArrayLength; $x++) {
				
					if ($ImageIDs[$x] == $Arguments3) {
					
						$CurrentImagePosition = $x;
					
						if ($x == 0) {
							$PreviousImageID = $ImageIDs[$ArrayLength-1];
							$NextImageID = $ImageIDs[$x+1];
						}
						else if ($x == $ArrayLength-1) {
							$PreviousImageID = $ImageIDs[$x-1];
							$NextImageID = $ImageIDs[0];
						}
						else {
							$PreviousImageID = $ImageIDs[$x-1];
							$NextImageID = $ImageIDs[$x+1];
						}
					
					}
				
				}
			
				// pick a random id for the next one if 'random' is clicked,
				// making sure it isn't the same one they're viewing now
				$ImageIDs[$CurrentImagePosition] = $ImageIDs[$ArrayLength-1];
		
				$RandomNumber = rand(0,$ArrayLength-2);
				$RandomImageID = $ImageIDs[$RandomNumber];
				
				
				$NavigationButtons = '<table width="80%" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td width="20%" align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$MainURL.'/photos/image/'.$PreviousImageID.'.html">'.$MsgText[3][70].'</a></font></td>
      <td width="20%" align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$MainURL.'/photos/image/'.$NextImageID.'.html">'.$MsgText[3][71].'</a></font></td>
      <td width="10%">&nbsp;</td>
      <td width="20%" align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$MainURL.'/photos/image/'.$RandomImageID.'.html">'.$MsgText[3][72].'</a></font></td>
      <td width="10%">&nbsp;</td>
      <td width="20%" align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="javascript:StartStopSlideshow();">'.$MsgText[3][73].'</a></font></td>
    </tr>
</table>';
				
			}
			else {
		
				$NavigationButtons = '<font face="'.$FontFace.'" size="'.$FontSize.'"><a href="javascript:window.close();">'.$MsgText[3][8].'</a></font>';	
			
			}
			
			
			
			$PageContents = '<div align="center"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="5" alt=""><br><table width="100%" height="'.($pgSettings['MaxHeight']+2).'" border="0" cellpadding="0" cellspacing="0"><tr><td align="center" valign="middle"><table border="0" cellpadding="1" cellspacing="0"><tr><td bgcolor="'.$Colors['Text'].'"><table border="0" cellpadding="0" cellspacing="0"><tr><td bgcolor="'.$Colors['BG'].'"><img src="'.$ImageBaseHTTP.'/'.$row['FileName'].$Extensions[$row['FileType']].'" width="'.$row['ImageWidth'].'" height="'.$row['ImageHeight'].'" border="0"></td></tr></table></td></tr></table></td></tr></table><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="10" alt=""><br><table width="100%" height="160" border="0" cellpadding="0" cellspacing="0"><tr><td height="110" align="center" valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$row['ImageTitle'].'</b><br>'.$row['ImageDescription'].'</font></td></tr><tr><td align="center" valign="middle" height="40"><script>
				
					var SlideshowRunning = '.$SlideshowRunning.';
					var TimerCode = "";
					
					function PageLoaded() {
						if (SlideshowRunning == true) {
							TimerCode = window.setInterval(AdvanceSlideshow,5000);
						}
					}
					
					function StartStopSlideshow() {
					
						if (SlideshowRunning == false) {
							SlideshowRunning = true;
							TimerCode = window.setInterval(AdvanceSlideshow,5000);
						}
						else {
							SlideshowRunning = false;
							window.clearInterval(TimerCode);
						}
					
					}
					
					function AdvanceSlideshow() {
						window.location = "'.$MainURL.'/photos/image/'.$NextImageID.'/1.html";
					}
				
				</script>'.$NavigationButtons.'</td></tr></table></div>';
		
		}
		else {
		
			$PageContents = '<br><br><div align="center">'.$MsgText[3][9].'<br><br><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="javascript:window.close();">'.$MsgText[3][8].'</a></font></div>';

			$row['ImageWidth'] = '500';
			$row['ImageHeight'] = '500';
		
		}
		
		
		$WindowWidth = ($row['ImageWidth'] + 150);
		$WindowHeight = ($row['ImageHeight'] + 200);
		
		
		print '<html><head>
<title>'.$BrowserTitle.'</title>
<meta name="Description" content="">
<meta name="Keywords" content="">
<meta name="Author" content="">
<meta name="Generator" content="">
<meta name="MSSmartTagsPreventParsing" content="TRUE">
</head>
<body bgcolor="'.$Colors['BG'].'" text="'.$Colors['Text'].'" link="'.$Colors['Link'].'" vlink="'.$Colors['VLink'].'" alink="'.$Colors['ALink'].'" leftmargin="5" marginwidth="5" topmargin="5" marginheight="5" rightmargin="5" style="margin:5" onLoad="PageLoaded();">
'.$PageContents.'
</body>
</html>';

		exit();
	
	}		
	else if ($Arguments2 != '') {
		
		$Arguments2 = intval($Arguments2);
		
		$query = "select * from `".$Settings['DBPrefix']."pg-Galleries` where RecordNumber=".$Arguments2." limit 1";
		$result = mysql_query($query) or die (mysql_error());
		$row = mysql_fetch_array($result);
		
		$GalleryFormat = $row['GalleryFormat'];
		
		
		if ($pgSettings['Title'] != '') {
			$PageTitle = '<div align="'.$AlignmentCodes[$pgSettings['TitleAlignment']].'">'.$pgSettings['Title'].' - '.$row['GalleryTitle'];
			$BrowserTitle = $pgSettings['Title'].' - '.$row['GalleryTitle'];
			$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/photos.html">'.$pgSettings['Title'].'</a> > '.$row['GalleryTitle'];
		}
		else {
			$PageTitle = '<div align="'.$AlignmentCodes[$pgSettings['TitleAlignment']].'">'.$row['GalleryTitle'];
			$BrowserTitle = $MsgText[3][1].' - '.$row['GalleryTitle'];
			$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/photos.html">'.$MsgText[3][1].'</a> > '.$row['GalleryTitle'];
		}
				
		$PageContents = $row['GalleryDescription'].'</div><br><br>
		<script language="Javascript">
		function ViewImage(ImageNumber,Width,Height) {
		
			var Width = "'.($pgSettings['MaxWidth']+100).'";
			var Height = "'.($pgSettings['MaxHeight']+200).'";
			
			var Left = "150";
			var Top = "50";
			
			if (screen.width > 0) {
				Left = ((screen.width-Width)/2);
			}
			if (screen.height > 0) {
				Top = ((screen.height-Height)/2);
			}
		
			//if (screen.width > 0) {
			//	Width = (screen.width-10);
			//}
			//if (screen.height > 0 && Height > (screen.height-50)) {
			//	Height = (screen.height-50);
			//}
					
			//var WindowID = window.open("'.$MainURL.'/photos/image/"+ImageNumber+".html","ViewImage","width="+Width+",height="+Height+",toolbars=no,scrollbars=yes");

			var WindowID = window.open("'.$MainURL.'/photos/image/"+ImageNumber+".html","ViewImage","width="+Width+",height="+Height+",top="+Top+",left="+Left+",toolbars=no,scrollbars=no");
		}		
		</script>';
		
		
		
		$query25 = "select RecordNumber,Username,DisplayName from `".$Settings['DBPrefix']."core-Users`";
		$result25 = mysql_query($query25) or die (mysql_error());
		while ($row25 = mysql_fetch_array($result25)) {
			
			if ($row25['DisplayName'] != '') {
				$DisplayNames[$row25['RecordNumber']] = $row25['DisplayName'];
			}
			else {
				$DisplayNames[$row25['RecordNumber']] = $row25['Username'];
			}
			
			$Usernames[$row25['RecordNumber']] = $row25['Username'];
					
		}
		
		
		$query = "select * from `".$Settings['DBPrefix']."pg-Galleries`";
		$result = mysql_query($query) or die (mysql_error());
		while ($row = mysql_fetch_array($result)) { 
			$GalleryLevel[$row['RecordNumber']] = $row['MinLevel'];		
		}
		
		
		$query = "select * from `".$Settings['DBPrefix']."pg-Images` where GalleryNumber=".$Arguments2." ORDER BY ImageTitle ASC, RecordNumber ASC";
		$result = mysql_query($query) or die (mysql_error());
		
		if (mysql_num_rows($result) > 0 && $GalleryLevel[$Arguments2] <= $UserLevel) {
						
			
			if ($GalleryFormat <= 4) {
				$PageContents .= '<table width="100%" border="0" cellpadding="5" cellspacing="0"><tr>';
			}
			else if ($GalleryFormat == 5) {
				$PageContents .= '<table border="0" cellpadding="5" cellspacing="0" align="center"><tr>';
			}
			else if ($GalleryFormat == 6 || $GalleryFormat == 7) {
				$PageContents .= '<table width="100%" border="0" cellpadding="5" cellspacing="0"><tr>';
			}
			
							
			while ($row = mysql_fetch_array($result)) { 
			
				if ($FirstImageID == '') {
					$FirstImageID = $row['RecordNumber'];
				}
			
				
				$WindowWidth = ($row['ImageWidth'] + 150);
				$WindowHeight = ($row['ImageHeight'] + 200);
			
        
				if ($GalleryFormat == 1) {
				
					$ColCount++;
					
					if ($ColCount > 2) {
					
						$ColCount = 1;
						
						$GallerySectionContents .= '</tr><tr><td colspan="2"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="10" alt=""></td></tr><tr>';
				
					}
		
					$GallerySectionContents .= '<td width="50%" align="center" height="100%"><table height="100%" border="0" cellpadding="0" cellspacing="3"><tr><td align="center" valign="middle" height="'.$pgSettings['ThumbMaxHeight'].'"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="javascript:ViewImage('.$row['RecordNumber'].','.$WindowWidth.','.$WindowHeight.');"><img src="'.$ImageBaseHTTP.'/'.$row['FileName'].$ThumbExtensions[$row['FileType']].'" alt="'.$row['ImageTitle'].'" border="0"></a></td></tr><tr><td align="center" valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="javascript:ViewImage('.$row['RecordNumber'].','.$WindowWidth.','.$WindowHeight.');"><b>'.$row['ImageTitle'].'</b></a></td></tr></table></td>';


				} // end format #1
				
				
				if ($GalleryFormat == 2) {
				
					$ColCount++;
					
					if ($ColCount > 3) {
					
						$ColCount = 1;
						
						$GallerySectionContents .= '</tr><tr><td colspan="3"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="10" alt=""></td></tr><tr>';
				
					}
					
					if ($ColCount == 2) {
						$ColWidth = '34%';
					}
					else {
						$ColWidth = '33%';
					}
					
					
					$GallerySectionContents .= '<td width="'.$ColWidth.'" align="center" height="100%"><table height="100%" border="0" cellpadding="0" cellspacing="3"><tr><td align="center" valign="middle" height="'.$pgSettings['ThumbMaxHeight'].'"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="javascript:ViewImage('.$row['RecordNumber'].','.$WindowWidth.','.$WindowHeight.');"><img src="'.$ImageBaseHTTP.'/'.$row['FileName'].$ThumbExtensions[$row['FileType']].'" alt="'.$row['ImageTitle'].'" border="0"></a></td></tr><tr><td align="center" valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="javascript:ViewImage('.$row['RecordNumber'].','.$WindowWidth.','.$WindowHeight.');"><b>'.$row['ImageTitle'].'</b></a></td></tr></table></td>';
		
					
				} // end format #2
				
				if ($GalleryFormat == 3) {
				
					$ColCount++;
					
					if ($ColCount > 4) {
					
						$ColCount = 1;
						
						$GallerySectionContents .= '</tr><tr><td colspan="4"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="10" alt=""></td></tr><tr>';
				
					}
		
					$GallerySectionContents .= '<td width="25%" align="center" height="100%"><table height="100%" border="0" cellpadding="0" cellspacing="3"><tr><td align="center" valign="middle" height="'.$pgSettings['ThumbMaxHeight'].'"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="javascript:ViewImage('.$row['RecordNumber'].','.$WindowWidth.','.$WindowHeight.');"><img src="'.$ImageBaseHTTP.'/'.$row['FileName'].$ThumbExtensions[$row['FileType']].'" alt="'.$row['ImageTitle'].'" border="0"></a></td></tr><tr><td align="center" valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="javascript:ViewImage('.$row['RecordNumber'].','.$WindowWidth.','.$WindowHeight.');"><b>'.$row['ImageTitle'].'</b></a></td></tr></table></td>';


				} // end format #3
				
				if ($GalleryFormat == 4) {
				
					$ColCount++;
					
					if ($ColCount > 5) {
					
						$ColCount = 1;
						
						$GallerySectionContents .= '</tr><tr><td colspan="5"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="10" alt=""></td></tr><tr>';
				
					}
		
					$GallerySectionContents .= '<td width="20%" align="center" height="100%"><table height="100%" border="0" cellpadding="0" cellspacing="3"><tr><td align="center" valign="middle" height="'.$pgSettings['ThumbMaxHeight'].'"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="javascript:ViewImage('.$row['RecordNumber'].','.$WindowWidth.','.$WindowHeight.');"><img src="'.$ImageBaseHTTP.'/'.$row['FileName'].$ThumbExtensions[$row['FileType']].'" alt="'.$row['ImageTitle'].'" border="0"></a></td></tr><tr><td align="center" valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="javascript:ViewImage('.$row['RecordNumber'].','.$WindowWidth.','.$WindowHeight.');"><b>'.$row['ImageTitle'].'</b></a></td></tr></table></td>';


				} // end format #4
				
				if ($GalleryFormat == 5) {
				
					if ($row['PostedBy'] > 0) {
						if ($LoggedIn == 'y') {
							$PostedBy = ' '.$MsgText[3][10].' <a href="'.$MainURL.'/profile/'.$Usernames[$row['PostedBy']].'.html">'.$DisplayNames[$row['PostedBy']].'</a>';
						}
						else {
							$PostedBy = ' '.$MsgText[3][10].' '.$DisplayNames[$row['PostedBy']];
						}
					}
					else {
						$PostedBy = '';
					}
					
					
					if ($pgSettings['ShowViewsCount'] == 'y') {
						$ViewsPrint = '<br><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="12" alt=""><br>Viewed '.$row['ImageViews'].' times';
					}
									
		
					$GallerySectionContents .= '<tr><td width="'.$pgSettings['ThumbMaxWidth'].'" align="center" valign="middle"><a href="javascript:ViewImage('.$row['RecordNumber'].','.$WindowWidth.','.$WindowHeight.');"><img src="'.$ImageBaseHTTP.'/'.$row['FileName'].$ThumbExtensions[$row['FileType']].'" alt="'.$row['ImageTitle'].'" border="0"></a></td><td valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="javascript:ViewImage('.$row['RecordNumber'].','.$WindowWidth.','.$WindowHeight.');"><b>'.$row['ImageTitle'].'</b></a><br><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="5" alt=""><br>'.$row['ImageDescription'].'<br><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="8" alt=""><br><font size="'.($FontSize-1).'">'.$MsgText[3][11] .' '.date("F jS, Y",$row['DatePosted']).$PostedBy.$ViewsPrint.'</font></font></td></tr><tr><td colspan="5"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="6" alt=""></td></tr>';


				} // end format #5
				
				if ($GalleryFormat == 6) {
				
					$ColCount++;
					
					if ($ColCount > 2) {
					
						$ColCount = 1;
						
						$GallerySectionContents .= '</tr><tr><td colspan="2"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="10" alt=""></td></tr><tr>';
				
					}
									
		
					$GallerySectionContents .= '<td width="50%" align="center" height="100%"><table height="100%" border="0" cellpadding="0" cellspacing="3"><tr><td align="center" valign="middle" height="'.$pgSettings['ThumbMaxHeight'].'"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="javascript:ViewImage('.$row['RecordNumber'].','.$WindowWidth.','.$WindowHeight.');"><img src="'.$ImageBaseHTTP.'/'.$row['FileName'].$ThumbExtensions[$row['FileType']].'" alt="'.$row['ImageTitle'].'" border="0"></a></td></tr><tr><td align="center" valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="javascript:ViewImage('.$row['RecordNumber'].','.$WindowWidth.','.$WindowHeight.');"><b>'.$row['ImageTitle'].'</b></a><br><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="1" alt=""><br><font face="'.$FontFace.'" size="'.($FontSize-1).'">'.$row['ImageDescription'].'</td></tr></table></td>';


				} // end format #6
				
				if ($GalleryFormat == 7) {
				
					$ColCount++;
					
					if ($ColCount > 3) {
					
						$ColCount = 1;
						
						$GallerySectionContents .= '</tr><tr><td colspan="3"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="10" alt=""></td></tr><tr>';
				
					}
					
					if ($ColCount == 2) {
						$ColWidth = '34%';
					}
					else {
						$ColWidth = '33%';
					}
									
		
					$GallerySectionContents .= '<td width="'.$ColWidth.'" align="center" height="100%"><table height="100%" border="0" cellpadding="0" cellspacing="3"><tr><td align="center" valign="middle" height="'.$pgSettings['ThumbMaxHeight'].'"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="javascript:ViewImage('.$row['RecordNumber'].','.$WindowWidth.','.$WindowHeight.');"><img src="'.$ImageBaseHTTP.'/'.$row['FileName'].$ThumbExtensions[$row['FileType']].'" alt="'.$row['ImageTitle'].'" border="0"></a></td></tr><tr><td align="center" valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="javascript:ViewImage('.$row['RecordNumber'].','.$WindowWidth.','.$WindowHeight.');"><b>'.$row['ImageTitle'].'</b></a><br><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="1" alt=""><br><font face="'.$FontFace.'" size="'.($FontSize-1).'">'.$row['ImageDescription'].'</td></tr></table></td>';


				} // end format #7
				

							
			}
			
			$GallerySectionContents .= '</tr></table>';
			
			if ($FirstImageID != '' && mysql_num_rows($result) > 1) {
				$PageContents .= '<div align="center"><a href="javascript:ViewImage(\''.$FirstImageID.'/1\','.$WindowWidth.','.$WindowHeight.');"><b>'.$MsgText[3][74].'</b></a></div><br>';
			}
			
			$PageContents .= $GallerySectionContents;
			
			
		}
		else {
			$PageContents = '<br>'.$MsgText[3][12];
		}
		
	
	} // end if showing a specific gallery
	else {
	// showing list of galleries the user has access to
	
	
		if ($pgSettings['Title'] == '') {
			$pgSettings['Title'] = $MsgText[3][1];
		}
		
	
		if ($pgSettings['TitleImage'] != '') {
			$PageTitle = '<div align="'.$AlignmentCodes[$pgSettings['TitleAlignment']].'"><img src="'.$BaseURL.$pgSettings['TitleImage'].'" alt="'.$pgSettings['Title'].'" border="0"></div>';	
		}
		else {
			$PageTitle = '<div align="'.$AlignmentCodes[$pgSettings['TitleAlignment']].'">'.$pgSettings['Title'].'</div>';
		}
		
		
		$BrowserTitle = $pgSettings['Title'];
		$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > '.$pgSettings['Title'];
		
		
		
	
		$query = "select * from `".$Settings['DBPrefix']."pg-Galleries` where MinLevel<=".$UserLevel." order by Priority ASC, GalleryTitle ASC, RecordNumber ASC";		
		$result = mysql_query($query) or die (mysql_error());
		
		if (mysql_num_rows($result) > 0) {
		
			//taken out to use otter's mod:
			//$PageContents .= '<table border="0" cellpadding="5" cellspacing="0" align="center"><tr>';
		
			while ($row = mysql_fetch_array($result)) {
			
				
				if ($row['GalleryImages'] > 0) {
					$RandomImage = rand(0,($row['GalleryImages']-1));
			
				
					$query2 = "select * from `".$Settings['DBPrefix']."pg-Images` where GalleryNumber=".$row['RecordNumber']." limit ".$RandomImage.",1";
					$result2 = mysql_query($query2) or die (mysql_error());
					$row2 = mysql_fetch_array($result2);
					
					$ThumbLocation = $ImageBaseHTTP.'/'.$row2['FileName'].$ThumbExtensions[$row2['FileType']];
					
					
					// figure out thumbnail dimensions
					$NewWidth = $pgSettings['ThumbMaxWidth'];
					$NewHeight = $pgSettings['ThumbMaxHeight'];
					
					$WidthRatio = $row2['ImageWidth'] / $NewWidth;
					$HeightRatio = $row2['ImageHeight'] / $NewHeight;
				
					if ($WidthRatio >= $HeightRatio) {
						$NewWidthCalc = number_format($row2['ImageWidth'] / $WidthRatio, 0);
						$NewHeightCalc = number_format($row2['ImageHeight'] / $WidthRatio, 0);
					}
					else {
						$NewWidthCalc = number_format($row2['ImageWidth'] / $HeightRatio, 0);
						$NewHeightCalc = number_format($row2['ImageHeight'] / $HeightRatio, 0);
					}
					
					$ImageWidth = $NewWidthCalc;
					$ImageHeight = $NewHeightCalc;
				}
				else {
					$ThumbLocation = $ImagesURL.'/admin/spacer.gif';
					
					$ImageWidth = $pgSettings['ThumbMaxWidth'];
					$ImageHeight = $pgSettings['ThumbMaxHeight'];
				}
				
		
				//$PageContents .= '<tr><td width="'.$pgSettings['ThumbMaxWidth'].'" align="center" valign="middle"><a href="'.$MainURL.'/photos/'.$row['RecordNumber'].'.html"><img src="'.$ThumbLocation.'" width="'.$ImageWidth.'" height="'.$ImageHeight.'" alt="'.$row2['ImageTitle'].' ('.$MsgText[3][14].' '.$row['GalleryTitle'].')" border="0"></a></td><td valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$MainURL.'/photos/'.$row['RecordNumber'].'.html"><b>'.$row['GalleryTitle'].'</b></a><br><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="15" alt=""><br>'.$row['GalleryDescription'].'<br><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="15" alt=""><br><font size="1">'.$MsgText[3][13].': '.$row['GalleryImages'].'</font></font></td></tr><tr><td colspan="5"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="6" alt=""></td></tr>';


				// otter mod for alternating image alignments:
				if ($OddEven == 0) {
					$OddEven = 1;
				
					$PageContents .= '<table width="400" border="0" cellpadding="5" cellspacing="0" align="center"><tr><td width="'.$pgSettings['ThumbMaxWidth'].'" align="center" valign="middle"><a href="'.$MainURL.'/photos/'.$row['RecordNumber'].'.html"><img src="'.$ThumbLocation.'" width="'.$ImageWidth.'" height="'.$ImageHeight.'" alt="'.$row2['ImageTitle'].' ('.$MsgText[3][14].' '.$row['GalleryTitle'].')" border="0"></a></td><td valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$MainURL.'/photos/'.$row['RecordNumber'].'.html"><b>'.$row['GalleryTitle'].'</b></a><br><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="15" alt=""><br>'.$row['GalleryDescription'].'<br><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="15" alt=""><br><font size="1">'.$MsgText[3][13].': '.$row['GalleryImages'].'</font></font></td></tr><tr><td colspan="5"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="6" alt=""></td></tr></table>';
				
				}
				else {
					$OddEven = 0;
				
					$PageContents .= '<table width="400" border="0" cellpadding="5" cellspacing="0" align="center"><tr><td valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$MainURL.'/photos/'.$row['RecordNumber'].'.html"><b>'.$row['GalleryTitle'].'</b></a><br><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="15" alt=""><br>'.$row['GalleryDescription'].'<br><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="15" alt=""><br><font size="1">'.$MsgText[3][13].': '.$row['GalleryImages'].'</font></font></td><td width="'.$pgSettings['ThumbMaxWidth'].'" align="center" valign="middle"><a href="'.$MainURL.'/photos/'.$row['RecordNumber'].'.html"><img src="'.$ThumbLocation.'" width="'.$ImageWidth.'" height="'.$ImageHeight.'" alt="'.$row2['ImageTitle'].' ('.$MsgText[3][14].' '.$row['GalleryTitle'].')" border="0"></a></td></tr><tr><td colspan="5"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="6" alt=""></td></tr></table>';
				}
			
			}
			
			//taken out to use otter's mod:
			//$PageContents .= '</tr></table>';
			
		}
		else {
		
			$PageContents = $MsgText[3][15];
		
		}
	
	
	} // end if showing list of galleries the user has access to
			
	
	// ========================================================================================




?>
