<?
session_start();
include('_db.connection.php');

$setup_result = mysql_query("SELECT title FROM setup WHERE setup_id = 1", $db);
$setup = mysql_fetch_object($setup_result);

$folder_result = mysql_query("SELECT mid FROM folders WHERE folder_id = '$fid'", $db);
$folder = mysql_fetch_object($folder_result);

$bheight = 0;

$member_result = mysql_query("SELECT custom_plan,custom_branding,plan FROM members WHERE member_id = '$folder->mid'", $db);
$member = mysql_fetch_object($member_result);

	if($member->custom_plan == 1){
		if($member->custom_branding == 1){
			$bheight = 10;
		}
	}
	else {
		$plan_result = mysql_query("SELECT branding FROM plans WHERE plan_id = '$member->plan'");
		$plan_rs = mysql_fetch_object($plan_result);
		
		if($plan->branding == 1){
			$bheight = 10;
		}
	}
/*
$image_w_result = mysql_query("SELECT width FROM images WHERE fid = '$fid' order by 'width' desc", $db);
$image_h_result = mysql_query("SELECT height FROM images WHERE fid = '$fid' order by 'height' desc", $db);
$image_count = mysql_num_rows($image_w_result);
$image_w = mysql_fetch_object($image_w_result);
$image_h = mysql_fetch_object($image_h_result);
*/

$w2 = 0;
$image_w_result = mysql_query("SELECT width FROM images WHERE fid = '$fid' order by width desc", $db);
$image_count = mysql_num_rows($image_w_result);
while($image_w = mysql_fetch_object($image_w_result)){
	$w1 = $image_w->width;
	if($w1 > $w2){
		$w2 = $w1;
	}
	
}

$h2 = 0;
$image_h_result = mysql_query("SELECT height FROM images WHERE fid = '$fid' order by height desc", $db);
while($image_h = mysql_fetch_object($image_h_result)){
	$h1 = $image_h->height;
	if($h1 > $h2){
		$h2 = $h1;
	}
}

$extra_height = $bheight + 22;
$extra_width = 2;
?>
<title><? echo $setup->title; ?></title>
<?
	if($image_count > 0){
?>
	<body bgcolor="#eeeeee" onload="window.open('ss.window.php?fid=<? echo $fid; ?>&pmode=build&sid=<? echo $setup->title; ?>', 'image_win', ['HEIGHT=<? echo $h2 + $extra_height; ?>', 'WIDTH=<? echo $w2 + $extra_width; ?>', 'dependent']);<? if($close == 1){ echo "window.close()"; } ?>">
<?
	}
	else{
?>
	<body bgcolor="#eeeeee">
<?
	}
?>
		<table width="100%" height="100%">
			<tr>
				<td height="100%" align="center"><font face="Verdana" size="2" color="#333333"><b><? echo $setup->title; ?></td>
			</tr>
		</table>
	</body>

