<?php namespace ProcessWire;

/**
 * Initialize variables output in _main.php
 *
 * Values populated to these may be changed as desired by each template file.
 * You can setup as many such variables as you'd like. 
 *
 * This file is automatically prepended to all template files as a result of:
 * $config->prependTemplateFile = '_init.php'; in /site/config.php. 
 *
 * If you want to disable this automatic inclusion for any given template, 
 * go in your admin to Setup > Templates > [some-template] and click on the 
 * "Files" tab. Check the box to "Disable automatic prepend file". 
 *
 */

// Variables for regions we will populate in _main.php. Here we also assign 
// default values for each of them.
$title = $page->get('headline|title'); // headline if available, otherwise title
$content = $page->body;
$sidebar = $page->sidebar;


// We refer to our homepage a few times in our site, so we preload a copy 
// here in a $homepage variable for convenience. 
$homepage = $pages->get('/'); 


// Include shared functions (if any)
include_once("./_func.php"); 


// What happens after this?
// ------------------------
// 1. ProcessWire loads your page's template file (i.e. basic-page.php).
// 2. ProcessWire loads the _main.php file
// 
// See the README.txt file for more information.
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title><?=$page->title;?></title>
  <!-- <base href="<?=$config->urls->templates;?>" /> -->
  <meta content="width=device-width, initial-scale=1.0" name="viewport">
  <meta content="" name="keywords">
  <meta content="" name="description">

  <!-- Favicons -->
  <link href="<?=$config->urls->templates;?>images/favicon/favicon.png" rel="icon">
  <link href="<?=$config->urls->templates;?>images/favicon/apple-touch-icon.png" rel="apple-touch-icon">

  <!-- Google Fonts -->
  <link href="https://fonts.googleapis.com/css?family=Ruda:400,900,700" rel="stylesheet">

  <!-- Bootstrap CSS File -->
  <link href="<?=$config->urls->templates;?>styles/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet">

  <!-- Libraries CSS Files -->
  <link href="<?=$config->urls->templates;?>styles/lib/font-awesome/css/font-awesome.min.css" rel="stylesheet">
  <link href="<?=$config->urls->templates;?>styles/lib/socicon/socicon.css" rel="stylesheet">
  <link href="<?=$config->urls->templates;?>styles/lib/prettyphoto/css/prettyphoto.css" rel="stylesheet">
  <link href="<?=$config->urls->templates;?>styles/lib/hover/hoverex-all.css" rel="stylesheet">
  <link href="<?=$config->urls->templates;?>styles/lib/jetmenu/jetmenu.css" rel="stylesheet">
  <link href="<?=$config->urls->templates;?>styles/lib/owl-carousel/owl-carousel.css" rel="stylesheet">

  <!-- Main Stylesheet File -->
  <link href="<?=$config->urls->templates;?>styles/main.css" rel="stylesheet">
  <link rel="stylesheet" href="<?=$config->urls->templates;?>styles/colors/<?=($g_settings->color_scheme ?: 'asphalt'); ?>.css">
</head>

<body>
  <div class="topbar clearfix">
    <div class="container">
      <div class="col-lg-12 text-right">
        <div class="social_buttons">
          <?php foreach($g_settings->social_media as $media) {
                  if (in_array($media, $g_settings->social_media))
                    echo '<a href='.($g_settings[$media.'_url'] ?: $page->url.'#').' data-toggle="tooltip" data-placement="bottom" title="'.
                          ucfirst($media).'"><i class="socicon socicon-'.strtolower($media).'"></i></a>';
                } ?>
        </div>
      </div>
    </div>
    <!-- end container -->
  </div>
  <!-- end topbar -->

  <header class="header">
    <div class="container">
      <div class="site-header clearfix">
        <div class="col-lg-3 col-md-3 col-sm-12 title-area">
          <div class="site-title" id="title">
            <a href="<?=$pages->get('/')->url; ?>" title="">
              <h4><?=($g_settings->title ?: 'RLD<span>CREATIVE</span>'); ?></h4>
            </a>
          </div>
        </div>
        <!-- title area -->
        <div class="col-lg-9 col-md-12 col-sm-12">
          <div id="nav" class="right">
            <div class="container clearfix">
              <?php 
                // only these 3 options apply to getMenuItems()
                $options = array('default_title'=> 1, 'default_class'=> 'cool_menu_class', 'current_class_level' => 4);

                // grab menu items as a WireArray with Menu objects
                $menuItems = $modules->get('MarkupMenuBuilder')->getMenuItems('menu_main', 2, $options);
  
                // build menu from array
                echo buildMenuFromObject(0, $menuItems);
              ?> 
            </div>
          </div>
          <!-- nav -->
        </div>
        <!-- title area -->
      </div>
      <!-- site header -->
    </div>
    <!-- end container -->
  </header>
  <!-- end header -->

  <?php if ($page === $pages->get(1)): ?>
  <section id="intro">
    <div class="container">
      <div class="ror">
        <div class="col-md-8 col-md-offset-2">
          <h1><?=$page->page_title; ?></h1>
          <p><?=$page->page_description; ?></p>
        </div>
      </div>
    </div>
  </section>

  <?php else: ?>
  <section class="post-wrapper-top">
    <div class="container">
      <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
        <?php
          // options for the breadcrumb
          $b_options = array ();
          $b_options['menu_css_class'] = 'breadcrumb';
          
          // breadcrumb fails if we forgot to add the page to the main menu
          //try {
          //  echo $modules->get('MarkupMenuBuilder')->renderBreadcrumbs('menu_main', $b_options);
          //} catch (\Exception $e) {
          //  echo 'Caught exception: ',  $e->getMessage(), "\n";
          //}
        ?>
        <h2><?=$page->page_title;?></h2>
      </div>
      <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
        <!-- search -->
        <div class="search-bar">
          <form action='<?php echo $pages->get('template=search')->url; ?>' method="post">
            <fieldset>
              <input type="image" src="<?=$config->urls->templates;?>images/pages/pixel.gif" class="searchsubmit" alt="" />
              <input type="text" onfocus="this.value=''" class="search_text showtextback" name="q" id="q" value="Search..." />
            </fieldset>
          </form>
        </div>
        <!-- / end div .search-bar -->
      </div>
    </div>
  </section>
  <!-- end post-wrapper-top -->
  <?php endif; ?>
