<?php

global $post;

$restorator_postid = get_the_ID();

$restorator_width = 1170;
$restorator_height = 650;
if( isset($style) && ( $style == 'grid_top_img' || $style == 'masonry_top_img' ) ) {
	if( $columns != 'col1' ) {
		$restorator_width = 550;
		$restorator_height = 400;
	} else {
		$restorator_width = 1170;
		$restorator_height = 700;
	}
}
if( isset($style) && ( $style == 'grid_card' || $style == 'masonry_card' ) ) {
	if( $columns != 'col1' ) {
		$restorator_width = 670;
		$restorator_height = 450;
	} else {
		$restorator_width = 1170;
		$restorator_height = 610;
	}
}

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

if (!empty($gallery_image_ids)) {
	$restorator_posts_image_gallery = get_post_meta($restorator_postid, 'gallery_image_ids', true);
} else {
	// Backwards compat
	$attachment_ids = get_posts('post_parent=' . $restorator_postid . '&numberposts=-1&post_type=attachment&orderby=menu_order&order=ASC&post_mime_type=image&fields=ids');
	$attachment_ids = array_diff($attachment_ids, array(get_post_thumbnail_id()));
	$restorator_posts_image_gallery = implode(',', $attachment_ids);
}

$attachments = array_filter(explode(',', $restorator_posts_image_gallery));

    if ($attachments) {
        echo '<div class="post-slider owl-carousel clearfix">';
			foreach ($attachments as $attachment) {
				$featured_image_url = wp_get_attachment_url( $attachment );
				$attachment_title = get_the_title( $attachment );
				echo '<div class="item">';
					echo '<img src="' . restorator_aq_resize( $featured_image_url, $restorator_width, $restorator_height, true, true, true ) . '" alt="' . esc_attr( $attachment_title ) . '" />';
				echo '</div>';
				?>
			<?php  }
        echo '</div>';
    }
?>
<script type="text/javascript">
	function restorator_post_gallery_carousel() {
		jQuery('.post_format_content .post-slider.owl-carousel').owlCarousel({
			items: 1,
			margin: 0,
			dots: true,
			nav: true,
			navText: [
				"<i class='fa fa-angle-left'></i>",
				"<i class='fa fa-angle-right'></i>"
			],
			loop: true,
			autoplay: true,
			autoplaySpeed: 1000,
			autoplayTimeout: 5000,
			navSpeed: 1000,
			autoplayHoverPause: true,
			thumbs: false
		});
	}
	jQuery(window).load(function() {
		restorator_post_gallery_carousel();
	});
</script>