<?php
/*
Template Name: Onepage
*/
?>

<?php get_header(); ?>

<?php
    global $theme_options;

	$locations = get_nav_menu_locations();
    $args = array(
        'order'                  => 'ASC',
        'orderby'                => 'menu_order',
        'post_type'              => 'nav_menu_item',
        'post_status'            => 'publish',
        'output'                 => ARRAY_A,
        'output_key'             => 'menu_order',
        'nopaging'               => true,
        'update_post_term_cache' => false );

    if(is_array($locations) && isset($locations["primary"])) {
        $items = wp_get_nav_menu_items( $locations["primary"], $args );
    } else {
        $items = Array();
    }

    if ($items) {
        ob_start();
        $i = 0;
        foreach ($items as $item) {

            // Don't show custom links as pages
            //if($item->object <> 'custom')

            $post = get_post($item->object_id);
            if ($i !== 0) {
                
                $page_openinnewwindow = get_post_meta( $post->ID, '_page_openinnewwindow_value', true );

                if (($item->object !== 'custom' && $item->object !== 'post' && $item->object !== 'category')&&(!$page_openinnewwindow)) {
                    $sub_title = get_post_meta( $post->ID, '_page_subtitle_value', true );
                    $page_class = get_post_meta( $post->ID, '_page_class_value', true );
                    $page_image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full');
                ?>
                <div id="<?php echo $post->post_name; ?>" class="parallax content-block <?php echo $page_class; ?>" <?php if(is_array($page_image) && isset($page_image[0])) { echo 'style="background-image: url('.$page_image[0].')"'; } ?>>
                    <div class="container">
                        <div class="row">
                            <div class="span12">
                                <h1 class="page-header-title left"><?php echo $post->post_title; ?></h1>
                                <?php
                                if(is_array($sub_title) && isset($sub_title[0]) && $sub_title[0]!="") {?>
                                <h6 class="page-subheader-title right"><?php echo $sub_title; ?></h6>
                                <?php } ?>
                            </div>
                        </div>
                        <div class="row">
                            <div class="span12">
                                <?php echo str_replace(']]>', ']]&gt;', apply_filters('the_content', $post->post_content)); ?>
                            </div>
                        </div>
                        <?php 
                            
                        	$current_template = basename(get_page_template(),".php");
                        	if ( 'page-onepage' !== $current_template )
                        	{
                        		get_template_part( $current_template );
                        	}
		                ?>
                    </div>
                </div>
                
                <?php
                }
            } else {
                if ($item->classes[0] !== 'page') {
                ?>
                <?php
                if(isset($theme_options['disable_slider']) && !$theme_options['disable_slider']):
                ?>
                <header id="<?php echo $post->post_name; ?>" class="content-block home">
                    <div class="intro-block"> 
				    <!-- Flexslider -->
				    <div class="flexslider" id="main-slider">
				      <ul class="slides">
				      	<!-- slides loop -->
				      	<?php
						$temp = $wp_query;
						$wp_query = null;

						$post_counter = 0;
						$wp_query = new WP_Query(array(
						  'post_type' => 'slides',
                          'posts_per_page' => 10000,
						  'orderby'=> 'menu_order'
						));
						      
						while ($wp_query->have_posts()) : $wp_query->the_post();
						  $post_counter++;
						  $slide_image = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'full' );
						  $button_text = get_post_meta( $post->ID, '_slides_button_text_value', true );
						  $button_url = get_post_meta( $post->ID, '_slides_button_url_value', true );
						?>
						<li class="parallax">
				            <div class="slide-content">
				                <div class="slide-header"><?php the_content(); ?></div>
				                <?php if($button_text <> ''): ?>
				                <a href="<?php echo $button_url; ?>" class="slide-button"><?php echo $button_text; ?></a>
				            	<?php endif; ?>
				            </div>
				            <img class="slider-bg" alt="<?php the_title(); ?>" src="<?php echo $slide_image[0]; ?>" />
				        </li>
						<?php endwhile; // end of the loop. ?>
         
						<?php $wp_query = null; $wp_query = $temp;?>
				        
				      </ul>
				    </div>
				    <!-- / Flexslider --> 
				    <a href="#" class="skip-intro"></a> </div>
                </header>
                <?php else: ?>
                <header id="<?php echo $post->post_name; ?>" class="no-home"></header>

                <?php endif; ?>
                <?php
                }
            }
        $i++;
        }
    
        $page_template = ob_get_contents();
        ob_end_clean();
        echo $page_template;
    }
?>

<?php get_footer(); ?>