<?php

Function Param($name,$value,$equal,$brackets,$post)
{
	$str="";
	if($value!="")
	{
		$str=$name.$equal.$brackets.$value.$brackets.$post;
	}
	return($str);
}

Function CreateLayer($id,$relative,$top,$left,$width,$height,$css,$bgColor,$bgImage,$visible,$zIndex,$html,$events)
{
	$src = "";
	$src.="<div ";
	$src.=Param("id",$id,"=","\""," ");
	$src.=Param("class",$css,"=","\""," ");
	$style="";
	$style.=Param("position",$relative?"relative":"absolute",":","",";");
	$style.=Param("overflow","hidden",":","",";");
	$style.=Param("visibility",$visible==true?"visible":"hidden",":","",";");
	$style.=Param("display",$visible==true?"block":"none",":","",";");
	$style.=Param("top","0",":","",";");
	$style.=Param("left","0",":","",";");
	$style.=Param("width",$width,":","",";");
	$style.=Param("height",$height,":","",";");
	$style.=Param("z-index",$zIndex,":","",";");
	$style.=Param("background-color",$bgColor,":","",";");
	$style.=Param("background-image",$bgImage,":","",";");
	

	// Do we need clip?	
	//$style.=Param("clip","rect(0,".$width.",".$height.",0)",":","",";");

	// Add events

	$src.=Param("style",$style,"=","\"","");
	$src.=">";
	$src.=$html;
	$src.="</div>\n";

	return($src);
}
Function CreateItem($id,$text,$url,$target,$css,$subitems,$level)
{
	$img_item = "/uclit/img/d.gif";
	$img_dir_close = "/uclit/img/fc.gif";
	$image = "\"".($subitems==""?$img_item:$img_dir_close)."\"";	
	$imgtag = "<img border=0 id=\"".$id."_codethat_image\" src=".$image.">";
	$td="";
	for($i=0;$i<$level;$i++)
		$td.="<td>&nbsp;&nbsp;&nbsp;</td>";
	$atag = "href=\"".$url."\" ".($target==""?"":("target=\""._self."\""));
	if($subitems=="" )
	{
		$html="<table cellpadding=0 cellspacing=0 border=0><tr>".$td."<td></td><td align=left><a ".$atag." class=".$css."><p class=".$css.">".$text."</p></td></tr></table></a>";
	}
	else
	{
		$html="<table cellpadding=0 cellspacing=0 border=0><tr>".$td."<td><a href=\"javascript:toggleNode('".$id."');\">".$imgtag."</a></td><td align=left><a onClick=\"toggleNode('".$id."');\" class=".$css."><p class=".$css.">".$text."</p></a></td></tr></table></a>";
	}	
	// We create item as one main layer where it shows folders, all collapsed
	$src=CreateLayer( 
				$id,  // Id 
				true, // Relative
				"",   // Top 
				"",   // Left
				"",   // Width 
				"",   // Height
				"",   // Css class
				"",   // Background color
				"",   // URL of background image
				true, // Is it visible?
				1,    // Z index
				$html,// HTML text
				""    // Events
				);
	if($subitems!="") // open the folder when the mouse clicks on the folder
	{
		$src.=CreateLayer($id."_codethat_subitems",true,"","","","","","","",false,1,$subitems,"");
	}
	return($src);
}

Function Preface() 
{
	$img_dir_open = "/uclit/img/fe.gif"; // open folder
	$img_dir_close = "/uclit/img/fc.gif"; // close folder
	$img_item = "/uclit/img/d.gif";
        $str ="<script language='javascript'>";
	$str.="var ct_image_dir = new Image();ct_image_dir.src=\"".$img_dir_open."\";";
	$str.="var ct_image_diropen = new Image();ct_image_dir.src=\"".$img_dir_close."\";";
	$str.="var ct_image_item = new Image();ct_image_dir.src=\"".$img_item."\";";
	$str.="function setExpandedIco(id){var i=document.getElementById(id+'_codethat_image');i.src='".$img_dir_open."';}\n" ;
        $str.="function setCollapsedIco(id){var i=document.getElementById(id+'_codethat_image');i.src='".$img_dir_close."';}\n" ;
        $str.="function toggleNode(id){if(toggleLayer(id+'_codethat_subitems'))setExpandedIco(id);else setCollapsedIco(id);}" ;
        $str.="function toggleLayer(id){var l=document.getElementById(id);var s=l.style||l;if(s.visibility=='hidden'){s.visibility='visible';s.display='block';return true;}else{s.visibility='hidden';s.display='none';return false;}}";
	$str.="</script>";
	return ($str);
}
?> 