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

require(ghostpool_inc . 'options.php');

if ( is_user_logged_in() ):

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

//if (is_home() || is_front_page()) {
    $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 (have_posts()) {
    
    $slide_counter = 0;
?>    

    <!--Begin Slider Wrapper-->
    <div id="slider-wrapper">
        <div id="dedicationTitle_container"><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="wp-content/themes/score/lib/scripts/videoslider/data/icons/thumb_backward_v.png" alt="" width="31" height="21" /></div>	
                <div class="thumbForward"><img src="wp-content/themes/score/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();    
        
        // Si ya hemos visto más de 'posts_per_page' dedicatorias, salgo del buble
        if ($slide_counter == $posts_per_page) {
            break;
        }
    
        $from_user_id = get_the_author_meta('ID');
        $to_user_id = get_post_meta($post->ID, 'ghostpool_destination_user_id', true);
        $to_user = get_user_by('id', $to_user_id);
        $to_user_email = get_post_meta($post->ID, 'ghostpool_destination_user_email', true);
        $displayed_id = bp_displayed_user_id();
        
        echo "post->ID => " . $post->ID;
        echo "from_user_id => " . $from_user_id;
        echo "to_user_id => " . $to_user_id;
        echo "displayed_id " . $displayed_id;
        
        // En el perfil del usuario sólo mostrar las dedicadas por él y para él. El resto se descartan.
        if ( bp_is_active( 'dedications' ) ) {
            if (($displayed_id != $from_user_id) && ($displayed_id != $to_user_id)) {
                continue; // me salto esta dedicatoria
            }
        }

        // Usuario actual puede ver la dedicatoria?
        if (get_post_status($post-ID) == 'private') {
            if (($current_user->ID != $from_user_id) && ($current_user->ID != $to_user_id)) {
                continue; // me salto esta dedicatoria
            }
        }
                            
            $video = get_post_meta($post->ID, 'ghostpool_dedication_url', true);
            $artist = get_post_meta($post->ID, 'ghostpool_dedication_artist', true);
            $song = get_post_meta($post->ID, 'ghostpool_dedication_song', true);

            // 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-title-<?php echo $slide_counter; ?>"><?php the_title(); ?></span>
                                    <span id="postdata-artist-<?php echo $slide_counter; ?>"><?php echo $artist; ?></span>
                                    <span id="postdata-song-<?php echo $slide_counter; ?>"><?php echo $song; ?></span>
                                    <span id="postdata-comments-<?php echo $slide_counter; ?>">
                                        <?php require('home-comments.php'); ?>
                                    </span>
                                    <span id="postdata-from-to-<?php echo $slide_counter; ?>">
                                    <?php                                
                                    gp_the_flag($from_user_id);
                                    ?>
                                    <span>FROM: <?php echo bp_core_get_userlink($from_user_id); ?></span>
                                    <?php                                 
                                    if ($to_user) {
                                        gp_the_flag($to_user->ID);
                                        ?><span>TO: <?php echo bp_core_get_userlink($to_user->ID); ?></span>
                                    <?php } else { ?>
                                        <?php gp_the_flag(); ?>
                                        <span>TO: <?php echo get_post_meta($post->ID, 'ghostpool_destination_user_name', true); ?></span>
                                    <?php } ?>
                                    </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="shareme" data-url="" data-text="Make your sharing widget with Sharrre"></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>
                </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">
                <?php if(function_exists('bp_is_active')) { ?>                
                <a href="<?php echo bp_loggedin_user_domain() . bp_get_dedication_slug() ?>/new-dedication/" class="button">Dedicate this song</a>
                <a href="<?php echo bp_loggedin_user_domain() . bp_get_dedication_slug() ?>/new-dedication/" class="button">Dedicate a song</a>                
                <?php } ?>
            </div>
            
        </div>
    </div>

    <script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/lib/scripts/jquery.jtypewriter.js"></script>  
    
    <script type="text/javascript">
        var aIndex=-1;
        jQuery.noConflict();

        jQuery(window).load(function() {
            jQuery('#componentWrapper').videoGallery({			
                componentFixedSize: true,
                animateVideoSizeOnPlaylistClose: true,
                thumbOrientation: 'vertical',
                activePlaylist:'playlist',
                activeVideo:0,
                autoPlay:true,
                loopingOn:true,
                randomPlay:false,
                autoAdvanceToNextVideo:true,
                youtubeChromeless:true,
                thumbWidth: 120,
                thumbHeight: 90,
                thumbsScrollValue: 150,
                autoOpenPlaylist: false,
                closePlaylistOnVideoSelect: false,
                thumbBackgroundColor: '#fff',
                iconLoader: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/loader.gif',
                iconClose: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/close.png',
                iconCloseOn: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/close_on.png',
                iconOpen: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/open.png',
                iconOpenOn: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/open_on.png',
                iconBackwardOn: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/backward_on.png',
                iconBackward: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/backward.png',
                iconForwardOn: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/forward_on.png',
                iconForward: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/forward.png',
                iconShare: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/share.png',
                iconShareOn: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/share_on.png',
                iconThumbForward: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/thumb_forward.png',
                iconThumbForwardV: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/thumb_forward_v.png',
                iconThumbForwardOn: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/thumb_forward_on.png',
                iconThumbForwardVOn: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/thumb_forward_v_on.png',
                iconThumbBackward: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/thumb_backward.png',
                iconThumbBackwardV: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/thumb_backward_v.png',
                iconThumbBackwardOn: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/thumb_backward_on.png',
                iconThumbBackwardVOn: '<?php echo get_template_directory_uri(); ?>/lib/scripts/videoslider/data/icons/thumb_backward_v_on.png'
                
            });
            setInterval("updateInfo()", 500);
        });

        function updateInfo() {
            var id = jQuery.fn.videoGallery.getMediaID();
            
            if ((aIndex != id) && (id >= 0)) {
                aIndex = id;

                var new_title = jQuery('#postdata-title-' + id).text();
                var from_to = jQuery('#postdata-from-to-' + id).html();
                var artist = jQuery('#postdata-artist-' + id).html();
                var song = jQuery('#postdata-song-' + id).html();
                var comments = jQuery('#postdata-comments-' + id).html();

                jQuery('#dedication-data-panel').hide('fast');
                jQuery('#dedication-data-panel').slideUp(
                    'fast',
                    function() { jQuery('#dedication-data-panel').html(from_to); }
                );
                jQuery('#dedication-data-panel').slideDown();
                
                jQuery('#dedicationFooter_container').slideUp(
                    'fast',
                    function() { 
                        jQuery('#dedicationArtits').html(artist);
                        jQuery('#dedicationSong').html(song);
                    }
                );
                jQuery('#dedicationFooter_container').slideDown(
                    'fast',
                    function() {}
                );
                jQuery('#dedicationTitle').html(new_title); 
                shrinkTitle(); 
                jQuery('#dedicationTitle').jTypeWriter(); 

                jQuery('#dedicationComments_container').slideUp(
                    'fast',
                    function() { jQuery('#dedicationComments_container').html(comments); }
                );                
                jQuery('#dedicationComments_container').slideDown();
            }
        }
                            
        function shrinkTitle()
        {
            var textH1 = document.getElementById("dedicationTitle");
            var textDiv = document.getElementById("dedicationTitle_container");

            textH1.style.fontSize = 42+"px";
            while(textH1.offsetWidth > textDiv.offsetWidth)
            {
                size = parseInt(textH1.style.fontSize.replace("px",""));
                size -= 1;
                textH1.style.fontSize = size+"px";
            }
            textH1.style.fontSize -= 10+"px";
        }

                            
        jQuery('#shareme').sharrre({
            share: {
                googlePlus: true,
                facebook: true,
                twitter: true
            },
            buttons: {
                googlePlus: {size: 'medium'},
                facebook: {layout: 'button_count'},
                twitter: {count: 'horizontal'}
            },
            enableHover: false,
            enableCounter: false,
            enableTracking: false
        });                
    </script>

<?php } ?>

<!--End Slider-->        



<?php endif; ?>



