<?php

/*

   Milonic DHTML Menu PHP Function Module  mm_phpmenu.php version 1.2 - August 3 2005
   This module is only compatible with the Milonic DHTML Menu version 5.62 or higher

   Copyright 2005 (c) Milonic Solutions Limited. All Rights Reserved.
   This is a commercial software product, please visit http://www.milonic.com/ for more information.

*/




$menuData="";

class mmenuStyle
{

	function createMenuStyle($styleName)
	{
		global $menuData;
		$styleArray=get_object_vars($this);
		$menuData.="with($styleName=new mm_style()){\n";

		foreach ($styleArray as $k => $v)
		{
			if(ereg("color",$k))
			{
				if(substr($v,0,1)!="#")$v="#".$v;
			}

			$menuData.= "$k=\"$v\";\n";
		}

		$menuData.= "}\n\n";
	}
}






class mMenu
{
	var $menuItems;
	function createMenu($menuName)
	{
		global $menuData;
		$menuArray=get_object_vars($this);

		$menuData.= "with(milonic=new menuname(\"$menuName\")){\n";
		$tempMenuItems="";
		foreach ($menuArray as $k => $v)
		{
			global $menuData;
			if($k!="menuItems")
			{
				if($k=="style")
				{
					$menuData.= "$k=$v;\n";
				}
				else
				{
					$menuData.= "$k=\"$v\";\n";
				}

			}
			else
			{
				if($k=="menuItems")$tempMenuItems=$v;
			}
		}

   		$menuData.= $tempMenuItems."\n";
		$menuData.= "}\n\n";
	}


	function addItemFromText($itemText)
	{
		global $menuData;
		$this->menuItems.="aI(\"".$itemText . "\");\n";
	}


	function addItemFromItem($menuItem)
	{
		global $menuData;
		$tempVar="";
		foreach ($menuItem as $k => $v)
		{
			if(ereg("color",$k))
			{
				if(substr($v,0,1)!="#")$v="#".$v;
			}

			$tempVar.="$k=$v;";
		}
		$this->menuItems.="aI(\"".$tempVar . "\");\n";
	}

}


class mItem
{
	function addItemElement($mtype,$mval)
	{
		$this->$mtype=$mval;
	}
}



function drawMenuCode()
{
	global $menuVars,$menuCodeDrawn;
	if($menuCodeDrawn==0)
	{
echo "
<SCRIPT language=\"JavaScript\" src=\"$menuVars[pathToCodeFiles]$menuVars[file_milonicsrc]\" type=\"text/javascript\"></SCRIPT>
<script	language=\"JavaScript\">

if(ns4)_d.write(\"<scr\"+\"ipt language=JavaScript src=$menuVars[pathToCodeFiles]$menuVars[file_mmenuns4]><\/scr\"+\"ipt>\");
  else _d.write(\"<scr\"+\"ipt language=JavaScript src=$menuVars[pathToCodeFiles]$menuVars[file_mmenudom]><\/scr\"+\"ipt>\");
</script>
";
}
	flush();
	$menuCodeDrawn++;
}


$drawCount=0;
$menuCodeDrawn=0;

function drawMenus()
{
	global $menuData, $menuVars, $drawCount, $menuCodeDrawn, $mmMenu;
	if($menuCodeDrawn==0)drawMenuCode();
	echo "<script>\n";
	if($drawCount==0)
	{
		echo "
_menuCloseDelay=$menuVars[menuCloseDelay];
_menuOpenDelay=$menuVars[menuOpenDelay];
_subOffsetTop=$menuVars[subOffsetTop];
_subOffsetLeft=$menuVars[subOffsetLeft]
		";
	}
	echo $menuData;
	echo "drawMenus();\n";
	echo "</script>\n";
	$drawCount++;
	$menuData="";
	$mmMenu=null;
	flush();
}


function commitMenus()
{
	drawMenuCode();
	drawMenus();
}