<?php /* Querystring is set via AJAX in _inc/ajax.php - bp_dtheme_object_filter() */ 
?>

<?php do_action( 'bp_before_groups_loop' ) ?>

<?php 

if($_GET['id'] != null){
$user_id = $_GET['id'];
}else{
$user_id = false;
}
if ( bp_has_groups( bp_ajax_querystring( 'groups' ), $user_id) ) :
?>

	<div id="pag-top" class="pagination">

		<div class="pag-count" id="group-dir-count-top">
			<?php bp_groups_pagination_count() ?>
		</div>

		<div class="pagination-links" id="group-dir-pag-top">
			<?php bp_groups_pagination_links() ?>
		</div>

	</div>

	<?php do_action( 'bp_before_directory_groups_list' ) ?>

	<ul id="groups-list" class="item-list">
	<?php while ( bp_groups() ) : bp_the_group(); ?>
	
		<?php
		$group_mood = groups_get_groupmeta(bp_get_group_id(), 'ironestado'); 
		// Color del post
		$classbackground='';
		if ($group_mood == "familiares") $classbackground="av01";
		elseif ($group_mood == "sintomaticos") $classbackground="av03";
		elseif ($group_mood == "reflexivos") $classbackground="av02";
		elseif ($group_mood == "transgresores") $classbackground="av04";	
		?>

		<li>
			<div class="item-avatar <?php echo $classbackground; ?>">
				<a href="<?php bp_group_permalink() ?>"><?php bp_group_avatar( 'type=thumb&width=50&height=50' ) ?></a>
			</div>

			<div class="item">
				<div class="item-title"><a href="<?php bp_group_permalink() ?>"><?php bp_group_name() ?></a></div>
				<div class="item-meta">
				<?php bp_group_type() ?> / <?php bp_group_member_count() ?>
				<br />
				<span class="activity"><?php printf( __( 'active %s ago', 'buddypress' ), bp_get_group_last_active() ) ?></span>
				</div>

				<div class="item-desc"><?php bp_group_description_excerpt() ?></div>

				<?php do_action( 'bp_directory_groups_item' ) ?>

			</div>

			<div class="action">
			
				<?php 				
				if (current_user_can ('manage_options') || groups_is_user_creator(bp_loggedin_user_id(),bp_get_group_id()) || groups_is_user_admin(bp_loggedin_user_id(),bp_get_group_id())) { ?>
				<a id="group-admin-button" href="<?php echo bp_get_group_permalink() . 'admin'; ?>">admin</a><br />
				<?php } ?>

				<?php
				bp_group_join_button();
				?>

			</div>

			<div class="clear"></div>
		</li>

	<?php endwhile; ?>
	</ul>

	<?php do_action( 'bp_after_directory_groups_list' ) ?>

	<div id="pag-bottom" class="pagination">

		<div class="pag-count" id="group-dir-count-bottom">
			<?php bp_groups_pagination_count() ?>
		</div>

		<div class="pagination-links" id="group-dir-pag-bottom">
			<?php bp_groups_pagination_links() ?>
		</div>

	</div>

<?php else: ?>

	<div id="message" class="info">
		<p><?php _e( 'There were no groups found.', 'buddypress' ) ?></p>
	</div>

<?php endif; ?>

<?php do_action( 'bp_after_groups_loop' ) ?>
