<!--Begin Slider-->	
<?php

require(ghostpool_inc . 'options.php');

$_ishome = (is_home() OR is_front_page());

global $gp_settings;
global $current_user, $bp;
get_currentuserinfo();

?>
<?php

if ($_ishome || ( $bp->current_component == BP_DEDICATION_SLUG )) {
    $posts_per_page = $theme_video_slides;

    $dedication_orderby = "date";
    $dedication_order = "DESC";
    $category_name = 'dedication';
    $post_status = array('publish', 'private');

    $args = array(
        'post_type' => array('post'),
        'order' => $dedication_order,
        'orderby' => $dedication_orderby,
        'posts_per_page' => -1,
        'post_status' => $post_status,
        'category_name' => $category_name,
    );
    query_posts($args);
}

if (is_singular()) {
    //
}

if (have_posts()) {
    $slide_counter = 0;
    $urls_video = array();
    
?>    
<div id="the_slider" <?php echo (play_video_on_full_screen()) ? 'class="fullscreen_div"' : ''; ?> >
    <!--Begin Slider Wrapper-->
    <div id="slider-wrapper">
        <?php if($theme_logo) { ?><div class="dedicationTitle_logo"><img src="<?php echo get_template_directory_uri(); ?>/lib/images/logo-w-fs.png" alt="<?php bloginfo('name'); ?>" /></div><?php } ?>
        <div id="dedicationTitle_container">
            <div id="dedicationTitle-data-panel"></div>
            <h2 id="dedicationTitle"></h2>
        </div>
        <div id="componentWrapper">
            <div class="mediaWrapper">
                <div class="youtubeHolder"></div>	
                <div class="vimeoHolder"></div>
            </div>

            <div class="thumbHolder">
                <div class="thumbContainer"><div class="thumbInnerContainer"></div></div>	
                <div class="thumbBackward"><img src="<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/thumb_backward_v.png" alt="" width="31" height="21" /></div>	
                <div class="thumbForward"><img src="<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/thumb_forward_v.png" alt="" width="31" height="21" /></div>	
            </div>
            <div class="mediaPreloader"></div>             
            <div class="componentPlaylist">
                <ul id='playlist'>

    <?php
    while (have_posts()) : the_post(); include('loop-dedication-data.php');   
        
        // Si ya hemos visto más de 'posts_per_page' dedicatorias, salgo del buble
        if ($slide_counter == $posts_per_page) {
            break;
        }
               
        $displayed_id = bp_displayed_user_id();
        
        // Perfil del usuario: sólo mostrar las dedicadas por él y para él. El resto se descartan.
        if ( $bp->current_component == BP_DEDICATION_SLUG ) {
            if (($displayed_id != $gp_settings['from_user_id']) && ($displayed_id != $gp_settings['to_user_id'])) {
                continue; // me salto esta dedicatoria
            }
        }

        // Página de inicio / página del video: Usuario actual puede ver la dedicatoria?
        if ($post->post_status == 'private') {
            if (($current_user->ID != $gp_settings['from_user_id']) && ($current_user->ID != $gp_settings['to_user_id'])) {
                continue; // me salto esta dedicatoria
            }
        }

            $video = $gp_settings['video'];

            if ($_ishome) {
                if ($theme_homepage_not_repeat_videos) {
                    // Si la URL del video ya ha salido en una dedicatoria anterior, me la salto
                    if (in_array($video, $urls_video)) {
                            continue;
                    }
                }
            }
            
            $urls_video[] = $video;
            
            // Video Type	
            $vimeo = strpos($video, "vimeo.com");
            $yt1 = strpos($video, "youtube.com");
            $yt2 = strpos($video, "youtu.be");

            if (($vimeo) OR ($yt1) OR ($yt2)) {
                if ($yt2) { //youtu.be
                    $video_id = substr(parse_url($video, PHP_URL_PATH), 1);
                    $data_type = 'youtube_single';
                    $data_path = 'http://gdata.youtube.com/feeds/api/videos/' . $video_id . '?v=2&amp;alt=jsonc';
                }
                if ($yt1) { //youtube.com
                    $video = parse_str(parse_url($video, PHP_URL_QUERY), $my_array_of_vars);
                    $video_id = $my_array_of_vars['v'];
                    $data_type = 'youtube_single';
                    $data_path = 'http://gdata.youtube.com/feeds/api/videos/' . $video_id . '?v=2&amp;alt=jsonc';
                }
                if ($vimeo) { //vimeo.com
                    $video_id = substr(parse_url($video, PHP_URL_PATH), 1);
                    $data_type = 'vimeo_single';
                    $data_path = 'http://vimeo.com/api/v2/video/' . $video_id . '.json';
                }
                ?>
                                <li data-type='<?php echo $data_type; ?>' data-path='<?php echo $data_path; ?>'>
                                    <span id="postdata-id-<?php echo $slide_counter; ?>"><?php the_ID(); ?></span>
                                    <span id="postdata-title-<?php echo $slide_counter; ?>"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></span>
                                    <span id="postdata-artist-<?php echo $slide_counter; ?>"><?php echo $gp_settings['artist_short']; ?></span>
                                    <span id="postdata-song-<?php echo $slide_counter; ?>"><?php echo $gp_settings['song_short']; ?></span>
                                    <span id="postdata-link-<?php echo $slide_counter; ?>"><?php the_permalink(); ?></span>
                                    <span id="postdata-extlink-<?php echo $slide_counter; ?>"><?php echo $gp_settings['enc_link']; ?></span>
                                    <span id="postdata-comments-<?php echo $slide_counter; ?>"></span>
                                    <?php if (($theme_show_new_label) && ($gp_settings['unreaded'])) { ?><span id="postdata-mark-read-<?php echo $slide_counter; ?>"><?php echo mar_read_unread_links('', '', false); ?></span><?php } ?>
                                    <span id="postdata-from-to-<?php echo $slide_counter; ?>">
                                    <?php echo $gp_settings['from_flag']; ?><span>FROM: <?php echo $gp_settings['from_user_link']; ?></span>&nbsp;
                                    <?php echo $gp_settings['to_flag']; ?>
                                    <span>TO: <?php echo $gp_settings['to_user_link']; ?></span>
                                    </span>
                                </li>
                        <?php } $slide_counter++; ?> 
                    <?php endwhile; ?>
                </ul>
            </div> <!--  componentPlaylist -->
            <div class="slideshow_controls">
                <?php if ($slide_counter > 1) { ?>                
                <div class="controls_prev"><img src='<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/backward.png' width='11' height='16' alt='controls_prev'/></div>
                <div class="controls_playlist_toggle"><img src='<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/close.png' width='16' height='16' alt='controls_playlist_toggle'/></div>
                <div class="controls_next"><img src='<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/forward.png' width='11' height='16' alt='controls_next'/></div>
                <?php } ?>
                <div class="player_share"><img src='<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/share.png' width='40' height='40' alt=''/></div>

                <div id="shareHolder">
                    <div id="shareHolderInner">
                        <div id="fb-root"></div>
                        <div id='fsbbtn'><a href="https://www.facebook.com/" target='_blank'><img src='<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/facebook.png' width='20' height='20' alt='facebook'/></a></div>
                        <div id='twtbtn'><a href="https://www.twitter.com/" target='_blank'><img src='<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/twitter.png' width='20' height='20' alt='twitter'/></a></div>
                        <div id='gpsbtn'><a href="https://plus.google.com/" target='_blank'><img src='<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/google_plus.png' width='20' height='20' alt='google'/></a></div>
                        <div id='mysbtn'><a href="https://myspace.com/" target='_blank'><img src='<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/myspace.png' width='20' height='20' alt='google'/></a></div>
                    </div>
                </div> 
            </div>            
        </div>
        <div id="dedicationFooter_container">
            <div class="columns two first text-left">
                <h3 id="dedicationArtits"></h3>
                <h4 id="dedicationSong"></h4>
            </div>
            <div class="columns two last">
                <div class="controls_fullscreen"><img src='<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/<?php echo (play_video_on_full_screen()) ? 'fullscreen_exit.png' : 'fullscreen.png'; ?>' width='11' height='16' alt='fullscreen'/></div>                                
                <?php if(function_exists('bp_is_active')) { ?>                
                <a id="dedicate_this_song_button" href="<?php echo bp_loggedin_user_domain() . bp_get_dedication_slug() ?>/new-dedication/" class="button" title="Dedicate this song">Dedicate this song</a>
                <a href="<?php echo bp_loggedin_user_domain() . bp_get_dedication_slug() ?>/new-dedication/" class="button" title="Dedicate a song">Dedicate a song</a>                
                <?php } ?>
            </div>
            
        </div>
    </div>

    <script type="text/javascript">
        function redirect() {
            <?php if ( is_user_logged_in() ) { ?>
                window.location.href = "<?php echo home_url(); ?>";
            <?php } else { ?>
                <?php if (play_video_for_registeres_user()) { ?>
                        window.location.href = "<?php echo home_url(); ?>/login/";    
                    <?php } else { ?>
                        window.location.href = "<?php echo home_url(); ?>/register/";    
                <?php } ?>                        
            <?php } ?>
        }
    </script>

<?php } ?>
<!--End Slider-->        
</div>
