<?php
function mosGetTabMenu($menutype) {
	global $database, $my, $cur_template, $Itemid;
	global $mosConfig_absolute_path, $mosConfig_live_site, $mosConfig_shownoauth;
    $module = "suckerfish";
	$class_sfx = "";
	$intUserType = 0;
	if($my->gid){
		switch ($my->usertype)
		{
			case 'Super Administrator':
			$intUserType = 0;
			break;
			case 'Administrator':
			$intUserType = 1;
			break;
			case 'Editor':
			$intUserType = 2;
			break;
			case 'Registered':
			$intUserType = 3;
			break;
			case 'Author':
			$intUserType = 4;
			break;
			case 'Publisher':
			$intUserType = 5;
			break;
			case 'Manager':
			$intUserType = 6;
			break;
		}
	}
	else
	{
		$intUserType = 0;
	}
		if ($mosConfig_shownoauth) {
			$sql = "SELECT m.* FROM #__menu AS m"
			. "\nWHERE menutype='". $menutype ."' AND published='1' AND parent='0'"
			. "\nORDER BY ordering";
		} else {
			$sql = "SELECT m.* FROM #__menu AS m"
			. "\nWHERE menutype='". $menutype ."' AND published='1' AND access <= '$my->gid' AND parent='0'"
			. "\nORDER BY ordering";
		}
		$database->setQuery($sql);

	$rows = $database->loadObjectList( 'id' );
	echo $database->getErrorMsg();

  include_once( "$mosConfig_absolute_path/templates/" . $cur_template . "/js/iehover.js" );
	echo "<div id=\"nav\">";
	$indents = array(
	array( "<ul>", "<li>" , "</li>", "</ul>" ),
	);
	$submenids = array();
    foreach ($rows as $v ) {
		$pt = $v->parent;
		$list = @$submenids[$pt] ? $submenids[$pt] : array();
		array_push( $list, $v );

        $submenids[$pt] = $list;
    }
	$open = array( $Itemid );
		$count = 20;
	$id = $Itemid;
	while (--$count) {
		if (isset($rows[$id]) && $rows[$id]->parent > 0) {
			$id = $rows[$id]->parent;
			$open[] = $id;
		} else {
			break;
		}
	}

    mosRecurseListMenu( 0, 0, $submenids, $open, $indents, $class_sfx );

	echo "</div>";
}
function mosRecurseListMenu( $id, $level, &$submenids, $open, &$indents, $class_sfx ) {
	global $Itemid;
	global $HTTP_SERVER_VARS, $mosConfig_live_site;

	if (@$submenids[$id]) {
		$n = min( $level, count( $indents )-1 );

        echo $indents[$n][0];

		foreach ($submenids[$id] as $row) {
		
		        switch ($row->type) {
          		case 'separator';
          		break;
          		case 'url':
          		if ( eregi( 'index.php\?', $row->link ) ) {
        				if ( !eregi( 'Itemid=', $row->link ) ) {
        					$row->link .= '&Itemid='. $row->id;
        				}
        			}
          		break;
          
          		default:
          			$row->link .= "&Itemid=$row->id";
          
          		break;
          	}
            $li =  "\n".$indents[$n][1] ;
            $current_itemid = trim( mosGetParam( $_REQUEST, 'Itemid', 0 ) );
            if ($Itemid == $row->id || 
                (sefRelToAbs( substr($_SERVER['PHP_SELF'],0,-9) . $row->link)) == $_SERVER['REQUEST_URI'] ||
                (sefRelToAbs( substr($_SERVER['PHP_SELF'],0,-9) . $row->link)) == $HTTP_SERVER_VARS['REQUEST_URI']) {
							$li = "<li class='active'>";
						}
	          echo $li;
             echo mosGetLink( $row, $level, $class_sfx );
			mosRecurseListMenu( $row->id, $level+1, $submenids, $open, $indents, $class_sfx );
            echo $indents[$n][2];
        }
		echo "\n".$indents[$n][3];
	}
}
function mosGetLink( $mitem, $level=0, $class_sfx='' ) {
	global $Itemid, $mosConfig_live_site;
	$txt = '';
	$mitem->link = str_replace( '&', '&amp;', $mitem->link );
	if (strcasecmp(substr($mitem->link,0,4),"http")) {
		$mitem->link = sefRelToAbs($mitem->link);
	}
    switch ($mitem->browserNav) {
		case 1:
        if ($mitem->cnt > 0) {
		   $txt = "<a class=\"daddy\" target=\"_window\"  href=\"$mitem->link\">$mitem->name</a>";
		} else {
		   	$txt = "<a href=\"$mitem->link\" target=\"_window\" >$mitem->name</a>\n";
		}
		break;

		case 2:
        if ($mitem->cnt > 0) {
		   $txt = "<a href=\"#\" class=\"daddy\" onClick=\"javascript: window.open('$mitem->link', '', 'toolbar=					no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=550'				);\" class=\"$menuclass\">$mitem->name</a>\n";
		} else {
		    $txt = "<a href=\"#\" onClick=\"javascript: window.open('$mitem->link', '', 'toolbar=					no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=550'				);\" class=\"$menuclass\">$mitem->name</a>\n";
		}

		break;

		case 3:
         if ($mitem->cnt > 0) {
		   $txt = "<a class=\"daddy\" >$mitem->name</a>\n";
		} else {
		   	$txt = "<a>$mitem->name</a>\n";
		}

		break;

		default:
		if ($mitem->cnt > 0) {
		    if ($level == 0) {
                $txt = "<a class=\"topdaddy\" href=\"$mitem->link\">$mitem->name</a>";
		   } else {
                $txt = "<a class=\"daddy\" href=\"$mitem->link\">$mitem->name</a>";
		   }
		} else {
		   $txt = "<a href=\"$mitem->link\">$mitem->name</a>";
		}
        break;
	}
    return $txt;
}
?>