
<?php
  $i=0;
  $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
  while ($categories = tep_db_fetch_array($categories_query))  {
    $tree1[$i][] = array('categories_name' => $categories['categories_name'],
                     'parent_id' => $categories['parent_id'],
                     'categories_id' => $categories['categories_id']);
    $tree2[$i][] = array('categories_name' => $categories['categories_name'],
                     'parent_id' => $categories['parent_id'],
                     'categories_id' => $categories['categories_id']);
    $tree3[$i][] = array('categories_name' => $categories['categories_name'],
                     'parent_id' => $categories['parent_id'],
                     'categories_id' => $categories['categories_id']);
	$i++;
	}
?>

						<?php
							global $SID;
							if (tep_not_null($SID)) 
								$s_id="&".$SID;
							else
								$s_id="";
							if(is_array($tree1)){foreach($tree1 as $key=>$value){
							if($value[0]['parent_id']==0){ 
						?>
						<div class="bigcategory"><a href="<?php echo tep_href_link(FILENAME_DEFAULT, 'cPath='.$value[0]['categories_id']);?>"><? echo $value[0]['categories_name'];?></a></div>
								<?php
									if(is_array($tree2)){foreach($tree2 as $key=>$value2){
										if($value2[0]['parent_id']==$value[0]['categories_id']){ 
									$j++;
								?>
								<div class="childcategory"><a href="<?php echo tep_href_link(FILENAME_DEFAULT, 'cPath='.$value[0]['categories_id'].'_'.$value2[0]['categories_id']);?>">&nbsp;<? echo $value2[0]['categories_name'];?></a></div>
										<?php
											if (is_array($cPath_array)) {
											if(is_array($tree3)){foreach($tree3 as $key=>$value3){
											$category_links = array_reverse($cPath_array);
											if ($category_links[2]!='')
												$cid=$category_links[1];
											else
											if ($category_links[1]!='')
												$cid=$category_links[0];
											else
												$cid=='';
											if($value3[0]['parent_id']==$cid && $value3[0]['parent_id']==$value2[0]['categories_id']){ 
										?>
											<div class="smallcategory"><a href="<?php echo tep_href_link(FILENAME_DEFAULT, 'cPath='.$value[0]['categories_id'].'_'.$value2[0]['categories_id'].'_'.$value3[0]['categories_id']);?>">&nbsp;&nbsp;<? echo $value3[0]['categories_name'];?></a></div>
										<? }}}}?>
								<? }}}?>
						<? }}}?>
