var errorString = "Sorry but this web page needs\nWindows95 and Internet Explorer 5 or above to view."
var name =  navigator.appName;
var version =  parseFloat(navigator.appVersion);
var platform = navigator.platform;

var ns = "false";

if ( !( (platform == "Win32") && 
        (name == "Microsoft Internet Explorer") && 
        (version >= 4) ) )
    {
    ns = "true";
    }
    
        CloseTimer = 0;

        
        //Settings which apply to all menus
        GeneralMenuSettings=["#000080",                 //Normal font Colour
                             "#E5E5E5",                 //Normal Background Colour
                             "#9E7130",                 //Hover Font Colour
                             "#F0F0F0",                 //Hover Background Colour
                             "Tahoma,Helvetica",        //font
                             12,                        //font size
                             "bold",                    //font weight
                             30];                        //Cell Height
        
        //Settings which only apply to sub menus
        SubMenuSettings= [1,                            //SubBorder
                         "left",                        //align
                         10,                            //padding right & left
                         180];                            //width
        
        //Settings which only apply to the main menu
        MainMenuSettings=[90,                            //top.         Only Applies to MainMenu
                            0,                            //left         Only Applies to MainMenu
                          125,                            //width.     Only Applies to MainMenu
                            0,                            //Mainborder Only Applies to MainMenu
                          "center",                        //Align
                          10                                //padding-left
                          ];
                      
        //The following arrays determine the text shown and the addresses they point too.
        MainMenu=[    //Text,                //Address
            "Home"              ,"/amd/docs/index.jsp",
            "About Us"          ,"/amd/docs/about_us.jsp",    
            "Our Services"      ,"submenu2", 
		    "AMD interactive"   ,"submenu1",    
            "Our People"   	    ,"/amd/docs/staff.jsp",  
            "Articles & News"  	,"/amd/docs/articles.jsp",
		    "Contact Us"        ,"/amd/docs/contact_us.jsp",
		    "Useful links"      ,"/amd/docs/links.jsp",
            "Site Map"          ,"/amd/docs/site_map.jsp"
                    ];
                    
        submenu1=[ //Text,                //Address
            "Online Conveyancing Quotes",        "/amd/docs/quote_main.jsp",
		    "Move Tracker", 		   			"/amd/docs/case_tracker.jsp"           
                      ];

        submenu2=[     //Text,                				//Address
           	"Business & Company Matters",					"/amd/docs/us_business.jsp",
			"Commercial Property", 							"/amd/docs/commercial_property.jsp",
			"Employment",            						"/amd/docs/employment.jsp",
			"Children, Divorce & Family Disputes",  					"/amd/docs/family.jsp",
			"Education",  									"/amd/docs/education.jsp",
			"Wills, Probate, Trusts & Powers of Attorney", 	"/amd/docs/wills.jsp",
			"Residential Property",  						"/amd/docs/property.jsp",
            "Dispute Resolution",        	 				"/amd/docs/dispute_resolution.jsp",                 	    		
            "Inheritance claims & Contested probate", 		"/amd/docs/inheritance_claims.jsp",       
            "Elderly",               						"/amd/docs/elderly.jsp"
			];

        MainFunc();
        
        //Write a div for the main position
        function MainFunc()
        {
        
            document.write("<div id='MainMenu' style='");
            document.write("position:absolute;top:");
            document.write(MainMenuSettings[0]);
            document.write(";left:");
            document.write(MainMenuSettings[1]);
            document.write(";width:"        + MainMenuSettings[2]);
            document.write("'>");
            
            //Populate the main menu
            PopulateMenuItems(MainMenu, MainMenuSettings, 'MainMenu');
            
            CheckSubMenus(MainMenu, 'MainMenu');
        }
        
        //Checks the menu for sub menus and generates them
        function CheckSubMenus(CheckMenu, CheckDivID)
        {
        for(CheckCounter=0;CheckCounter<CheckMenu.length;CheckCounter++)
            {
            IsMenu=CheckMenu[CheckCounter+1].substr(0,7);
            
            if (IsMenu == "submenu")
                {
                    //Need to show another menu
                    PositionSubMenu(CheckCounter, CheckMenu[CheckCounter+1], CheckDivID);
                }
            CheckCounter++;
            }
        }
        
        function PositionSubMenu(PosMenuCounter, PosMenu, PosParentMenu)
        {
            
            MenuArray = eval(PosMenu);
            //Construct A Div for the menu
            ParentMenuDiv = document.getElementById(PosParentMenu);
            document.write("<div id='" + PosMenuCounter + "' style='visibility:hidden;position:absolute;top:");
            
            //Calculate the position of the top
            DivPos = (PosMenuCounter/2);
            DivPos = DivPos * GeneralMenuSettings[7];
            DivPos = DivPos + parseInt(ParentMenuDiv.style.top);
            
            document.write(DivPos);
            
            DivPos = parseInt(ParentMenuDiv.style.left);
            DivPos = DivPos + parseInt(ParentMenuDiv.style.width) - SubMenuSettings[0];
            
            document.write(";left:");
            document.write(DivPos);
            document.write(";width:");
            document.write(SubMenuSettings[3]);
            document.write("'>");
            
            //Create the table to house the menu and populate the items
            PopulateMenuItems(MenuArray, SubMenuSettings, PosMenuCounter);
            
            //Check for submenus
            //CheckSubMenus(MenuArray, PosMenuCounter);
        }
            
            
        
        //Loops and populates the menu with all the items
        function PopulateMenuItems(PopMenu, PopSettingsArray, PopMenuCounter)
        {
            document.write("<table cellspacing='0' cellpadding='0' width='100%'  border='");
            if (PopSettingsArray == MainMenuSettings)
                document.write(MainMenuSettings[3]);
            else
                document.write(PopSettingsArray[0]);
            
            document.write("'>");
            
            for(PopCounter=0;PopCounter<PopMenu.length;PopCounter++)
            {
                document.write("<tr><td id='Menu" + PopMenuCounter + PopCounter);
                document.write("'style = '");
                
                //Write the style settings
                document.write("height:"            + GeneralMenuSettings[7]);
                document.write(";font-family:"        + GeneralMenuSettings[4]);
                document.write(";font-size:"        + GeneralMenuSettings[5]);
                document.write(";font-weight:"        + GeneralMenuSettings[6]);
                document.write(";background-color:" + GeneralMenuSettings[1]);
                document.write(";color:"            + GeneralMenuSettings[0]);
                document.write(";vertical-align:middle");
                
                if (PopSettingsArray == MainMenuSettings)
                {
                    //Dealing with the main menu
                    document.write(";text-align:"    + MainMenuSettings[4]);
                    document.write(";padding-left:" + MainMenuSettings[5]);
                }
                else
                {
                    //Dealing with sub menu
                    document.write(";text-align:"    + SubMenuSettings[1]);
                    document.write(";padding-right:" + SubMenuSettings[2]);
                    document.write(";padding-left:" + SubMenuSettings[2]);
                }
                    
                document.write("'");
                
                //Check for SubMenu
                IsMenu = PopMenu[PopCounter+1].substr(0,7);
                
                if (IsMenu == "submenu")
                {
                    //we need to open a submenu on hover here
                    document.write(" onmouseover='ShowSubMenu(" + PopCounter + ");HoverAppearance(Menu" + PopMenuCounter + PopCounter + ")'");
                    document.write(" onmouseout='HideSubMenu(" + PopCounter + ");UnHoverAppearance(Menu" +PopMenuCounter + PopCounter + ")'");
                    document.write(">" + PopMenu[PopCounter]);
                }
                else
                {
                    //An Actual Link
                    if (PopSettingsArray != MainMenuSettings)
                    {
                        document.write(" onmouseover='SubMenuActive(Menu" + PopMenuCounter + PopCounter + ");HoverAppearance(Menu" + PopMenuCounter + PopCounter + ")'");
                        document.write(" onmouseout='HideSubMenu(" + PopMenuCounter + ");UnHoverAppearance(Menu" + PopMenuCounter + PopCounter + ")'");
                    }
                    else
                    {
                        document.write(" onmouseover='HoverAppearance(Menu" + PopMenuCounter + PopCounter + ")'");
                        document.write(" onmouseout='UnHoverAppearance(Menu" + PopMenuCounter + PopCounter + ")'");
                    }
                    
                    document.write(" onclick='Navigate(\"" + PopMenu[PopCounter+1] + "\")'");
                    document.write(">" + PopMenu[PopCounter]);
                }
                
                document.write("</td></tr>");
                PopCounter++;
            }
            document.write("</table></div>");
        }    
        
        function Navigate(address)
        {
            window.location=address;
        }
        
        function HoverAppearance(thiscell)
        {
            thiscell.style.background = GeneralMenuSettings[3];
            thiscell.style.color = GeneralMenuSettings[2];
            thiscell.style.cursor = "hand";
        }
        
        function UnHoverAppearance(thiscell)
        {
            thiscell.style.background = GeneralMenuSettings[1];
            thiscell.style.color = GeneralMenuSettings[0];
            thiscell.style.cursor = "pointer";
        }
        
        function ShowSubMenu(MenuID)
        {
            //Hide all other current submenus
            clearTimeout(CloseTimer);
            
            for(i=0;i<MainMenu.length;i++)
            {
                IsMenu=MainMenu[i+1].substr(0,7);
                if (IsMenu == "submenu")
                    {
                        //Need to show another menu
                        MenuDiv = document.getElementById(i);
                        MenuDiv.style.visibility = 'hidden';
                    }
                i++;
            }
            
            MenuDiv = document.getElementById(MenuID);
            MenuDiv.style.visibility = 'visible';
        }
        
        function HideSubMenu(i)
        {
            MenuDiv = document.getElementById(i);
           
            // If this is netscape, COMPLETE HACK, you have 1.5 seconds to click it
            if( ns == "true" )
            {
                CloseTimer = setTimeout("MenuDiv.style.visibility = 'hidden';",1500);            
            }
            else
            {
                CloseTimer = setTimeout("MenuDiv.style.visibility = 'hidden';",30);
            }
        }        
        
        function SubMenuActive(MenuDiv)
        {
            clearTimeout(CloseTimer);
            Div = document.getElementById(MenuDiv);
            
        }
