<?php
/**
 * The sidebar containing the front page widget areas.
 * If there are no active widgets, the sidebar will be hidden completely.
 *
 * @package Wisnia
 * @since Wisnia 1.0
 */
?>
	<?php
	// Count how many front page sidebars are active so we can work out how many containers we need
	$wisnia_wisnia_footerSidebars = 0;
	for ( $x=1; $x<=4; $x++ ) {
		if ( is_active_sidebar( 'sidebar-homepage' . $x ) ) {
			$wisnia_wisnia_footerSidebars++;
		}
	}

	// If there's one or more one active sidebars, create a row and add them
	if ( $wisnia_wisnia_footerSidebars > 0 ) { ?>
		<div id="secondary" class="home-sidebar row">
			<?php
			// Work out the container class name based on the number of active front page sidebars
			$containerClass = "grid_" . 12 / $wisnia_wisnia_footerSidebars . "_of_12";

			// Display the active front page sidebars
			for ( $x=1; $x<=4; $x++ ) {
				if ( is_active_sidebar( 'sidebar-homepage'.  $x ) ) { ?>
					<div class="col <?php echo esc_attr( $containerClass ) ?>">
						<div class="widget-area" role="complementary">
							<?php dynamic_sidebar( 'sidebar-homepage'.  $x ); ?>
						</div> <!-- #widget-area -->
					</div> <!-- /.col.<?php echo esc_attr( $containerClass )?> -->
				<?php }
			} ?>
		</div> <!-- /#secondary.row -->

	<?php } ?>
