<?php
global $smof_data;
/*---------------------------------------
---------Customised Menu-----------------
-----------------------------------------*/
function next_custom_mobile_menu($title = NULL,$onep = 0)
{
	$locations = get_nav_menu_locations();
	
    if(isset( $locations['primary'] )) { $menu = wp_get_nav_menu_object( $locations['primary']); }else { $menu = '';}
	_wp_menu_item_classes_by_context( $menu_items );

$return = '<!-- Mobile Only Navigation - 2 types each for small device screens -->
<!-- Sliding Navigation : starts -->
<nav class="menu visible-xs" id="sm">
  <div class="sm-wrap">
    <h1 class="sm-logo">'.$title.'</h1>
    <i class="icon-remove menu-close"></i>';

if($menu != '')
	{
	$menu_items = wp_get_nav_menu_items($menu->term_id);		

	$menunu = array();
	foreach((array)$menu_items as $key => $menu_item )
	{
		$menunu[ (int) $menu_item->db_id ] = $menu_item;
	}
	unset($menu_items);

	foreach ($menunu as $i => $men ){
		if($men->menu_item_parent == '0')
		{
		      $post_finder = get_post($men->object_id);
		      $page_slug = $post_finder->post_name;
		      $newlink   = strtolower(preg_replace('/[^a-zA-Z]/s', '', $page_slug)); 
            //Other menu items
			    //Specific additions add custom icons
				if( ( 'page' == $men->object ))
				{
					$href =  '#'.$newlink;				
					$incl_onepage = get_post_meta($men->object_id,'next_include_onepage',true );

                  if($incl_onepage == 1)
                    {
						$href =  '#'.$newlink;
						$identifyClass = "is_onepage";
				    }
				    else
				    {
                       $href = $men->url;
                       $identifyClass = "not_onepage";
				    }	
				} 
				else 
				{
					$href =  $men->url;
					$identifyClass = "not_onepage";

				}
				$return .= '<a class="scroll-link mobmenu '.$identifyClass.'" href="'.$href.'" id="'.$newlink.'-linker" data-soffset="60">'.$men->title.'</a>';
			    $return .=  "\n";

		}
	}
}
	else
	{
 	  $return .= '<a id="defaultam-linker" title="Configure Menu" href="'.site_url().'/wp-admin/nav-menus.php">Configure Menu</a>';       
	}

	unset($menunu);	
	$return .= '</div>
  <!-- Navigation Trigger Button -->
  <div id="sm-trigger"></div>
</nav>
<!-- Sliding Navigation : ends -->' . "\n";

	echo $return;
}