/*************************************************************************************************************
**** File:          navigation.js
**** Owner:         Tison Kelley
**** Copyright:     2005 Web Design Please
**** Description:   This file creates a custom menu system for manidoDesign.com
**** Notes:         All submenus are created as the page loads.  Clicking a specific top level
****                menu will show/hide one of these submenus.  They are given
****                id's of 'navMenu_(Submenu Number)'. Submenu Numbers range from 1 - numMenus (defined below)
**************************************************************************************************************/

/*******************************************************************************************
**** Writing menu divs to page & Setting the top level handlers
********************************************************************************************/
var numMenus = 6; //Enter the number of top level menus here
var theTimeoutId;
var parentMenu;
for(i=1;i<=numMenus;i++)
{
    document.write('<div id="navMenu_'+ i +'" class="navMenu" style="display:none"></div>');
    parentMenu = document.getElementById('nav_'+i);
    if(parentMenu)
    {
        parentMenu.onmouseover = showMenu;
        parentMenu.onmouseout = prepHideMenu;
    }
}

/*******************************************************************************************
**** Building menus 
********************************************************************************************/
/** Interior Redesign Menu **/
var intMenu = new Array();
intMenu[intMenu.length] = new menu('Introduction','interior-design-syracuse.html','The Interior ReDesign Concept by Manido');
intMenu[intMenu.length] = new menu('One-Day Room Makeover & \'Before & After\' Party','one-day-makeover.html','One day makeover & \'Before and After\' Party');
intMenu[intMenu.length] = new menu('Mini-Extreme Makeover & \'Reveal\' Party','mini-extreme-makeover.html','Mini-Extreme Makeover & \'Reveal\' Party');
intMenu[intMenu.length] = new menu('Spring & Fall Makeover Giveaways','spring-fall-makeover-giveaways.html','Spring & Fall Makeover Giveaways');
intMenu[intMenu.length] = new menu('Design Consultation Services','design-consultation-services.html','Design Consultation Services');
intMenu[intMenu.length] = new menu('Home Staging for Homeowners & Realtors','home-staging.html','Home Staging for Homeowners & Realtors');
intMenu[intMenu.length] = new menu('\'Box-to-Beautiful\' & Move-In Services','box-to-beautiful-move-in-services.html','Box-To-Beautiful & Move-in Services');
intMenu[intMenu.length] = new menu('Seasonal, Special Event, Holiday Decorating','holiday-special-event-decorating.html','Seasonal, Holiday, Special Event Decorating');
intMenu[intMenu.length] = new menu('\'Clean Up Your Act\' Organizational Services','clean-up-your-act.html','\'Clean Up Your Act\' Organizational Services');
intMenu[intMenu.length] = new menu('D&eacute;cor\' Shopping Excursions','decor-shopping-excursions.html','Decor Shopping Excursions');
intMenu[intMenu.length] = new menu('Handyman Services','handyman.html',null);
intMenu[intMenu.length] = new menu('Gift Certificates','gift-certificates.html','Great Gift Certificates');
buildMenu(intMenu,1);

/** Paint & Faux Finish **/
var paintMenu = new Array();
paintMenu[paintMenu.length] = new menu('Introduction','decorative-paint-faux-finish.html','Decorative Paint &amp; Faux Finishes Introduction');
paintMenu[paintMenu.length] = new menu('Popular Finishes','popular-faux-finishes.html','Some Popular Finishes');
paintMenu[paintMenu.length] = new menu('Textured Finishes','textured-finishes.html','Textured Finishes');
paintMenu[paintMenu.length] = new menu('Distressing','distressing-finishes-techniques.html','Distressing');
paintMenu[paintMenu.length] = new menu('Linen','linen-finishes-design.html','Linen');
paintMenu[paintMenu.length] = new menu('Patterning','patterning-finishes-techniques.html','Patterning');
paintMenu[paintMenu.length] = new menu('Stencil & Embossing','stencil-embossing-techniques.html','Stencil & Embossing');
paintMenu[paintMenu.length] = new menu('Basic Murals & Trompe l\'Oeil','basic-murals-trompe-loeil.html','Basic Murals & Trompe l\'Oeil');
paintMenu[paintMenu.length] = new menu('In-House Consultation','inhouse-consultation.html','In-House Consultation & Performance');
buildMenu(paintMenu,2);

/** Virtual Services **/
var virtualMenu = new Array();
virtualMenu[virtualMenu.length] = new menu('Introduction','interior-design-virtual-services.html','Virtual Services Introduction');
virtualMenu[virtualMenu.length] = new menu('Personalized Color Technology (PCT)','personalized-color-technology.html',null);
virtualMenu[virtualMenu.length] = new menu('Virtual Room Design (VRD)','virtual-room-design-vrd.html',null);
virtualMenu[virtualMenu.length] = new menu('560 Virtual Color Swatches','virtual-color-swatch-samples.html',null);
buildMenu(virtualMenu,3);

/** Etc. **/
var etcMenu = new Array();
etcMenu[etcMenu.length] = new menu('Introduction','manido-design-etc.html',null);
etcMenu[etcMenu.length] = new menu('Pencil Reproductions','black-white-pencil-reproductions.html','Black & White Pencil Reproductions');
etcMenu[etcMenu.length] = new menu('Handcrafted Chess Sets','handcrafted-chess-sets.html','Unique Handcrafted Chess Sets');
etcMenu[etcMenu.length] = new menu('Publishing Designs','publishing-designs.html','Publishing Designs');
buildMenu(etcMenu,4);

/** Commissions/Fees **/
var feeMenu = new Array();
feeMenu[feeMenu.length] = new menu('Introduction','fees.html',null);
feeMenu[feeMenu.length] = new menu('Payment Methods','payment-methods.html','Payment Methods');
feeMenu[feeMenu.length] = new menu('Consultation Fees','consultation-fees.html','Consultation Fees');
feeMenu[feeMenu.length] = new menu('Design/Performance Commissions','design-commissions.html','Design & Performance Commissions');
feeMenu[feeMenu.length] = new menu('Miscellaneous Design Fees','misc-fees.html',null);
feeMenu[feeMenu.length] = new menu('Decorative Paint Commissions','decorative-paint-commissions.html',null);
feeMenu[feeMenu.length] = new menu('Ordering, Commission, Fee Schedule','order.html','Order Services or View Commission, Fee, and Services Schedule');
buildMenu(feeMenu,5);

/** About **/
var aboutMenu = new Array();
aboutMenu[aboutMenu.length] = new menu('About Manido Design','about.html',null);
aboutMenu[aboutMenu.length] = new menu('Earn Free Services!','earn-free-interior-design.html','Earn Free Interior Design Services');
aboutMenu[aboutMenu.length] = new menu('Fundraising, Charity','fundraising-interior-design.html','Fundraising and Charity Around Syracuse');
aboutMenu[aboutMenu.length] = new menu('Supply Houses','supply-houses-interior-design.html','Supply Houses');
aboutMenu[aboutMenu.length] = new menu('Calendar','calendar.html','Calendar of Upcoming Events');
aboutMenu[aboutMenu.length] = new menu('Site Map','sitemap.html','ManidoDesign.com Site Map');
buildMenu(aboutMenu,6);

/** Constructor Function **/
function menu(label,page,alt)
{
    if(!alt)alt = label;
    this.label = label;
    this.page = page;
    this.alt = alt;
}
function buildMenu(menuArray,menuNum)
{
    menuDiv = document.getElementById('navMenu_'+menuNum);
    var code='';
    for(i=0;i<menuArray.length;i++)
    {
        code += '<a href="'+ menuArray[i].page +'" title="'+ menuArray[i].alt +'" onmouseover="stopHide();" onmouseout="prepHideMenu();">'+ menuArray[i].label +'</a>\n';
    }
    menuDiv.innerHTML = code;
}
function showMenu(e)
{
    target = getTarget(e);
    menuNum = target.id.substring(target.id.indexOf('_')+1);
    stopHide();
    hideMenu();
    var theMenu = document.getElementById('navMenu_'+menuNum);   
    /** If the last menu, declare the offsetRight, otherwise declare offsetLeft ***/ 
    if(menuNum == numMenus)
    {
        theMenu.style.right = getRightPosition();
    }
    else theMenu.style.left =  getLeftPosition(menuNum);    
    theMenu.style.display = '';
}
function prepHideMenu(menuNum)
{
    theTimeoutId = setTimeout('hideMenu()',900);
}
function hideMenu()
{
    for(var i=1;i<=numMenus;i++)
    {
        document.getElementById('navMenu_'+i).style.display = 'none';
    }
}
function stopHide()
{
    if(theTimeoutId)clearTimeout(theTimeoutId);
}
/** This function is necessary because the menu must be absolutely positioned, while the page is not!! **
*** (lesson learned there) **/
function getLeftPosition(menuNum)
{
    var bodyLeft = document.getElementById('main').offsetLeft;
    for(var i=1;i<menuNum;i++)
    {
        bodyLeft += document.getElementById('nav_'+i).offsetWidth;
    }
    return bodyLeft  + 'px';   
}
/** The last menu is simply flush with the right side of the content **/
function getRightPosition()
{
    var bodyContainer = document.getElementById('main');
    var bodyContWidth = bodyContainer.offsetLeft + bodyContainer.offsetWidth;
    var windowWidth = getWindowWidth();
    var right = windowWidth - bodyContWidth;
    return right + 'px';
}