<?php
global $post;
if (!is_object($post)) {
    return;
}
$page_settings = Thememakers_Entity_Page_Constructor::get_page_settings($post->ID);

if (!$page_settings['page_slider']) {
    return;
}


$slider = new Thememakers_Entity_Slider();
$slides = Thememakers_Entity_Slider::get_slide_group($page_settings['page_slider']);
$options = $slider->get_slider_options($page_settings['page_slider_type']);
switch ($page_settings['page_slider_type']) {
    case 'nivo':
        ?>

        <?php wp_enqueue_script('thememakers_theme_slider_nivo_js', THEMEMAKERS_THEME_URI . '/js/sliders/nivo/jquery.nivo.slider.js'); ?>
        <?php wp_enqueue_style("thememakers_theme_slider_nivo_css1", THEMEMAKERS_THEME_URI . '/js/sliders/nivo/themes/default/default.css'); ?>
        <?php wp_enqueue_style("thememakers_theme_slider_nivo_css2", THEMEMAKERS_THEME_URI . '/js/sliders/nivo/nivo-slider.css'); ?>

        <script type="text/javascript">
            jQuery(window).load(function() {
                jQuery('#slider').nivoSlider({
                    effect: "<?php echo $options['transition_effect'] ?>", // Specify sets like: 'fold,fade,sliceDown'
                    animSpeed:<?php echo $options['transition_speed'] ?>, // Slide transition speed
                    pauseTime:<?php echo $options['autoslide'] ?>, // How long each slide will show


                    startSlide: <?php echo $options['start_slide'] ?>, // Set starting Slide (0 index)
                    captionOpacity: 1,
                    directionNav: <?php echo $options['direction_nav'] ?>, // Next & Prev navigation
                    directionNavHide:<?php echo $options['direction_nav_hide'] ?>, // Only show on hover
                    manualAdvance:<?php echo $options['manual_advance'] ?>, // Force manual transitions
                    keyboardNav: true, // Use left & right arrows


                    slices: <?php echo $options['slices'] ?>, // For slice animations
                    boxCols: <?php echo $options['box_cols'] ?>, // For box animations
                    boxRows: <?php echo $options['box_rows'] ?>, // For box animations
                    controlNav: <?php echo $options['control_nav'] ?>, // 1,2,3... navigation
                    controlNavThumbs: 0, // Use thumbnails for Control Nav
                    pauseOnHover: <?php echo $options['pause_on_hover'] ?>, // Stop animation while hovering
                    prevText: 'Prev', // Prev directionNav text
                    nextText: 'Next', // Next directionNav text
                    randomStart: <?php echo $options['random_start'] ?>, // Start on a random slide
                    beforeChange: function() {
                    }, // Triggers before a slide transition
                    afterChange: function() {
                    }, // Triggers after a slide transition
                    slideshowEnd: function() {
                    }, // Triggers after all slides have been shown
                    lastSlide: function() {
                    }, // Triggers when last slide is shown
                    afterLoad: function() {
                    } // Triggers when slider has loaded
                });
            });</script>


        <div id="slider" class="nivoSlider" style="width: <?php echo $options['slide_width'] ?>px; height: <?php echo $options['slider_height']; ?>px;">

            <?php
            if (!empty($slides)) {
                foreach ($slides as $slide) {

                    $slide_url = ThemeMakersHelper::resize_image($slide['image'], 'slider_showcase');
                    $slide_thumb_url = ThemeMakersHelper::resize_image($slide['image'], 'carusell_thumb');
                    $slide_link_url = $slide['link'];
                    $slide_title = ThemeMakersHelper::quotes_shield($slide['title']);
                    $slide_subtitle = ThemeMakersHelper::quotes_shield($slide['subtitle']);
                    $slide_desciption = ThemeMakersHelper::quotes_shield($slide['description']);


                    $slide_title_color = $slide['additional']['slide_title_color'];
                    $slide_subtitle_color = $slide['additional']['slide_subtitle_color'];
                    $slide_description_color = $slide['additional']['slide_description_color'];


                    $caption = "";
                    if ($options['enable_caption']) {
                        $caption = '<div class="nivo-caption"><div class="alignleft"><h3 style="color:' . $slide_title_color . ' !important;">' . $slide_title . '</h3><span class="desc" style="color:' . $slide_subtitle_color . ' !important;">' . $slide_subtitle . '</span></div><p style="color:' . $slide_description_color . ' !important;">' . $slide_desciption . '</p></div>';
                    }

                    if (strlen($slide_link_url) > 0) {
                        ?>
                        <a href="<?php echo $slide_link_url; ?>">
                            <img src="<?php echo $slide_url; ?>" data-thumb="<?php echo $slide_thumb_url; ?>" alt="<?php echo $slide_title ?>" title='<?php echo $caption ?>' />
                        </a>
                        <?php
                    } else {
                        ?>
                        <img src="<?php echo $slide_url; ?>" data-thumb="<?php echo $slide_thumb_url; ?>" alt="<?php echo $slide_title ?>" title='<?php echo $caption ?>' />

                        <?php
                    }
                }
            }
            ?>

        </div><!--/ #slider-->

        <?php
        break;

    case 'showcase':

        $slider = new Thememakers_Entity_Slider();
        $slides = Thememakers_Entity_Slider::get_slide_group($page_settings['page_slider']);
        $options = $slider->get_slider_options($page_settings['page_slider_type']);
        ?>

        <?php wp_enqueue_script('thememakers_theme_slider_showcase_js', THEMEMAKERS_THEME_URI . '/js/jquery.aw-showcase.min.js'); ?>

        <script type="text/javascript">
            jQuery(function() {
                jQuery("#showcase").awShowcase(
                        {
                            content_width: 770,						 
                            content_height: 500,
                            fit_to_parent: false,
                            auto: <?php echo $options['auto'] ?>,
                            interval: <?php echo $options['interval'] ?>,
                            continuous: parseInt(<?php echo $options['continuous'] ?>, 10),
                            loading: <?php echo $options['loading'] ?>,
                            tooltip_width: 250,
                            tooltip_icon_width: 32,
                            tooltip_icon_height: 32,
                            tooltip_offsetx: 18,
                            tooltip_offsety: 0,
                            arrows: false,
                            buttons: false,
                            btn_numbers: true,
                            keybord_keys: <?php echo $options['keybord_keys'] ?>,
                            mousetrace: false, /* Trace x and y coordinates for the mouse */
                            pauseonover: <?php echo $options['pauseonover'] ?>,
                            stoponclick: true,
							transition: '<?php echo $options['transition'] ?>', /* hslide/vslide/fade */
                            transition_delay: <?php echo $options['transition_delay'] ?>,
							transition_speed: <?php echo $options['transition_speed'] ?>,
							show_caption: 'show', /* onload/onhover/show */
							thumbnails: true,
                            thumbnails_position: '<?php echo $options['thumbnails_position'] ?>', /* outside-last/outside-first/inside-last/inside-first */
                            thumbnails_direction: '<?php echo $options['thumbnails_direction'] ?>', /* vertical/horizontal */
                            thumbnails_slidex: parseInt(<?php echo $options['thumbnails_slidex'] ?>, 10), /* 0 = auto / 1 = slide one thumbnail / 2 = slide two thumbnails / etc. */
                            dynamic_height: false, /* For dynamic height to work in webkit you need to set the width and height of images in the source. Usually works to only set the dimension of the first slide in the showcase. */
                            speed_change: true, /* Set to true to prevent users from swithing more then one slide at once. */
                            viewline: false /* If set to true content_width, thumbnails, transition and dynamic_height will be disabled. As for dynamic height you need to set the width and height of images in the source. */
                        
									
						 
                        });
            });
        </script>
	
        <div id="showcase" class="showcase">

            <?php
						
            if (!empty($slides)) {
                foreach ($slides as $slide) {
                    $slide_url = ThemeMakersHelper::get_image($slide['image'], 'slider_showcase');
                    $slide_thumb_url = ThemeMakersHelper::get_image($slide['image'], 'slider_showcase_thumb');
                    $slide_console = $slide['console'];
                    $slide_link_url = $slide['link'];
					$read_more=$slide['link_text'];
                    $slide_title = ThemeMakersHelper::quotes_shield($slide['title']);
                    $slide_subtitle = ThemeMakersHelper::quotes_shield($slide['subtitle']);
                    $slide_desciption = ThemeMakersHelper::quotes_shield($slide['description']);
					$slide_video=$slide['video'];
					
					//echo "slide_video=".$slide['video'];
					
                    ?>
					
					<?php 
					if(!empty($slide_video)) {
						
						?>
						<div class="showcase-slide">
							<!-- Put the slide content in a div with the class .showcase-content. -->
							<div class="showcase-entry">
								<!-- <img src="<?php echo $slide_url ?>" width="730" height="460" alt="<?php echo $slide_title ?>" /> -->
								<?php
								$video_width = 730;
								$video_height = 460;
								$video_url=$slide_video;
								 if (!empty($video_url)) {
									//$video_type = 'youtube.com';
									$allows_array = array('youtube.com', 'vimeo.com', '.mp4');

									foreach ($allows_array as $key => $needle) {
										$count = substr_count($video_url, $needle);
										if ($count) {
											$video_type = $allows_array[$key];
										}
									}

									switch ($video_type) {
										case $allows_array[0]:
											$video_url = explode("?v=", $video_url);
											$video_url = explode("&", $video_url[1]);
											if (is_array($video_url)) {
												$video_url = $video_url[0];
											}
											?>
												<iframe alt="<?php echo $slide_title ?>" width="<?php echo $video_width; ?>" height="<?php echo $video_height; ?>" frameborder="0" allowfullscreen="" src="http://www.youtube.com/embed/<?php echo $video_url; ?>?wmode=transparent" allowtransparency="true"></iframe>
											<?php
											
											break;
										case $allows_array[1]:
											$video_url = explode("/", $video_url);
											if (is_array($video_url)) {
												$video_url = $video_url[count($video_url) - 1];
											}
											?>
												<iframe alt="<?php echo $slide_title ?>" width="<?php echo $video_width; ?>" height="<?php echo $video_height; ?>" frameborder="0" allowfullscreen="" src="http://player.vimeo.com/video/<?php echo $video_url; ?>?wmode=transparent" allowtransparency="true"></iframe>
											<?php 
											//echo do_shortcode('[video type="vimeo" html5_poster="" html5_video_url="" src_webm="" src_ogg="" width="' . $video_width . '" height="' . $video_height . '"]' . $video_url . '[/video]');
											break;

										default:
											$html5_poster = THEMEMAKERS_THEME_URI . "/images/video_poster.jpg";
											if (has_post_thumbnail($first_preview->ID)) {
												$html5_poster = ThemeMakersHelper::get_post_featured_image($first_preview->ID, 'slider_showcase');
											}
											echo do_shortcode('[video type="html5" html5_poster="' . $html5_poster . '" html5_video_url="' . $video_url . '" src_webm="" src_ogg="" width="' . $video_width . '" height="' . $video_height . '"][/video]');
											break;
									}
								}
							?>	
							</div>
							<!-- Put the thumbnail content in a div with the class .showcase-thumbnail -->
							<div class="showcase-thumbnail">
								<?php
								$video_width = 86;
								$video_height = 52;
								$video_url=$slide_video;
								 if (!empty($video_url)) {
									//$video_type = 'youtube.com';
									$allows_array = array('youtube.com', 'player.vimeo.com', '.mp4');

									foreach ($allows_array as $key => $needle) {
										$count = substr_count($video_url, $needle);
										if ($count) {
											$video_type = $allows_array[$key];
										}
									}

									switch ($video_type) {
										case $allows_array[0]:
											$video_url = explode("?v=", $video_url);
											$video_url = explode("&", $video_url[1]);
											if (is_array($video_url)) {
												$video_url = $video_url[0];
											}
											?>
											<iframe alt="<?php echo $slide_title ?>" width="<?php echo $video_width; ?>" height="<?php echo $video_height; ?>" frameborder="0" allowfullscreen="" src="http://www.youtube.com/embed/<?php echo $video_url; ?>?wmode=transparent" allowtransparency="true"></iframe>
											<?php 
											//echo do_shortcode('[video type="youtube" html5_poster="" html5_video_url="" src_webm="" src_ogg="" alt="'.$slide_title.'" width="' . $video_width . '" height="' . $video_height . '"]' . $video_url . '[/video]');
											break;
										case $allows_array[1]:
											$video_url = explode("/", $video_url);
											if (is_array($video_url)) {
												$video_url = $video_url[count($video_url) - 1];
											}?>
											<iframe alt="<?php echo $slide_title ?>" width="<?php echo $video_width; ?>" height="<?php echo $video_height; ?>" frameborder="0" allowfullscreen="" src="http://player.vimeo.com/video/<?php echo $video_url; ?>?wmode=transparent" allowtransparency="true"></iframe>
											<?php
											//echo do_shortcode('[video type="vimeo" html5_poster="" html5_video_url="" src_webm="" src_ogg="" width="' . $video_width . '" height="' . $video_height . '"]' . $video_url . '[/video]');
											break;

										default:
											$html5_poster = THEMEMAKERS_THEME_URI . "/images/video_poster.jpg";
											if (has_post_thumbnail($first_preview->ID)) {
												$html5_poster = ThemeMakersHelper::get_post_featured_image($first_preview->ID, 'slider_showcase');
											}
											echo do_shortcode('[video type="html5" html5_poster="' . $html5_poster . '" html5_video_url="' . $video_url . '" src_webm="" src_ogg="" width="' . $video_width . '" height="' . $video_height . '"][/video]');
											break;
									}
								}
							?>	
								<!-- <img src="<?php echo $slide_thumb_url ?>" alt="<?php echo $slide_title ?>" /> -->
								
								<span class="showcase-thumbnail-console"><?php echo $slide_console ?></span>
								<h6 class="showcase-thumbnail-title"><a href="#"><?php echo $slide_title ?></a></h6>
							</div>
							<!-- Put the caption content in a div with the class .showcase-caption -->
							
						</div>
						
						
						<?php
					}					
						else {
						?>
				
                   <div class="showcase-slide">
                        <!-- Put the slide content in a div with the class .showcase-content. -->
                        <div class="showcase-entry">
							<img src="<?php echo $slide_url ?>" width="730" height="460" alt="<?php echo $slide_title ?>" />
						</div>
                        <!-- Put the thumbnail content in a div with the class .showcase-thumbnail -->
                        <div class="showcase-thumbnail">
							<img src="<?php echo $slide_thumb_url ?>" alt="<?php echo $slide_title ?>" />
							<span class="showcase-thumbnail-console"><?php echo $slide_console ?></span>
							<h6 class="showcase-thumbnail-title"><a href="#"><?php echo $slide_title ?></a></h6>
                       </div>
                        <!-- Put the caption content in a div with the class .showcase-caption -->
                        <div class="showcase-caption clearfix">
								
                            <h2>
									<?php if (!empty($slide_link_url)){ ?>
									<a href="<?php echo $slide_link_url; ?>"><?php echo $slide_title ?></a>
									<?php } else {?>
									<?php echo $slide_title ?>
									<?php } ?>
							</h2>
							
                            <div class="showcase-description">
                                <?php echo $slide_desciption ?>
                            </div>
							
							<?php if (!empty($slide_link_url)){ ?>
                            <a href="<?php echo $slide_link_url ?>" class="button small red align-btn-right">
								<?php if (!empty($read_more)){ echo $read_more ;}
								else {
										echo "Read more";
								}
								?>
							</a>
							<?php } ?>
                        </div>
                   </div> 
			
				   <?php } ?>
							  

                    <?php
               }
            }
            ?>


        </div>
        <?php
        break;
    default:
        break;
}
?>

<div style="clear:both;"></div>

