<?php
 
lt_include( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );


    
    /*
     * Plugin that offers features to return links within a
     *  given link category with extra html in between each link
     */
class PluginNavMenu extends PluginBase
{
        // TODO: grab the posts dynamically - maybe use a custom field to
        //       determine whether the post should be shown on the menu?
    var $menu = Array("Home" =>
                      Array("LINK" => "/",
                            ),
                      
                      "Company" =>
                      Array("LINK" => "/category/company",
                        "Management Team" => "/category/company/management",
                        "Investors" => "/category/company/investors",
                        "Directors" => "/category/company/directors",
                        "Advisory Board" => "/category/company/advisory",
                        "News" => "/category/press-releases",
                        "Careers" => "/category/company/careers",
                        ),
                  
                  "Products" =>
                  Array("LINK" => "/category/products",
                        "Key Benefits" => "/category/products/benefits",
                        "Featured Capabilities" => "/category/products/capabilities",
                        ),
                  
                  "Partners" =>
                  Array("LINK" => "/category/partners"),
                  
                  "Support" =>
                  Array("LINK" => "/category/support",
                        "Support Site Login" => "http://designadvance.com/frame.html",
                        "Software Downloads" => "https://system.netsuite.com/app/center/center.nl?c=453099&sc=7&category=140&ctype=KB",
                        ),
                  
                  );


    function PluginNavMenu($source = ""){
        $this->PluginBase($source);

	    $this->id = "navmenu";
        $this->version = "20070904";
        $this->author = "Jon Daley";
        $this->desc = "This plugin adds the ability to print out a semi-dynamic menu";
    }

    function printHtml(){
        $id=1;
        $count=0;

        $menu_height = $this->_getMenuHeight($this->menu);
        
        print "<table><tr><td width='30%'>\n";
        print "<table>";
        foreach($this->menu as $key => $value){
            if(is_array($value)){
                $count++;
                print "<tr><td>";
                print "<a onMouseover='showit(".
                    ((count($value) > 1) ? $id : -1).
                    ")' href='";
                print $this->_removeSpaces($value["LINK"]);
                print "'>$key</a>\n";
                if(count($value) > 1)
                    $this->printJavascript($value, $id, $menu_height);
                print "</td></tr>\n";
            }
            $id++;
        }
        for($i=$count; $i < $menu_height; $i++)
            print "<tr><td>&nbsp;</td></tr>";
        print "</table></td><td width='70%' id='describe' onMouseover='clear_delayhide()' onMouseout='resetit(event)'>".
            "</td></tr></table>";
    }

    function printJavascript($arr, $id, $menu_height){
        print "<script type='text/javascript'>\n";
        print "submenu[".$id."] = '".
            "<table>";
        $count = 0;
        foreach($arr as $str => $link){
            if($str != "LINK"){
                $count++;
                print "<tr><td><a href=\"$link\">";
                print $this->_removeSpaces($str);
                print "</a></td></tr>";
            }
        }
        for($i=$count; $i < $menu_height; $i++)
            print "<tr><td>&nbsp;</td></tr>";
        print "</table>';</script>\n";
    }

    function _removeSpaces($str){
        $str = str_replace(" ", "&nbsp;", $str);
        return $str;
    }

    function _getMenuHeight($menu){
        $height = count($menu) - 1;
        foreach($this->menu as $key => $value){
            if(is_array($value)){
                $item_height = count($value);
                if($item_height > $height)
                    $height = $item_height - 1;
            }
        }
        return $height;
    }
}
?>