<?php
/**
 * get Footer widgets based on Columns Counts from theme options
 */
$storeup_footer_widget_counts = get_option( 'storeup_footerwidgetcount' ) ? get_option( 'storeup_footerwidgetcount' ): 4;
if ( $storeup_footer_widget_counts ) {
	if ( 6 === intval( $storeup_footer_widget_counts ) ) { $storeup_fclass = 'one_sixth'; }
	if ( 5 === intval( $storeup_footer_widget_counts ) ) { $storeup_fclass = 'one_fifth'; }
	if ( 4 === intval( $storeup_footer_widget_counts ) ) { $storeup_fclass = 'one_fourth'; }
	if ( 3 === intval( $storeup_footer_widget_counts ) ) { $storeup_fclass = 'one_third'; }
	if ( 2 === intval( $storeup_footer_widget_counts ) ) { $storeup_fclass = 'one_half'; }
	if ( 1 === intval( $storeup_footer_widget_counts ) ) { $storeup_fclass = 'fullwidth'; }
}

$storeup_footer_columns = 0; // Footer count
if ( is_numeric( $storeup_footer_widget_counts ) ) {
	for ( $i = 1; $i <= $storeup_footer_widget_counts; $i++ ) {
		$storeup_footer_columns++;
		$storeup_last_class = ( ( intval( $storeup_footer_widget_counts ) === $storeup_footer_columns ) && ( 1 !== intval( $storeup_footer_widget_counts ) ) ) ? 'last' : '';
		if ( is_active_sidebar( 'footercolumn' . $i ) ) :
			echo '<div class="' . esc_attr( $storeup_fclass ) . ' ' . esc_attr( $storeup_last_class ) . '">';
			if ( ! function_exists( 'dynamic_sidebar' ) || ! dynamic_sidebar( 'footercolumn' . $i ) ) {
				echo '';
			}
				echo '</div>';
			endif;
	}
} else {
	switch ( $storeup_footer_widget_counts ) {
		case 'half_one_half': ?>
			<div class="one_half"><?php dynamic_sidebar( 'footercolumn1' ); ?></div>
			<div class="one_half last">
				<div class="one_half"><?php dynamic_sidebar( 'footercolumn2' ); ?></div>
				<div class="one_half last"><?php dynamic_sidebar( 'footercolumn3' ); ?></div>
			</div>
			<?php
			break;
		case 'half_one_third': ?>
			<div class="one_half"><?php dynamic_sidebar( 'footercolumn1' ); ?></div>
			<div class="one_half last">
				<div class="one_third"><?php dynamic_sidebar( 'footercolumn2' ); ?></div>
				<div class="one_third"><?php  dynamic_sidebar( 'footercolumn3' ); ?></div>
				<div class="one_third last"><?php dynamic_sidebar( 'footercolumn4' ); ?></div>
			</div>
			<?php break;
		case 'one_half_half': ?>
			<div class="one_half">
				<div class="one_half"><?php dynamic_sidebar( 'footercolumn1' ); ?></div>
				<div class="one_half last"> <?php dynamic_sidebar( 'footercolumn2' ); ?></div>
			</div>
			<div class="one_half last"><?php dynamic_sidebar( 'footercolumn3' ); ?></div>
			<?php break;
		case 'one_third_half': ?>
			<div class="one_half">
			<div class="one_third"><?php dynamic_sidebar( 'footercolumn1' ); ?></div>
				<div class="one_third"><?php dynamic_sidebar( 'footercolumn2' ); ?></div>
				<div class="one_third last"><?php dynamic_sidebar( 'footercolumn3' ); ?></div>
			</div>
			<div class="one_half last"><?php dynamic_sidebar( 'footercolumn4' ); ?></div>
			<?php break;
		case 'two_third_onethird': ?>
			<div class="two_third"><?php dynamic_sidebar( 'footercolumn1' ); ?></div>
			<div class="one_third last"><?php dynamic_sidebar( 'footercolumn2' ); ?></div>
			<?php break;

	}
}
