<!-- THIS IF FOR AJAX COMMENTS AND MAKES COMMENTING REAL-TIME -->
<?php
foreach ($project['comments'] as $comment) {
//    if (empty($comment['user']['name']) && $comment['is_sms'])
//        $comment['user']['name'] = $comment['user']['phone'];
//
//    	$sms_class = $comment['is_sms'] ? " sms" : "";
    if($comment['parent_id'] !=0){
    	// Then it's a sub-comment, so skip it.
    	continue;
    }
?>
<style>
.other-post-item .thumb-left {
  height: 90px;
  border: 1px solid #eee;
}  
.media {
	border-bottom: 1px solid #efefef !important;
}
input[type="submit"]{
	background:#000;
	color:#fff;
	border:0px;
	padding:10px 20px;
	border-radius: 4px;
	-moz-border-radius: 4px;
	-webkit-border-radius: 4px;	
}
/*.other-post-item .thumb-left {
  width: 90px;
  height: 90px;
  border: 1px solid #d4d4d4;
  padding: 1px;
  background: #FFF;
  border-radius: 0px;
  -moz-border-radius: 0px;
  -webkit-border-radius: 0px;
}*/
</style>

<div class="media other-post-item comment-item<?= $sms_class ?>" 
data-comment-id="<?= $comment['id'] ?>" style="border-bottom:1px solid #ddd; 
padding:15px;">
    
    <div style="float:left; height:80px; width:80px; overflow:hidden; border:4px solid #eee; 
        background:#777; border-radius:50%; -moz-border-radius:50%; -webkit-border-radius:50%; 
        text-align:center; margin-right:10px; margin-bottom:0px;">
        
		<a href="/profile/<?= $comment['user']['user_slug'] ?>" class="thumb-leftxxx"><img
			src="<?= $comment['user']['image'] ?>" alt="<?= $comment['user']['name'] ?>"
			onerror="this.src='/static/system/default_avatar.png'"
			style="border-radius:0px; min-width:100%; width:auto; min-height:100%; height:auto;"></a>
    </div>
    <div class="media-body">
    	<?php if($project['user_id'] == $comment['user']['id']) { ?>
		<div style="height:15px; line-height:15px; font-size:9px; background:#f4f4f4; width:auto; 
		max-width:50px; color:#000; padding:0 3px; text-align:center; border-radius:4px; 
		-moz-border-radius:4px; -webkit-border-radius:4px;">
			POSTER
		</div>
		<?php } ?>
		<p class="rs fc-gray time-post pb10" style="padding-bottom:0px;">
        	<a href="/profile/<?= $comment['user']['user_slug'] ?>" 
        	class="be-fc-orange fw-b"><?= $comment['user']['name'] ?>&nbsp;</a>
			<span style="font-weight:300;"><?= time_elapsed_string($comment['date_created']) ?></span>
			<!--<?= date("m/d/y", strtotime($comment['date_created'])); ?>-->
        	<!--<?= $comment['user']['comments_count'] ?> Comments-->
        </p>
        
        <!--<input name="project_id" type="hiddenX" value="<?= $comment['project_id'] ?>" />-->
        
		<input name="parent_id" type="hidden" value="<?= $comment['id'] ?>" />
		
        <input name="project_id" type="hidden" value="<?= $comment['project_id'] ?>" />
        
        <?= $comment['content']; ?>
        
        <!--  first reply button - THIS IS THE MAIN REPLY BUTTON/LINK T-->
        <?php if($_SESSION['user']['id']) { ?>
	        <div class='comment_actions'>
		    	<a href='javascript:;' comment_id='<?= $comment['id'] ?>' project_id='<?= $comment['project_id'] ?>'
		    	onclick='maincommentReply(this)' title='<?= $comment['id'] ?>'>Reply</a> |
				<?php
				if ($_SESSION['user']['is_admin'] || $_SESSION['user']['id'] == $comment['user']['id']) { ?>
					<a href='?comment&delete=<?= $comment['id'] ?>' 
					comment_id='<?= $comment['id'] ?>' style='color:#ff0000;'>Delete</a>
					<?php } ?>
			</div>
			<div class='clear'></div>	
		<?php } else { ?>
			<div class='comment_actions'>
				&nbsp;
			</div>
		<?php } ?>
		<br />                            
    </div>
    
    <!-- THIS IS A SUB-COMMENT REPLY, WHICH SHOULD SIMPLY POST IT UNDER THE SAME PARENT AND UNDER THE SUB-COMMENT. -->
    
	<?php 
	asort($project['comments']);
		foreach ($project['comments'] as $subcomment) { 
			if($subcomment['parent_id']==0){
				// Then it's a Main Comment, so skip it
				continue;
			}
			
			if($subcomment['parent_id'] != $comment['id']){
				continue;
			}
	?>

	<!-- SUBCOMMENTS START HERE -->
	 <!-- 2nd reply button - THREADED REPLY / SUBCOMMENT DIV -->
	<div style="display:nonex; background:none; margin-top:20px; margin-left:40px;">
		<div style="float:left; height:40px; width:40px; overflow:hidden; border:4px solid #eee;
			        background:#777; border-radius:50%; -moz-border-radius:50%; -webkit-border-radius:50%;
			        text-align:center; margin-right:10px; margin-bottom:0px;">

			<a href="/profile/<?= $subcomment['user']['user_slug'] ?>" class="thumb-leftxxx"><img
				src="<?= $subcomment['user']['image'] ?>" alt="<?= $subcomment['user']['name'] ?>"
				onerror="this.src='/static/system/default_avatar.png'"
				style="border-radius:0px; min-width:100%; width:auto; min-height:100%; height:auto;"></a>
		</div>
		<div class="media-body">
		    <?php if($project['user_id'] == $subcomment['user']['id']) { ?>
			<div style="height:15px; line-height:15px; font-size:9px; background:#f4f4f4; width:auto; max-width:50px; 
				color:#000; padding:0 3px; text-align:center; border-radius:4px; -moz-border-radius:4px;
				 -webkit-border-radius:4px;">
				POSTER
			</div>
			<?php } ?>
			<p class="rs fc-gray time-post pb10" style="padding-bottom:0px">
				<a href="/profile/<?= $subcomment['user']['user_slug'] ?>"
			        	class="be-fc-orange fw-b"><?= $subcomment['user']['name'] ?>&nbsp;</a>
				<span style="font-weight:300;"><?= time_elapsed_string($subcomment['date_created']) ?></span>
				<!-- <?= $subcomment['date_created'] ?> -->
				<!--/ <?= $subcomment['user']['comments_count'] ?> Comments-->
			</p>

			<?= $subcomment['content']; ?>

			<!-- THIS IS THE SUBCOMMENT'S REPLY BUTTON -->
			<?php
			if ($_SESSION['user']['id']) { ?>
			<div class='comment_actions' style='background:none'>
				<a href='javascript:;' comment_id='<?= $subcomment['id'] ?>' project_id='<?= $comment['project_id'] ?>'
				    	onclick='maincommentReply(this)'>Reply</a> | <?php
						if ($_SESSION['user']['is_admin']) { ?>
				<a href='?comment&delete=<?= $subcomment['id'] ?>' comment_id='<?= $subcomment['id'] ?>'
							style='color:#ff0000;'>Delete</a>
				<?php } ?>
			</div>
			<div class='clear'></div>
			<?php } else { ?>
			<div class='comment_actions' style='background:none'>
				&nbsp;
			</div>
			<?php } ?>
		</div>
	</div>
	<!-- THREADED REPLY / SUBCOMMENT DIV ENDS -->

	<?php } ?> 
    
</div>

<?php
}
?>