<?php
global $redux_demo, $nolazy;
$image1 = get_post_meta($post->ID, '_slider_image1', true);
$image2 = get_post_meta($post->ID, '_slider_image2', true);
$image3 = get_post_meta($post->ID, '_slider_image3', true);
$image4 = get_post_meta($post->ID, '_slider_image4', true);
$image5 = get_post_meta($post->ID, '_slider_image5', true);
$image6 = get_post_meta($post->ID, '_slider_image6', true);
$image7 = get_post_meta($post->ID, '_slider_image7', true);
$image8 = get_post_meta($post->ID, '_slider_image8', true);
$image9 = get_post_meta($post->ID, '_slider_image9', true);
$image10 = get_post_meta($post->ID, '_slider_image10', true);

$title1 = get_post_meta($post->ID, '_slider_title1', true);
$title2 = get_post_meta($post->ID, '_slider_title2', true);
$title3 = get_post_meta($post->ID, '_slider_title3', true);
$title4 = get_post_meta($post->ID, '_slider_title4', true);
$title5 = get_post_meta($post->ID, '_slider_title5', true);
$title6 = get_post_meta($post->ID, '_slider_title6', true);
$title7 = get_post_meta($post->ID, '_slider_title7', true);
$title8 = get_post_meta($post->ID, '_slider_title8', true);
$title9 = get_post_meta($post->ID, '_slider_title9', true);
$title10 = get_post_meta($post->ID, '_slider_title10', true);

$nsfw = get_post_meta($post->ID, '_slider_nsfw', true);

if(is_user_logged_in() ) {
    $userid = wp_get_current_user();
    if(get_user_meta($userid->ID, '_nsfw', true) != 1) {
        $nsfw = 2;
    }
}
$class = 'main-post';
if(is_single() ) {
    $class .= ' post-page';
}
?>
<article <?php post_class($class);?>>
    <?php get_template_part('content', 'header');?>
    <div class="article-content article-id-<?php echo $post->ID;?>">
        <?php get_template_part('content', 'infobar');?>
        <div class="slider-controls-wrap">
            <h2><?php _e('Slider', 'Aruna');?></h2>
            <?php
            for($i=1; $i<=10; $i++) {
                if($i==1) {
                    echo '<h1 rel="1" class="visible-title">' . $title1 . '</h1>';
                }
                else {
                    $var = 'title' . $i;
                    echo '<h1 rel="' . $i . '">' . $$var . '</h1>';
                }
            }
            ?>
            <div class="controls">
                <a href="#" class="prev">Prev</a>
                <div class="counters"> <span class="current">1</span> <?php _e('of', 'Aruna');?> <span class="total">5</span> </div>
                <a href="#" class="next">Next</a>
            </div>
        </div>
        <figure <?php if($nsfw == 1) echo 'class="nsfw"';?>>
            <div class="post-slider flexslider">
                <ul class="slides">
                    <?php
                    for($i=1; $i<=10; $i++) {
                        $var = 'image' . $i;
                        if($$var != '') {
                            if($i == 1) {
                                if($nolazy == 1) { 
                                    echo '<li><a href="' . get_permalink() . '"><img src="' . aq_resize($$var, 635, null, true) . '" alt="' . get_the_title() . ' - image ' . $i . '" /></a></li>';
                                } else { 
                                    echo '<li><a href="' . get_permalink() . '"><img class="lazy" data-original="' . aq_resize($$var, 635, null, true) . '" alt="' . get_the_title() . ' - image ' . $i . '" /></a></li>';
                                }
                            }
                            else {
                                echo '<li><a href="' . get_permalink() . '"><img src="' . aq_resize($$var, 635, null, true) . '" alt="' . get_the_title() . ' - image ' . $i . '" /></a></li>';
                            }
                        }
                    }
                    ?>
                </ul>
            </div>
            <div class="nsfw_text"><?php _e('Not safe for work', 'Aruna');?></div>
            <div class="nsfw_textreveal"><?php _e('Click here to reveal', 'Aruna');?></div>
        </figure>
    </div>
</article>
<script>
    jQuery(document).ready(function() {
        jQuery('.article-id-<?php echo $post->ID;?> .post-slider').flexslider({
            'controlNav': false,
            'directionNav' : false,
            "touch": true,
            "animation": "slide",
            "animationLoop": true,
            "slideshow" : false,
            start : function(ev) {
                var slideTotal = ev.find('li:not(".clone") img').length;
                var slideCurrent = ev.find('li:not(".clone").flex-active-slide').index();
                jQuery('.article-id-<?php echo $post->ID;?> .slider-controls-wrap .counters .total').text(slideTotal);
                jQuery('.article-id-<?php echo $post->ID;?> .slider-controls-wrap .counters .current').text(slideCurrent);
            },
            after : function(ev) {
                var slideCurrent = ev.find('li:not(".clone").flex-active-slide').index();
                jQuery('.article-id-<?php echo $post->ID;?> .slider-controls-wrap .counters .current').text(slideCurrent);
                jQuery('.article-id-<?php echo $post->ID;?> .slider-controls-wrap h1.visible-title').removeClass('visible-title');
                jQuery('.article-id-<?php echo $post->ID;?>  .slider-controls-wrap h1[rel="'+slideCurrent+'"]').addClass('visible-title');
            }
        });

        jQuery('.article-id-<?php echo $post->ID;?> .slider-controls-wrap .next').click(function() {
            jQuery('.article-id-<?php echo $post->ID;?> .post-slider').flexslider('next');
            return false;
        });
        jQuery('.article-id-<?php echo $post->ID;?> .slider-controls-wrap .prev').click(function() {
            jQuery('.article-id-<?php echo $post->ID;?> .post-slider').flexslider('prev');
            return false;
        });

    });
</script>