<?php
// Add classes for Landing Page Template
add_filter( 'body_class','eth_body_classes' );
function eth_body_classes( $classes ) {

	if ( is_page_template( 'landing-page.php' ) ) {
		$classes[] = esc_attr( 'landing-page' );	
	}
	
	return $classes;
}


// Filters title and highlight word from settings
function eth_filter_title( $title, $highlight ) {
	$highlight = empty( $highlight ) ? '' : $highlight;
	$title = str_replace( $highlight, '<span class="title-highlight">' . $highlight .'</span>', $title );

	return $title;
}


// Google Analytics
if ( ot_get_option('eth_google_analytics_insert') == 'header' ) {
	add_action( 'wp_head', 'eth_google_analytics', 9999 );
} elseif ( ot_get_option('eth_google_analytics_insert') == 'footer' ) {
	add_action( 'wp_footer', 'eth_google_analytics', 9999 );
}
function eth_google_analytics() {
	echo ot_get_option('eth_google_analytics');
}


// Display post meta
function eth_post_meta() {
	?>
	<!-- date -->
	<span class="post-meta-date">
		<i class="fa fa-clock-o"></i> <a href="<?php esc_url( the_permalink() ); ?>"><?php echo __( get_the_date('d M , Y') , 'eth-theme'); ?></a>
	</span>
	<!-- comments -->
 	<span class="comments-span">
  	<i class="fa fa-comments"></i> <a href="<?php esc_url( the_permalink() ); ?>#comments"><?php comments_number( __( 'Leave a comment', 'eth-theme' ), __( '1 Comment', 'eth-theme' ), __( '% Comments', 'eth-theme' ) ); ?></a>
  </span>
  <!-- categories -->
	<span class="post-meta-categories">
		<i class="fa fa-folder-open"></i><?php the_category( _x( ', ', 'Used between list items, there is a space after the comma.', 'focus-theme' ) ); ?>
	</span>
	<!-- tags -->
	<span class="post-meta-tags">
		<i class="fa fa-tags"></i><?php the_tags(' '); ?>
	</span>
	<?php
}


// Dipslay comment form
function eth_custom_comment_form() {
	$commenter = wp_get_current_commenter();
	$req = get_option( 'require_name_email' );
	$aria_req = ( $req ? " aria-required='true'" : '' );

	$fields =  array(
		// 'author' =>
		//   '<p class="comment-form-author">
		// 	  <input id="name" name="name" type="text" value="' . esc_attr( $commenter['comment_author'] ) .
		// 	  '" size="30" placeholder="'. esc_attr( __( '*Enter your name...', 'eth-theme' ) ) .'" />
		//   </p>',

		// 'email' =>
		//   '<p class="comment-form-email">
		// 	  <input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) .
		// 	  '" size="30" placeholder="'. esc_attr( __( '*Enter your email...', 'eth-theme' ) ) .'" />
		//   </p>',

		// 'url' =>
		//   '<p class="comment-form-url">
		//   	<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) .
		// 	  '" size="30" placeholder="'. esc_attr( __( 'Enter your website...', 'eth-theme' ) ) .'" />
		// 	</p>',
	'author' =>
    '<p class="comment-form-author"><label for="author"><input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .
    '" size="30"' . $aria_req . ' placeholder="'. esc_attr( __( '*Enter your name...', 'eth-theme' ) ) .'"/></p>',

  'email' =>
    '<p class="comment-form-email"><label for="email"><input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) .
    '" size="30"' . $aria_req . ' placeholder="'. esc_attr( __( '*Enter your email...', 'eth-theme' ) ) .'"/></p>',

  'url' =>
    '<p class="comment-form-url"><label for="url"><input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) .
    '" size="30" placeholder="'. esc_attr( __( 'Enter your website...', 'eth-theme' ) ) .'"/></p>',		
	);


	$comment_args = array(
	  'title_reply'       => __( 'Leave a comment', 'eth-theme' ),
	  'title_reply_to'    => __( 'Leave a reply to %s', 'eth-theme' ),
	  'cancel_reply_link' => "<span class='cancel-reply-link'>" . __( 'Cancel reply', 'eth-theme' ) . "</span>",
	  'label_submit'      => __( 'Post Comment', 'eth-theme' ),
	  'fields' 						=> $fields,
	  'comment_field' 		=> '<p class="comment-form-comment"><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" placeholder="' . esc_attr( __( '*Enter your comment...', 'eth-theme' ) ) . '"></textarea></p>'
	);

	comment_form( $comment_args );
}



// Add animate.css settings
add_action( 'wp_footer', 'eth_animations', 99 );
function eth_animations() {

	if ( 'disable' == ot_get_option( 'eth_disable_animation_mobile' ) ) {
		$is_animation_disabled = 1;
	} else {
		$is_animation_disabled = 0;
	}
?>
<script type="text/javascript">
(function($) {
"use strict";
$(document).ready(function() {

	if ( <?php echo $is_animation_disabled; ?> == 1 && $('body').hasClass('is-mobile-js') ) {
		return;
	} 



	// Home section
	<?php if ( ot_get_option('eth_home_image_anim') !== 'none' ) : ?>
		$('.home-image').addClass('animated <?php echo ot_get_option( 'eth_home_image_anim' ); ?>');
	<?php endif; ?>


	// Features section
	<?php if ( ot_get_option('eth_features_list_anim') !== 'none' ) : ?>
		$('.feature').addClass('opacity-zero');

		$('.features').waypoint( function() {
			$('.feature').each( function ( i ) {
				$(this).css({
					'animation-delay' : (i * 0.3) + "s",
					'-webkit-animation-delay' : (i * 0.3) + "s",
					'-moz-animation-delay' : (i * 0.3) + "s",
					'-ms-animation-delay' : (i * 0.3) + "s",
					'-o-animation-delay' : (i * 0.3) + "s"
				});
			});

			$('.feature')
				.removeClass('opacity-zero')
				.addClass('animated opacity-one <?php echo ot_get_option('eth_features_list_anim'); ?>');
		}, {offset: 400});
	<?php endif; ?>


	// Overview section
	<?php if ( ot_get_option('eth_overview_list_anim') !== 'none' ) : ?>
		// Chapters
		$('.chapter-block').addClass('opacity-zero');

		$('.overview').waypoint( function() {
			$('.chapter-block').each( function ( i ) {
				$(this).css({
					'animation-delay' : (i * 0.1) + "s",
					'-webkit-animation-delay' : (i * 0.1) + "s",
					'-moz-animation-delay' : (i * 0.1) + "s",
					'-ms-animation-delay' : (i * 0.1) + "s",
					'-o-animation-delay' : (i * 0.1) + "s"
				});
			});

			$('.chapter-block')
				.removeClass('opacity-zero')
				.addClass('animated opacity-one <?php echo ot_get_option('eth_overview_list_anim'); ?>');

		}, {offset: 400});
	<?php endif; ?>
	<?php if ( ot_get_option('eth_overview_product_image_anim') !== 'none' ) : ?>
		// Product image
		$('.product-sample').addClass('opacity-zero');

		$('.product-sample').waypoint( function() {
			$(this)
				.removeClass('opacity-zero')
				.addClass('animated opacity-one <?php echo ot_get_option('eth_overview_product_image_anim'); ?>');
		}, {offset: 800});
	<?php endif; ?>
	

	// CTA section
	<?php if ( ot_get_option('eth_cta_button_anim') !== 'none' ) : ?>
		$('.cta .purchase-button').addClass('opacity-zero');

		$('.cta').waypoint( function() {
			$('.cta .purchase-button')
				.removeClass('opacity-zero')
				.addClass('animated opacity-one <?php echo ot_get_option('eth_cta_button_anim'); ?>');
		}, {offset: 550});
	<?php endif; ?>


	// Testimonials section
	<?php if ( ( ot_get_option('eth_testimonials_anim_even') !== 'none' ) || ( ot_get_option('eth_testimonials_anim_odd') !== 'none' ) ) : ?>
		$('.testimonial').addClass('opacity-zero');

		$('.testimonials').waypoint( function() {

			$('.testimonial').each( function ( i ) {
				$(this).css({
					'animation-delay' : (i * 0.3) + "s",
					'-webkit-animation-delay' : (i * 0.3) + "s",
					'-moz-animation-delay' : (i * 0.3) + "s",
					'-ms-animation-delay' : (i * 0.3) + "s",
					'-o-animation-delay' : (i * 0.3) + "s"
				});
			});

			$('.testimonial:nth-child(2n)')
				.removeClass('opacity-zero')
				.addClass('animated opacity-one <?php echo ot_get_option('eth_testimonials_anim_even'); ?>');
			$('.testimonial:nth-child(2n+1)')
				.removeClass('opacity-zero')
				.addClass('animated opacity-one <?php echo ot_get_option('eth_testimonials_anim_odd'); ?>');
		}, {offset: 400});
	<?php endif; ?>


	// Purchase section
	<?php if ( ot_get_option('eth_pricetable_anim') !== 'none' ) : ?>

		// hide it first
		$('.price-table').addClass('opacity-zero');

		$('.purchase').waypoint( function () {

			$('.price-table').each( function ( i ) {
				$(this).css({
					'animation-delay' : (i * 0.1) + "s",
					'-webkit-animation-delay' : (i * 0.1) + "s",
					'-moz-animation-delay' : (i * 0.1) + "s",
					'-ms-animation-delay' : (i * 0.1) + "s",
					'-o-animation-delay' : (i * 0.1) + "s"
				});
			});


			<?php
			$tables = ot_get_option( 'eth_pricetable_list', array() );
			if ( ! empty( $tables ) ) :
				foreach( $tables as $key => $table ) :

				?>

					// get each table's animation separately from option list
					$('.price-table:nth-child( <?php echo $key + 1; ?> )')
						.removeClass('opacity-zero')
						.addClass('animated opacity-one <?php echo $table['eth_pricetable_anim']; ?>');

				<?php
				endforeach; // foreach( $tables as $key => $table )
			endif; // if ( ! empty( $tables ) )
			?>


		}, {offset: 400});
	<?php endif; ?>

		


});
}(jQuery));
</script>
<?php
} // eth_animations()