<?php
/**
 * @version	$Id$
 * @package	IT_Theme_Framework
 * @author	 InnoThemes Team <support@innothemes.com>
 * @copyright  Copyright (C) 2012 InnoThemes.com. All Rights Reserved.
 * @license	GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
 *
 * Websites: http://www.innothemes.com
 */

$loop = new WP_query(
	array(
		'post_type'      => 'portfolio',
		'posts_per_page' => 8,
		'orderby'        => 'ASC'
	)
);

$count       = 0;
$arr_content = array();
while( $loop->have_posts() ) :
	$loop->the_post();
$count++;

$url 	= get_post_meta($post->ID, "url", true);
$urlimg	= get_post_meta($post->ID, 'urlimg', true);
$src 	= wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), true, '' );
$str 	= '';

if( $url != '' ) {
	$str .= '<li class="it-project"><div class="it-project-thumb"><a class="fancybox" href="' . $urlimg . '"><img src="' . $url . '" />';
	$str .= '<span class="mark"></span>';
	$str .= '</a><span class="portfolio-cat">';
	$str .= get_the_title();
	$str .= '</span></div></li>';
} else {
	$str .= '<li class="it-project"><div class="it-project-thumb"><a class="fancybox" href="' . $src[0] . '">';
	$str .= get_the_post_thumbnail( $page->ID, 'portthumb' );
	$str .= '<span class="mark"></span>';
	$str .= '</a><span class="portfolio-cat">';
	$str .= get_the_title();
	$str .= '</span></div></li>';
}
$arr_content[] = $str;

endwhile;  wp_reset_query();
if( $count ): ?>
<ul id="it-recent-project">
	<link href="<?php echo IT_THEME_URI . '/assets/3rd-party/fancybox/jquery.fancybox.css' ?>" rel="stylesheet">
	<script src="<?php echo IT_THEME_URI . '/assets/3rd-party/fancybox/jquery-1.10.1.min.js' ?>"></script>
	<script src="<?php echo IT_THEME_URI . '/assets/3rd-party/fancybox/jquery.fancybox.js' ?>"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			$("a.fancybox").fancybox();
		});
	</script>

	<h3 class="it-title"><?php _e( 'Recent Projects', IT_THEME_TEXTDOMAIN ); ?></h3>

	<?php echo implode( "", $arr_content ); ?>

    <div class="it-viewall-portfolio">
    	<a href="<?php echo get_post_type_archive_link( 'portfolio' ); ?>"><?php _e( 'See All Projects', IT_THEME_TEXTDOMAIN ); ?></a>
    </div><!--End div.it-viewall-portfolio-->

	<div class="it-separate"></div>
</ul><!--End ul#it-recent-project-->
<?php endif;?>
