<?php if( ! defined( 'ABSPATH' ) ) exit;

/**
 * Enqueue scripts and styles marquee.
 */
function faster_marquee_scripts() {	
	wp_enqueue_style( 'faster-marquee-css', get_template_directory_uri() . '/include/marquee/marquee.css' );
	wp_enqueue_script( 'faster-jquery-marquee-js', get_template_directory_uri() . '/include/marquee/jquery.marquee.js', array(), '', true);
}
add_action( 'wp_enqueue_scripts', 'faster_marquee_scripts' );


function faster_marquee_vert () {
?>
<div class='marquee-vert' data-direction='down' data-pauseOnHover='true' data-pauseOnCycle='true'>
	
	<?php
	   $the_query = new WP_Query( array(  'ignore_sticky_posts' => 1 ) );
	if ( $the_query->have_posts() ) {
        while ( $the_query->have_posts() ) {
    $the_query->the_post(); 
	?>
		<div><a href="<?php echo esc_url( get_permalink() ); ?>"><?php echo esc_html( get_the_title() ); ?> </a></div>
	<?php
		}
	}
	/* Restore original Post Data */
	wp_reset_postdata();
	?>
	
</div>
	<?php
}


function faster_script_marquee () { ?>
	<script>
		jQuery(function(jQuery){
		  var $mwo = jQuery('.marquee-with-options');


		  //Direction upward
		  jQuery('.marquee-vert').marquee({
			direction: 'up',
			speed: <?php if ( get_theme_mod( 'faster_sticky_speed') ) { echo esc_html ( get_theme_mod( 'faster_sticky_speed') ); } else echo "200"; ?>,
			delayBeforeStart: 0,
			startVisible: false
		  });

		  //pause and resume links
		  jQuery('.pause').on("click",function(e){
			e.preventDefault();
			$mwo.trigger('pause');
		  });
		  jQuery('.resume').on("click",function(e){
			e.preventDefault();
			$mwo.trigger('resume');
		  });
		  //toggle
		  jQuery('.toggle').on("hover",function(e){
			$mwo.trigger('pause');
		  },function(){
			$mwo.trigger('resume');
		  })
		  .on("click",function(e){
			e.preventDefault();
		  })
		});
	</script>
<?php }

add_action('wp_head','faster_script_marquee');