<?php
/**
 * Template Name: Job Page With Sidebar
 * The main template file for display page.
 *
 * @package WordPress
*/

get_template_part("lib/fallback.home.lib");

//Check if job cat content
$jobs_cat_query = '';
if(!empty($term))
{
	$jobs_cat_query.= $term;
	
	$obj_term = get_term_by('slug', $term, 'job_cats');
	$custom_title = $obj_term->name;
}
else
{
	$custom_title = get_the_title();
}

/**
*	Get Current page object
**/
$page = get_page($post->ID);

/**
*	Get current page id
**/
if(!isset($current_page_id) && isset($page->ID))
{
    $current_page_id = $page->ID;
}

//Get page Sidebar
$page_sidebar = get_post_meta($current_page_id, 'page_sidebar', true);
if(empty($page_sidebar))
{
	$page_sidebar = 'Page Sidebar';
}

//Hide header if homepage
if(!isset($hide_header) OR !$hide_header)
{
	get_header(); 
}

if(!isset($hide_header) OR !$hide_header)
{
?>
</div>

<?php
	if(has_post_thumbnail($current_page_id, 'full'))
    {
        $image_id = get_post_thumbnail_id($current_page_id); 
        $image_thumb = wp_get_attachment_image_src($image_id, 'full', true);
        $pp_page_bg = $image_thumb[0];
?>
<style>
.page_caption { background: #f9f9f9 url('<?php echo $pp_page_bg; ?>') center center no-repeat; background-size: cover; }
</style>
<?php
	}
?>

<?php
if(!is_front_page())
{
?>
<div class="page_caption">
	<div class="caption_inner">
		<div class="caption_header">
			<h1 <?php if(!empty($pp_page_bg)) { ?>class="withbg"<?php } ?>><span><?php echo $custom_title; ?></span></h1>
			<?php
			$page_description = get_post_meta($current_page_id, 'page_description', true);
			
			if(!empty($page_description))
			{
			?>
			    <div class="page_description<?php if(!empty($pp_page_bg)) { ?> withbg<?php } ?>"><?php echo $page_description; ?></div>
			<?php
			}
			?>
		</div>
	</div>
	
	<hr class="hr_page_caption"/>
</div>
<br class="clear"/>

<!-- Begin content -->
<div id="content_wrapper">

    <div class="inner">
    
    	<!-- Begin main content -->
    	<div class="inner_wrapper">
    	
    	<div class="standard_wrapper">
<?php
}

} //End is not front page
?>			

    	<div class="sidebar_content">
    	
    		<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>		
    		
    			<?php the_content(); break;  ?>
			
    		<?php endwhile; ?>
    		
    		<?php
	            //Display FAQs
	            $temp = $wp_query; 
	            $wp_query = null; 
	            $wp_query = new WP_Query(); 
	            
	            if(empty($term))
			    {
			    	$wp_query->query('showposts=-1&post_type=jobs&orderby=menu_order&order=ASC');
			    }
			    else
			    {
					$wp_query->query('showposts=-1&post_type=jobs&job_cats='.$term.'&orderby=menu_order&order=ASC');
				}

	            $i = 0;
	            
	            while ($wp_query->have_posts()) : $wp_query->the_post(); 
	            
	            	if($i>0)
	            	{
	            		echo do_shortcode('[accordion close="1" title="'.get_the_title().'"]'.get_the_content().'[/accordion]');
	            	}
	            	else
	            	{
		            	echo do_shortcode('[accordion close="0" title="'.get_the_title().'"]'.get_the_content().'[/accordion]');
	            	}
	            	$i++;
	            	
	            endwhile;
	            //End while loop
	        ?>
    	
    	</div>
    	
    	<div class="sidebar_wrapper">
    	
    	    <div class="sidebar_top"></div>
    	
    	    <div class="sidebar">
    	    
    	    	<div class="content">
    	    
    	    		<ul class="sidebar_widget">
    	    		<?php dynamic_sidebar($page_sidebar); ?>
    	    		</ul>
    	    	
    	    	</div>
    	
    	    </div>
    	
    	    <div class="sidebar_bottom <?php echo $sidebar_class; ?>"></div>
    	    <br class="clear"/>
    	    
    	</div>
    
    </div>
    <!-- End main content -->
    <br class="clear"/>
    
</div>
			
<?php 
//Hide footer if homepage
if(!isset($hide_header) OR !$hide_header OR is_null($hide_header))
{
?>			

</div>
<?php get_footer(); ?>

<?php
}
?>