<?php
/**
 * Get the theme options
 */
global $tw_options;

/**
 * Get header layout
 */
$header_layout = isset( $tw_options['header_layout'] )  ? $tw_options['header_layout'] : 'regular-nav'; ?>

<!-- Navigation -->
<?php if ($header_layout == 'regular-nav') : ?>
	<div class="top-nav <?php echo esc_attr( $header_layout); ?>">
		<div class="container top-nav-inner">
				<!-- Logo -->
		  		<div id="logo">
					<?php echo is_front_page() ? '<h1>' : '<h2>'; ?>
						<a href="<?php echo home_url(); ?>">
							<?php if (isset($tw_options['logo']['url']) && $tw_options['logo']['url']) { 
								$width  = $tw_options['logo']['width'];
								$retinaClass = 'non-retina';

								if ( tw_issetor($tw_options['retina-logo']) ) {
									$width 	= $width/2;
									$retinaClass = 'retina';
								} ?>
								<span class="logosizer" class="<?php echo esc_attr( $retinaClass ); ?>" style="max-width: <?php echo (int) $width; ?>px">
				  					<img src="<?php echo esc_url( $tw_options['logo']['url'] ); ?>" alt="<?php bloginfo( 'name' ); ?>"/>
								</span>
							<?php } else { 
								bloginfo( 'name' );
							} ?>
						</a> 
					<?php echo is_front_page() ? '</h1>' : '</h2>'; ?> 
				</div>
				<!-- END Logo -->

				<div class="mobile-link">
					<a href="#mobilemenu"><i class="fa fa-bars"></i></a>
				</div>
	  
				<!-- Menu -->
				<div id="menu">
					<?php if ( has_nav_menu( 'main_nav_menu' ) ) { /* if menu location 'Main Navigation Menu' exists then use custom menu */ 
						wp_nav_menu( array(
							'menu'            => 'Main Navigation Menu', 
							'theme_location'  => 'main_nav_menu', 
							'menu_class'      => 'sf-menu', 
							'walker'          => new Themewich_Mega_Walker()
						)); 
					} else { /* else use wp_list_pages */ ?>
						<ul class="sf-menu">
							<?php wp_list_pages( array('title_li' => '','sort_column' => 'menu_order')); ?>
						</ul>
					<?php } ?>
					<div class="clear"></div>
				</div>
				<!-- END Menu -->

				<!--Searchbox-->
				<div class="searchnav">
					<?php get_search_form(true); ?>
				</div>
					
			<div class="clear"></div>
		</div>  
	</div><!-- End Top Nav -->

<?php else : ?>

	<div class="top-nav <?php echo esc_attr( $header_layout); ?>">
		<div class="container top-nav-inner">
					<!-- Logo -->
					<div id="logo">
						<?php echo is_front_page() ? '<h1>' : '<h2>'; ?>
							<a href="<?php echo home_url(); ?>">
								<?php if (isset($tw_options['logo']['url']) && $tw_options['logo']['url']) { 
									$width  = $tw_options['logo']['width'];
									$retinaClass = 'non-retina';

									if ( tw_issetor($tw_options['retina-logo']) ) {
										$width 	= $width/2;
										$retinaClass = 'retina';
									} ?>
									<span class="logosizer" class="<?php echo esc_attr( $retinaClass ); ?>" style="max-width: <?php echo (int) $width; ?>px">
					  					<img src="<?php echo esc_url( $tw_options['logo']['url'] ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>"/>
									</span>
								<?php } else { 
									bloginfo( 'name' );
								} ?>
							</a> 
						<?php echo is_front_page() ? '</h1>' : '</h2>'; ?> 
			  		</div>
			  		<!-- END Logo -->

					<div class="mobile-link table-cell">
						<a href="#mobilemenu"><i class="fa fa-bars"></i></a>
					</div>

					<div class="top-ad">
						<div class="alignright">
							<?php echo ( isset( $tw_options['header_ad'] ) ) ? do_shortcode( $tw_options['header_ad'] ) : '' ?>
						</div>
						<div class="clear"></div>
					</div>
		</div>
	  
		<div class="altcontainer">
			<div class="container">
				<!-- Menu -->
				<div id="menu">
					<?php if ( has_nav_menu( 'main_nav_menu' ) ) { /* if menu location 'Main Navigation Menu' exists then use custom menu */ 
						wp_nav_menu( array(
							'menu'            => 'Main Navigation Menu', 
							'theme_location'  => 'main_nav_menu', 
							'menu_class'      => 'sf-menu', 
							'walker'          => new Themewich_Mega_Walker()
						)); 
					} else { /* else use wp_list_pages */?>
						<ul class="sf-menu">
							<?php wp_list_pages( array('title_li' => '','sort_column' => 'menu_order')); ?>
						</ul>
					<?php } ?>
	
					<!--Searchbox-->
					<div class="searchnav">
						<?php get_search_form(true); ?>
					</div>
					<div class="clear"></div>
				</div>
			<!-- END Menu -->  
			</div>
			<div class="clear"></div>
		</div>
	</div><!-- End Top Nav -->

<?php endif; ?>

	<!-- Mobile Navigation -->
	<nav id="mobilemenu">
		<?php if ( has_nav_menu( 'main_nav_menu' ) ) { /* if menu location 'Top Navigation Menu' exists then use custom menu */ ?>
				<?php wp_nav_menu( array('menu' => 'Main Navigation Menu', 'theme_location' => 'main_nav_menu', 'items_wrap' => '<ul>%3$s</ul>')); ?>
		<?php } else { /* else use wp_list_pages */?>
			<ul>
				<?php wp_list_pages( array('title_li' => '','sort_column' => 'menu_order', )); ?>
			</ul>
		<?php } ?>
	</nav> 
  	<!-- END Mobile Navigation -->