<?php
/*################################

This code is COPYRIGHTED by joomlathemes.org

Do not redistribute it to third part without permission
from joomlathemes.org

*/################################


  defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  global $database, $my, $Itemid, $mosConfig_shownoauth;
  $menu_tree = array();
  $highligh_code = array ( "current" , "subcurrent" );

  function getFather( $actual_id ) {
    global $menu_tree, $database;
    array_unshift ($menu_tree, $actual_id);
    $database->setQuery("SELECT parent from #__menu WHERE id='$actual_id'");
    $actual_father = $database->loadResult();
    if (!$actual_father == 0) getFather($actual_father);
  }

  function getLink( $menuitem, $level=0 ) {
    global $mosConfig_live_site, $menu_tree, $highligh_code;
    if ($menuitem->type != "url") {
      $vmenulink = sefRelToAbs($menuitem->link."&Itemid=$menuitem->id");
    } else {
      if ((eregi( "index.php\?", $menuitem->link )) AND (!eregi( "Itemid=", $menuitem->link ))) {
        $vmenulink = sefRelToAbs($menuitem->link."&Itemid=$menuitem->id");
      } else {
        $vmenulink = $menuitem->link;
      }
    }
    $menu_class = ($level == "0") ? "navlist" : "subnavlist";

    switch ($menuitem->browserNav) {
      case 1: // new window
        $mlink = ($menu_tree[$level] == $menuitem->id) ? "<a href=\"$vmenulink\" target=\"_window\" class=\"$menu_class\" id=\"$highligh_code[$level]\">$menuitem->name</a>" : "<a href=\"$vmenulink\" target=\"_window\" class=\"$menu_class\">$menuitem->name</a>";
        break;
      case 2: // popup window
        $mlink = "<a href=\"#\" onClick=\"javascript: window.open('$vmenulink', '', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=760,height=550');\" class=\"$menu_class\">$menuitem->name</a>";
        break;
      case 3: // separator
        $mlink = ($menu_tree[$level] == $menuitem->id) ? "<span class=\"$menu_class\" id=\"$highligh_code[$level]\">$menuitem->name</span>" : "<span class=\"$menu_class\">$menuitem->name</span>";
        break;
      default: // parent window
        $mlink = ($menu_tree[$level] == $menuitem->id) ? "<a href=\"$vmenulink\" class=\"$menu_class\" id=\"$highligh_code[$level]\">$menuitem->name</a>" : "<a href=\"$vmenulink\" class=\"$menu_class\">$menuitem->name</a>";
        break;
    }
    return $mlink;
  }

  getFather($Itemid);

  if ($mosConfig_shownoauth) {
    $sql = "SELECT * FROM #__menu WHERE menutype='mainmenu' AND published='1' AND parent='0' AND type!='separator' ORDER BY ordering";
  } else {
    $sql = "SELECT * FROM #__menu WHERE menutype='mainmenu' AND published='1' AND parent='0' AND type!='separator' AND access <= '$my->gid' ORDER BY ordering";
  }
  $database->setQuery($sql);
  if(!$result = $database->query()) {
    echo $database->stderr();
  }
  $rows = $database->loadObjectList();
  $ms_split_main  = "<ul id=\"navlist\">\n";
  foreach($rows as $row) {
    if ($menu_tree[0] == $row->id) {
      $link_status = "<li id=\"active\">";
    } else {
      $link_status = "<li>";
    }
    $ms_split_main .= $link_status.getLink( $row )."</li>\n";
  }
  $ms_split_main .= "</ul>";

  $ms_split_sub  = "<ul id=\"subnavlist\">\n";
  if ($menu_tree[0]!=0) {
    if ($mosConfig_shownoauth) {
      $sql = "SELECT * FROM #__menu WHERE menutype='mainmenu' AND published='1' AND parent='$menu_tree[0]' ORDER BY ordering";
    } else {
      $sql = "SELECT * FROM #__menu WHERE menutype='mainmenu' AND published='1' AND parent='$menu_tree[0]' AND access <= '$my->gid' ORDER BY ordering";
    }
    $database->setQuery($sql);
    if(!$result = $database->query()) {
      echo $database->stderr();
    }
    $subrows = $database->loadObjectList();
    foreach($subrows as $row) {
      if ($menu_tree[1] == $row->id) {
        $link_status = "<li id=\"active\">";
      } else {
        $link_status = "<li>";
      }
      $ms_split_sub .= $link_status.getLink( $row, 1 )."</li>\n";	
    }
  }
  $ms_split_sub .= "</ul>";

?>