<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  require_once "/home/jglimpse/public_html/national/cmsAdmin/lib/viewer_functions.php";

  list($tile_imagesRecords, $tile_imagesMetaData) = getRecords(array(
    'tableName'   => 'tile_images',
    'perPage'     => '1',
  ));
  
   $tile_imagesRecord = @$tile_imagesRecords[0]; // get first record 
  // show error message if no matching record is found 
  if (!$tile_imagesRecord) { 
    print "Record not found!"; 
    exit; 
  } 
  
  //Interactive Tools Help

  // compile a list of tile nums to fetch
  $tile_fields = array('floor_tile', 'floor_feature_1', 'floor_feature_2', 'floor_grout');
  global $tile_imagesRecord;
  function collectRecordValues($field) {
    global $tile_imagesRecord;
    return $tile_imagesRecord[$field] ? $tile_imagesRecord[$field] : 0;
  }
  $tile_nums = join(', ', array_map('collectRecordValues', $tile_fields));
  
 // fetch referenced tiles and index by num 
  list($tile_detailsRecords, $tile_detailsMetaData) = getRecords(array( 
    'tableName'   => 'tile_details', 
    'where'       => "num IN ($tile_nums)", 
  )); 
  function collectNum($record) { return $record['num']; } 
  if ( sizeof($tile_detailsRecords) > 0 ) { 
    $tile_detailsRecordsByNum = array_combine(array_map('collectNum', $tile_detailsRecords), $tile_detailsRecords);  
  } 
   
  // inject tile_sku records into tile_images record's fields 
  foreach ( $tile_fields as $field ) { 
    $tile_imagesRecord[$field] =& $tile_detailsRecordsByNum[ $tile_imagesRecord[$field] ]; 
  }


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
	<title>Metricon Tile Studio</title>
	<link rel="stylesheet" type="text/css" href="css/all.css" />
	<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
	<!--[if IE ]><link rel="stylesheet" type="text/css" href="css/ie.css" /><![endif]-->
    <script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
    </script>
	</head>
	<body>
		<div id="wraper">
			<div class="wraper-c">
				<div id="header">
					<h1><a href="#">Metricon</a></h1>
					<div id="header-nav">
						<ul>
							<li><a href="http://www.metricon.com.au/about/">ABOUT METRICON</a></li>
							<li><a href="http://www.metricon.com.au/contact/">CONTACT US</a></li>
						</ul>
					</div>
				</div>
				<div id="main">
					<div class="headline">
						<h2>Find The Perfect Tiles For Your New Home</h2>
					</div>
					<div class="content-area">
						<div class="sidebar">
							<ul class="sidebar-nav">
								<li>
									<a href="#"><strong>FIND TILES BY HOME</strong></a>
									<ul>
										<li><a href="index.php">Select A Home</a></li>
									</ul>
								</li>
								<li>
									<a href="#"><strong>FIND TILES BY ROOM</strong></a>
									<ul>
										<li><a href="detail.php?room_type=3">Dining</a></li>
									    <li><a href="detail.php?room_type=4">Family Rooms</a></li>
										<li><a href="detail.php?room_type=2">Kitchens</a></li>
										<li><a href="detail.php?room_type=6">Bathrooms</a></li>
										<li><a href="detail.php?room_type=5">Ensuites</a></li>
										<li><a href="detail.php?room_type=1">Entries</a></li>
										<li><a href="detail.php?room_type=9">Laundries</a></li>
										<li><a href="detail.php?room_type=8">Outdoor Areas</a></li>
										<li><a href="detail.php?room_type=7">Powder Rooms</a></li>
									</ul>
								</li>
								<li>
									<a href="#"><strong>FIND BY COLOUR TONE</strong></a>
									<ul>
										<li>
											<form action="#">
												<fieldset>
													<div class="select-frm">
													<select name="select-tone" id="select-tone" class="sel" onchange="MM_jumpMenu('parent',this,1)">
                                                          <option value="detail.php?colour_tones=Brown">Brown</option>
                                                          <option value="detail.php?colour_tones=Beige">Beige</option>
                                                          <option value="detail.php?colour_tones=Grey">Grey</option>
                                                          <option value="detail.php?colour_tones=White">White</option>
                                                          <option value="detail.php?colour_tones=Bright">Bright</option>
                                                        </select>
														<label for="select-tone">Select:</label>
													</div>
												</fieldset>
											</form>
										</li>
									</ul>
								</li>
							</ul>
							<div class="sidebar-menu">
								<ul>
									<li><a href="http://www.metricon.com.au/queensland/displaycentres/">DISPLAY LOCATION</a></li>
								  <li><a href="#">VIEW FAVOURITES</a></li>
								</ul>
							</div>
						</div>
						<div class="primary-inner">
							<div class="gallery-holder">
								<div class="gallery-t">
									<span class="next"><?php foreach ($tile_imagesRecords as $record): ?><strong>On display in:&nbsp;</strong><?php echo join(', ', getListLabels('tile_images', 'display_village_s', $record['display_village_s'])); ?>
                                    <?php endforeach; ?></span>
									<strong class="pre">
									<?php foreach ($tile_imagesRecords as $record): ?>
									<?php 
  list($housesRecords) = getRecords(array( 
    'tableName'   => 'houses', 
    'where'       => "num = '{$tile_imagesRecord['house']}'", 
    'limit'       => '1', 
  )); 
  $housesRecord = @$housesRecords[0]; // get first record 

  list($room_typesRecords) = getRecords(array( 
    'tableName'   => 'room_types', 
    'where'       => "num = '{$tile_imagesRecord['room_type']}'", 
    'limit'       => '1', 
  )); 
  $room_typesRecord = @$room_typesRecords[0]; // get first record 
?> 
 <?php echo $housesRecord['title'] ?>: <?php echo $room_typesRecord['title'] ?></strong>
 <?php endforeach; ?>
								</div>
								<div id="carusel">
                                <?php if ($tile_imagesMetaData['prevPage']): ?>
								<a href="<?php echo $tile_imagesMetaData['prevPageLink'] ?>" class="link-prev">pre</a>

	<?php else: ?>
									<a href="<?php echo $tile_imagesMetaData['prevPageLink'] ?>" class="link-prev">pre</a>
    <?php endif ?>
                                    <div>
										<ul class="slideshow-item">
                                        <?php foreach ($tile_imagesRecords as $record): ?>
             <?php foreach ($record['main_image'] as $upload): ?>
											<li><div class="image-holder"><img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br /><br />
											  <a href="favourites.php"><img src="images/btn_addtofav.jpg" /></a></div>
                                            </li>
                                                 <?php endforeach ?>
   											 <?php endforeach; ?>

									<?php if (!$tile_imagesRecords): ?>
      								No records were found!<br/><br/>
    								<?php endif ?>
										</ul>
									</div>
                                    <?php if ($tile_imagesMetaData['nextPage']): ?>
									<a href="<?php echo $tile_imagesMetaData['nextPageLink'] ?>" class="link-next">next</a>
    <?php else: ?>
									<a href="<?php echo $tile_imagesMetaData['nextPageLink'] ?>" class="link-next">next</a>
    <?php endif ?>
								</div>
								<div class="gallery-b"></div>
							</div>
							<div class="column">
								<div class="column-info">
									<ul>
										<li>
											<a href="#"><strong>IN THIS IMAGE:</strong></a>
											<div class="text">
                                            <?php foreach ($tile_imagesRecords as $record): ?>  
      <?php if ($record['concept_no']): ?>
      <p><strong>Concept No.: </strong><?php echo $record['concept_no'] ?></p>
      <?php endif ?>
	  <?php if ($record['floor_tile']): ?>
      <p><strong>Floor Tile: </strong><?php echo $record['floor_tile']['tile_sku'] ?></p>
      <?php endif ?>
      <?php if ($record['floor_feature_1']): ?>
      <p><strong> Floor Feature 1: </strong><?php echo $record['floor_feature_1']['tile_sku'] ?></p>
      <?php endif ?>
      <?php if ($record['floor_feature_2']): ?>
      <p><strong>Floor Feature 2: </strong><?php echo $record['floor_feature_2']['tile_sku'] ?></p>
      <?php endif ?>
      <?php if ($record['floor_grout']): ?>
      <p><strong>Floor Grout: </strong><?php echo $record['floor_grout']['tile_sku'] ?></p>
      <?php endif ?>
      <?php if ($record['wall_tile']): ?>
      <p><strong>Wall Tile: </strong><?php echo $record['wall_tile'] ?></p>
      <?php endif ?>
      <?php if ($record['wall_grout']): ?>
      <p><strong>Wall Grout: </strong><?php echo $record['wall_grout'] ?></p>
      <?php endif ?>
      <?php if ($record['wall_feature_1']): ?>
      <p><strong>Wall Feature 1: </strong><?php echo $record['wall_feature_1'] ?></p>
      <?php endif ?>
      <?php if ($record['wall_feature_2']): ?>
      <p><strong>Wall Feature 2: </strong><?php echo $record['wall_feature_2'] ?></p>
      <?php endif ?>
      <?php if ($record['wall_feature_grout']): ?>
      <p><strong>Wall Feature grout: </strong><?php echo $record['wall_feature_grout'] ?></p>
      <?php endif ?>
      <?php if ($record['shower_wall_1']): ?>
      <p><strong>Shower Wall 1: </strong><?php echo $record['shower_wall_1'] ?></p>
      <?php endif ?>
      <?php if ($record['shower_wall_1_grout']): ?>
      <p><strong>Shower Wall 1 Grout: </strong><?php echo $record['shower_wall_1_grout'] ?></p>
      <?php endif ?>
      <?php if ($record['shower_wall_2']): ?>
      <p><strong>Shower Wall 2: </strong><?php echo $record['shower_wall_2'] ?></p>
      <?php endif ?>
      <?php if ($record['shower_wall_2_grout']): ?>
      <p><strong>Shower Wall 2 Grout: </strong><?php echo $record['shower_wall_2_grout'] ?></p>
      <?php endif ?>
      <?php if ($record['shower_feature']): ?>
      <p><strong>Shower Feature: </strong><?php echo $record['shower_feature'] ?></p>
      <?php endif ?>
      <?php if ($record['shower_feature_grout']): ?>
      <p><strong>Shower Feature Grout: </strong><?php echo $record['shower_feature_grout'] ?></p>
      <?php endif ?>
      <?php if ($record['bath_hob_and_face']): ?>
      <p><strong>Bath Hob and Face: </strong><?php echo $record['bath_hob_and_face'] ?></p>
      <?php endif ?>
      <?php if ($record['bath_hob_and_face_grout']): ?>
      <p><strong>Bath Hob and Face Grout: </strong><?php echo $record['bath_hob_and_face_grout'] ?></p>
      <?php endif ?>
      <?php if ($record['bath_hob_and_face_grout']): ?>
      <p><strong>Vanity Wall Tile: </strong><?php echo $record['bath_hob_and_face_grout'] ?></p>
      <?php endif ?>
      <?php if ($record['vanity_wall_grout']): ?>
      <p><strong>Vanity Wall Grout: </strong><?php echo $record['vanity_wall_grout'] ?></p>
      <?php endif ?>
      <?php if ($record['splashback_tile']): ?>
      <p><strong>Splashback Tile: </strong><?php echo $record['splashback_tile'] ?></p>
      <?php endif ?>
      <?php if ($record['splashback_tile_grout']): ?>
      <p><strong>Splashback Tile Grout: </strong><?php echo $record['splashback_tile_grout'] ?></p>
      <?php endif ?>
      <?php if ($record['pool_tile']): ?>
      <p><strong>Pool Tile: </strong><?php echo $record['pool_tile'] ?></p>
      <?php endif ?>
      <?php if ($record['pool_tile_grout']): ?>
      <p><strong>Pool Tile Grout: </strong><?php echo $record['pool_tile_grout'] ?></p>
      <?php endif ?>
      <?php if ($record['facade_tile']): ?>
      <p><strong>Facade Tile: </strong><?php echo $record['facade_tile'] ?></p>
      <?php endif ?>
      <?php if ($record['facade_tile_grout']): ?>
      <p><strong>Facade Tile Grout: </strong><?php echo $record['facade_tile_grout'] ?></p>
      <?php endif ?>
      <?php if ($record['colour_tones']): ?>
      <p><strong>Colour Tone: </strong><?php echo $record['colour_tones'] ?></p>
      <?php endif ?>
<?php endforeach; ?>
											</div>
										</li>
										<li>
											<a href="#"><strong>FIND MORE TILES LIKE THIS</strong></a>
											<ul>
                                         <?php foreach ($tile_imagesRecords as $record): ?>
												<li><a href="detail.php?colour_tones=<?php echo $record['colour_tones'] ?>">Similar colour tone</a></li>
												<li><a href="detail.php?room_type=<?php echo $record['room_type'] ?>">Similar room type</a></li>
                                                <?php endforeach; ?>
										  </ul>
										</li>
									</ul>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="wraper-b"></div>
		</div>
	</body>
</html>
