<?php global $gp;

if ( $GLOBALS['gp_filter'] == 'enabled' && $gp['ajax'] == 'ajax-loop' ) { ?>

	<div class="filter-wrapper">
	
		<div class="filter-menu-wrapper">

			<?php if ( isset( $GLOBALS['gp_filter_cats'] ) && $GLOBALS['gp_filter_cats'] == '1' ) { 

				$taxonomies = get_taxonomies();
				$args = array(
					'parent' => (int) $GLOBALS['gp_filter_cats_id'],
				);
				$terms = get_terms( array( 'category', 'gp_hubs', 'gp_videos' ) );
				foreach ( $taxonomies as $taxonomy ) {
					$term = term_exists( (int) $GLOBALS['gp_filter_cats_id'], $taxonomy );
					if ( $term !== 0 && $term !== null ) {
						$terms = get_terms( $taxonomy, $args );
						break;
					}
				}
				if ( $terms ) { ?>
					<select name="filter-cats" class="filter-menu filter-cats">
						<option value="<?php echo esc_attr( $GLOBALS['gp_filter_cats_id'] ); ?>"><?php _e( 'All', 'gp_lang' ); ?></option>		
						<?php foreach( $terms as $term ) {
							if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { ?>
								<option value="<?php echo esc_attr( $term->term_id ); ?>"><?php echo esc_attr( $term->name ); ?></option>
							<?php } ?>
						<?php } ?>
					</select>
				<?php } ?>
			<?php } ?>
		
			<?php if ( ( isset( $GLOBALS['gp_filter_date'] ) && $GLOBALS['gp_filter_date'] == '1' )
			OR ( isset( $GLOBALS['gp_filter_title'] ) && $GLOBALS['gp_filter_title'] == '1' )
			OR ( isset( $GLOBALS['gp_filter_comment_count'] ) && $GLOBALS['gp_filter_comment_count'] == '1' )
			OR ( isset( $GLOBALS['gp_filter_views'] ) && $GLOBALS['gp_filter_views'] == '1' )
			OR ( isset( $GLOBALS['gp_filter_followers'] ) && $GLOBALS['gp_filter_followers'] == '1' )
			OR ( isset( $GLOBALS['gp_filter_site_rating'] ) && $GLOBALS['gp_filter_site_rating'] == '1' )
			OR ( isset( $GLOBALS['gp_filter_user_rating'] ) && $GLOBALS['gp_filter_user_rating'] == '1' )
			OR ( isset( $GLOBALS['gp_filter_hub_awards'] ) && $GLOBALS['gp_filter_hub_awards'] == '1' ) ) { ?>

				<select name="filter-orderby" class="filter-menu filter-orderby">
		
					<?php if ( isset( $GLOBALS['gp_filter_date'] ) && $GLOBALS['gp_filter_date'] == '1' ) { ?>
						<option value="newest"<?php if ( $GLOBALS['gp_orderby'] == 'newest' ) { ?> selected="selected"<?php } ?>><?php _e( 'Newest', 'gp_lang' ); ?></option>
						<option value="oldest"<?php if ( $GLOBALS['gp_orderby'] == 'oldest' ) { ?> selected="selected"<?php } ?>><?php _e( 'Oldest', 'gp_lang' ); ?></option>
					<?php } ?>
		
					<?php if ( isset( $GLOBALS['gp_filter_title'] ) && $GLOBALS['gp_filter_title'] == '1' ) { ?>
						<option value="title_az"<?php if ( $GLOBALS['gp_orderby'] == 'title_az' ) { ?> selected="selected"<?php } ?>><?php _e( 'Title (A-Z)', 'gp_lang' ); ?></option>
						<option value="title_za"<?php if ( $GLOBALS['gp_orderby'] == 'title_za' ) { ?> selected="selected"<?php } ?>><?php _e( 'Title (Z-A)', 'gp_lang' ); ?></option>
					<?php } ?>		
											
					<?php if ( isset( $GLOBALS['gp_filter_comment_count'] ) && $GLOBALS['gp_filter_comment_count'] == '1' ) { ?>
						<option value="comment_count"<?php if ( $GLOBALS['gp_orderby'] == 'comment_count' ) { ?> selected="selected"<?php } ?>><?php _e( 'Most Comments', 'gp_lang' ); ?></option>
					<?php } ?>		
						
					<?php if ( isset( $GLOBALS['gp_filter_views'] ) && $GLOBALS['gp_filter_views'] == '1' ) { ?>
						<option value="views"<?php if ( $GLOBALS['gp_orderby'] == 'views' ) { ?> selected="selected"<?php } ?>><?php _e( 'Most Views', 'gp_lang' ); ?></option>
					<?php } ?>

					<?php if ( isset( $GLOBALS['gp_filter_followers'] ) && $GLOBALS['gp_filter_followers'] == '1' ) { ?>
						<option value="followers"<?php if ( $GLOBALS['gp_orderby'] == 'followers' ) { ?> selected="selected"<?php } ?>><?php _e( 'Most Followers', 'gp_lang' ); ?></option>
					<?php } ?>	
			
					<?php if ( isset( $GLOBALS['gp_filter_site_rating'] ) && $GLOBALS['gp_filter_site_rating'] == '1' ) { ?>
						<option value="site_rating"<?php if ( $GLOBALS['gp_orderby'] == 'site_rating' ) { ?> selected="selected"<?php } ?>><?php _e( 'Top Site Rated', 'gp_lang' ); ?></option>
					<?php } ?>
		
					<?php if ( isset( $GLOBALS['gp_filter_user_rating'] ) && $GLOBALS['gp_filter_user_rating'] == '1' ) { ?>
						<option value="user_rating"<?php if ( $GLOBALS['gp_orderby'] == 'user_rating' ) { ?> selected="selected"<?php } ?>><?php _e( 'Top User Rated', 'gp_lang' ); ?></option>
					<?php } ?>
					
					<?php if ( isset( $GLOBALS['gp_filter_hub_awards'] ) && $GLOBALS['gp_filter_hub_awards'] == '1' ) { ?>
						<option value="hub_awards"<?php if ( $GLOBALS['gp_orderby'] == 'hub_awards' ) { ?> selected="selected"<?php } ?>><?php _e( 'Awards', 'gp_lang' ); ?></option>
					<?php } ?>
						
				</select>
	
			<?php } ?>

			<?php if ( isset( $GLOBALS['gp_filter_date_posted'] ) && $GLOBALS['gp_filter_date_posted'] == '1' ) { ?>		
		
				<select name="filter-date-posted" class="filter-menu filter-date-posted">
					<option value="all"<?php if ( $GLOBALS['gp_date_posted'] == 'all' ) { ?> selected="selected"<?php } ?>><?php _e( 'Posted any date', 'gp_lang' ); ?></option>
					<option value="year"<?php if ( $GLOBALS['gp_date_posted'] == 'year' ) { ?> selected="selected"<?php } ?>><?php _e( 'Posted in the last year', 'gp_lang' ); ?></option>
					<option value="month"<?php if ( $GLOBALS['gp_date_posted'] == 'month' ) { ?> selected="selected"<?php } ?>><?php _e( 'Posted in the last month', 'gp_lang' ); ?></option>
					<option value="week"<?php if ( $GLOBALS['gp_date_posted'] == 'week' ) { ?> selected="selected"<?php } ?>><?php _e( 'Posted in the last week', 'gp_lang' ); ?></option>
					<option value="day"<?php if ( $GLOBALS['gp_date_posted'] == 'day' ) { ?> selected="selected"<?php } ?>><?php _e( 'Posted in the last day', 'gp_lang' ); ?></option>	
				</select>
		
			<?php } ?>

			<?php if ( isset( $GLOBALS['gp_filter_date_modified'] ) && $GLOBALS['gp_filter_date_modified'] == '1' ) { ?>		
		
				<select name="filter-date-modified" class="filter-menu filter-date-modified">
					<option value="all"<?php if ( $GLOBALS['gp_date_modified'] == 'all' ) { ?> selected="selected"<?php } ?>><?php _e( 'Updated any date', 'gp_lang' ); ?></option>
					<option value="year"<?php if ( $GLOBALS['gp_date_modified'] == 'year' ) { ?> selected="selected"<?php } ?>><?php _e( 'Updated in the last year', 'gp_lang' ); ?></option>
					<option value="month"<?php if ( $GLOBALS['gp_date_modified'] == 'month' ) { ?> selected="selected"<?php } ?>><?php _e( 'Updated in the last month', 'gp_lang' ); ?></option>
					<option value="week"<?php if ( $GLOBALS['gp_date_modified'] == 'week' ) { ?> selected="selected"<?php } ?>><?php _e( 'Updated in the last week', 'gp_lang' ); ?></option>
					<option value="day"<?php if ( $GLOBALS['gp_date_modified'] == 'day' ) { ?> selected="selected"<?php } ?>><?php _e( 'Updated in the last day', 'gp_lang' ); ?></option>	
				</select>
		
			<?php } ?>			
									
		</div>
	
		<div class="element-title-line"></div>
	
	</div>

<?php } ?>