<?php $slider = get_field('slider'); ?>

  <?php foreach($slider as $slide): ?>

	<?php $type = $slide['type']; ?>
		
	<?php if($type == 'image'):?>			            
        <?php 
        	$image = wp_get_attachment_image_src($slide['image'],'full');  
        	$overlayPercantage = $slide['overlay_percentage'];
			$overlay = 1 - ($overlayPercantage / 100);
			$overlayColorHex = $slide['image_overlay'];
			$color = sscanf($overlayColorHex, "#%02x%02x%02x");
        ?>	            
    	<div class="sliderItem" style="background-color:<?php echo $overlayColorHex; ?>">    
			<img style="opacity:<?php echo $overlay; ?>" class="rsImg" src="<?php echo $image[0]; ?>" />
    <?php else: ?>
     	<?php $videoType = $slide['video_type']; ?>
     	<?php if($videoType == 'selfhost'): ?>
     			<div class="sliderItem"> 	
     				<?php $video_poster = wp_get_attachment_image_src($slide['video_poster'],'full'); 
     					if(!$video_poster){
     						$video_poster = array(0 => '');
     					}
     				?>
     				
					<video preload="none"  poster="<?php  echo $video_poster[0];?>" width="480" height="270">
						<source type="video/mp4" src="<?php echo $slide['video']; ?>">
					</video>
								
					<div class="rsPlayBtn selfPlay">
						<div class="rsPlayBtnIcon"></div>
					</div>
     	<?php elseif($videoType == 'youtube'): ?>
     				<?php 
     				
     				$video_id = $slide['video_url']; 
					
     					if($slide['video_poster']){
         					$thumb_url = wp_get_attachment_image_src($slide['video_poster'],'full'); 
							$thumb_url = $thumb_url[0];
         				}
         				else
         				{		
							parse_str( parse_url( $video_id, PHP_URL_QUERY ), $youTubeID );
							$thumb_url = 'http://img.youtube.com/vi/'.$youTubeID['v'].'/maxresdefault.jpg';
						}
					?>
					<div class="sliderItem"> 	
						<img class="rsImg" src="<?php echo $thumb_url; ?>" data-rsVideo="<?php echo $video_id; ?>" />
						
						
     	<?php else: ?>
     				
     				<?php
     				
     				$video_id = $slide['video_url']; 
					
     				if($slide['video_poster']){
     					$thumb_url = wp_get_attachment_image_src($slide['video_poster'],'full'); 
						$thumb_url = $thumb_url[0];
     				}
     				else
     				{
						
						preg_match('~^http://(?:www\.)?vimeo\.com/(?:clip:)?(\d+)~', $video_id , $vimeoID);
						$link = 'http://vimeo.com/api/v2/video/'.$vimeoID[1].'.php';
						$link = wp_remote_get($link);
						$link = wp_remote_retrieve_body($link);
						$html_returned = unserialize($link);
						$thumb_url = $html_returned[0]['thumbnail_large'];
					}
					?>
     				<div class="sliderItem"> 
     					<img class="rsImg" src="<?php echo $thumb_url; ?>" data-rsVideo="<?php echo $video_id; ?>" />			
 		<?php endif; ?>		
 	<?php endif; ?>			
     		<?php if($slide['content_effect']): ?>	
		      	<div class="sliderContent absoluteFill <?php echo $slide['content_effect']; ?> animated">
                    <div class="um_helper">
                        <div class="um_middle">
                           <?php echo $slide['content']; ?>
                        </div>
                    </div>
                </div>
               <?php endif; ?>   
 		 </div> <!--sliderItem END-->
         	
   <?php endforeach; ?>