<?php
get_header();
$gallery_thumbnail_width = 313;
$gallery_thumbnail_height = 220;
global $post;
//*****
$post_id = get_the_ID();
?>


<div class="title-caption-large">
    <h3><?php echo $post->post_title ?></h3>
</div><!--/ .title-caption-large-->


<!-- ************ - Gallery - ************** -->
<div id="grid-wrapper">
    <ul id="gallery" class="image-grid">
        <?php
        $images = get_post_meta($post_id, 'thememakers_gallery', true);
        ?>

        <?php if (is_array($images) AND !empty($images)) : ?>
            <?php foreach ($images as $key => $img_src) : ?>
                <?php if ($img_src != '') : ?>
                    <?php
                    $is_picture = true;
                    if (substr_count($img_src, "www.youtube.com")) {
                        $is_picture = false;
                    }
                    ?>
                    <li id="id-<?php echo $key; ?>" class="everyone <?php echo($is_picture ? "picture-icon" : "video-icon") ?>">
                        <a href="<?php echo $img_src ?>" class="zoomer" rel="<?php echo($is_picture ? "picture-group" : "video-group") ?>">
                            <img src="<?php
            if ($is_picture) {
                echo ThemeMakersHelper::resize_image($img_src, 'gallery_thumb');
            } else {
                echo THEMEMAKERS_THEME_URI . "/images/video_poster.jpg";
            }
                    ?>" width="<?php echo $gallery_thumbnail_width ?>" alt="" title="" />
							
                        </a>
                    </li>
                <?php endif; ?>
            <?php endforeach; ?>
        <?php endif; ?>
					
		<?php $video=get_post_meta($post_id, 'thememakers_gallery_video', true); ?>
			<?php if (is_array($video) AND !empty($video) ){ ?>
				<?php foreach ($video as $key => $video_src){ ?>
					
					<?php $vimeo=substr_count($video_src, 'vimeo'); 
						
						if ($vimeo!="0") {
								$cl_link='video-icon-vimeo';								
								} 
						else{
								$cl_link='video-icon';
								}
													
					?>
					<?php if (!empty($video_src)){ ?>
					<li id="id-<?php echo $key; ?>" class="everyone <?php echo $cl_link; ?>">
													
                        <a  href="<?php echo $video_src ?>" class="zoomer" rel="video-group">
                           																
							<?php 
							preg_match('#(\.be/|/embed/|/v/|/watch\?v=)([A-Za-z0-9_-]{5,11})#', $video_src, $matches);
								if(isset($matches[2]) && $matches[2] != ''){
										 $youtubecode = $matches[2];
										 ?>
								<img src="http://img.youtube.com/vi/<?php echo $youtubecode ?>/default.jpg" width="<?php echo $gallery_thumbnail_width ?>" height="<?php echo $gallery_thumbnail_height; ?>" alt="" title="" />
								<?php
										 
								}
								else {
										
										$arr = parse_url($video_src);
																			
										 $xml = simplexml_load_file('http://vimeo.com/api/v2/video'.$arr['path'].'.xml');
										if ($xml) {
												$th_url = (string) $xml->video->thumbnail_medium;
										}
										 ?>
										<img src="<?php echo $th_url ?>" width="<?php echo $gallery_thumbnail_width ?>" height="<?php echo $gallery_thumbnail_height; ?>" alt="" title="" />
								<?php
								}
								
								?>
													
						</a>
							
                    </li>
					<?php } ?>
					
					<?php } ?>
			<?php } ?>		
					

    </ul><!--/ gallery-->

    <div class="clear"></div>
</div><!-- / grid-wrapper -->
<!-- ************ - END Gallery - ************** -->

<div class="clear"></div>
<?php get_footer(); ?>

