<?php
/**
 * This file is used for your service post media and service entries
 * @package Ultra WordPress Theme
 * @since 1.0
 * @author AJ Clarke : http://wpexplorer.com
 * @copyright Copyright (c) 2012, AJ Clarke
 * @link http://wpexplorer.com
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 */


/******************************************************
* Services Single Posts
* @since 1.0
*****************************************************/
if ( is_singular('services') ) { ?>

	
    <div id="service-post-media">
		<?php
		/*** Video Style ***/
		if( get_post_meta( get_the_ID(), 'wpex_services_post_video', true ) !== '' ) { ?>
            
            <div id="services-post-video" class="fitvids">
                <?php echo wp_oembed_get( get_post_meta( get_the_ID(), 'wpex_services_post_video', true ) ); ?>
            </div><!-- #services-post-video -->	
        
        <?php
        }
		
		/*** FlexSlider Style ***/
		elseif( get_post_meta( get_the_ID(), 'wpex_services_post_slider', true ) !== 'no' ) {
        // Enque Javascript for the services slider
        wp_enqueue_script('services-flexslider');
        
           
           // Get image attachments
            $wpex_services_imgs = get_posts(
                array(
                    'orderby' => 'menu_order',
                    'order' => 'ASC',
                    'post_type' => 'attachment',
                    'post_parent' => get_the_ID(),
                    'post_mime_type' => 'image',
                    'post_status' => null,
                    'posts_per_page' => -1
                )
            ); ?>
            <div id="services-post-slider" class="flexslider-container flex-loading">
                <div class="flexslider">
                    <ul class="slides">
                    <?php
                    //loop through attachments
                    foreach ( $wpex_services_imgs as $wpex_services_img ) : ?>
                        <li class="slide">
                        	<img src="<?php echo aq_resize( wp_get_attachment_url( $wpex_services_img->ID ),  wpex_img( 'services_post_width' ), wpex_img( 'services_post_height' ), wpex_img( 'services_post_crop' ) ); ?>" alt="<?php echo the_title(); ?>" /> 
                        </li>
                    <?php endforeach; ?>
                    </ul><!-- .slides -->
                </div><!-- .flexslider -->
            </div><!-- .flexslider-container -->
    
        <?php
		
        /*** Featured Image Style ***/
        } else {
            if( has_post_thumbnail() ) { ?>
            <div id="services-post-thumbnail">
				<img src="<?php echo aq_resize( wp_get_attachment_url( get_post_thumbnail_id() ),  wpex_img( 'services_post_full_width' ), wpex_img( 'services_post_full_height' ), wpex_img( 'services_post_full_crop' ) ); ?>" alt="<?php echo the_title(); ?>" />
            </div><!-- #services-post-thumbnail -->
        <?php }
        } ?>
        </div><!-- #service-post-media -->
   
<?php } // end is_singular('services') && is_main_query() check
	
	else {



/******************************************************
* Services Entries
* @since 1.0
*****************************************************/
 
 	// Vars
	global $wpex_services_count;
	$wpex_grid_class = of_get_option('services_archive_columns','3'); ?> 
    
    <article class="services-entry grid-<?php echo $wpex_grid_class; if( wpex_service_icon( get_the_ID () ) !=='' ) echo ' service-entry-with-icon'; if ( $wpex_services_count == $wpex_grid_class ) echo ' remove-margin'; ?>">
        <a href="<?php echo wpex_service_url(get_the_ID()); ?>" title="<?php the_title(); ?>" class="services-entry-link">
            <?php
			// Display service icon => see functions/post_types_taxonomies/post-type-helpers.php
            echo wpex_service_icon( get_the_ID() ); ?>
            <h3 class="services-entry-title"><?php the_title(); ?></h3>
        </a><!-- /services-entry-inner -->
        <div class="services-entry-details">
			<?php
			// Show trimmed content if excerpt is blank
			echo ( (!empty($post->post_excerpt) ) ) ? apply_filters('the_content', get_the_excerpt()) : wp_trim_words( strip_shortcodes( get_the_content() ), 17);
			
			// Show read more link if enabled
			if ( of_get_option('services_entry_readmore' ) == '1' ) { ?>
            	<a href="<?php echo wpex_service_url(get_the_ID()); ?>" title="<?php the_title(); ?>" class="services-entry-readmore"><?php _e('read more','wpex'); ?> &rarr;</a>
            <?php } ?>
        </div><!-- /services-entry-details -->
    </article><!-- /services-entry -->
    
	<?php
    if ( $wpex_services_count == $wpex_grid_class ) {
        echo '<div class="clear"></div>'; // Clear Floats
        $wpex_services_count=0; // Reset post counter
    }
    $wpex_grid_class = NULL; // Nullify var

}