
var listMenu = null;
var ctxListMenu = null;
var arrow = null;

function activePageHighlight(elm)
{
 if (typeof elm == 'string') elm = document.getElementById(elm);
 if (!elm) return;
 var links = elm.getElementsByTagName('a'), chosen = null;

 for (var i = 0; i < links.length; i++)
 {
  if (links.item(i).href.indexOf(location.pathname) > -1)
   if (!chosen || links[i].href.length > chosen.href.length) chosen = links[i];
 }
 
 if(chosen && chosen.tagName.toLowerCase() == "a")
 {    
    chosen.className = 'current-page';
 }  
 /*
 while (chosen && chosen.className != 'menulist')
 {
  if (chosen.nodeName.toLowerCase() == 'li')
  {
   chosen.getElementsByTagName('a').item(0).className = 'current-page';
  }
  chosen = chosen.parentNode;
 }
 */
};

var BreadcrumbOpen = function(ref,counter,show)
{
    
    if(show && (counter==0))
    {
        ref._fsm_styT = ref.style.top;
        ref._fsm_styMT = ref.style.marginTop;
        ref._fsm_offT = ref.offsetTop || 0
    }
    
    var cP=Math.pow(Math.sin(Math.PI*counter/2),0.75);
    var clipY=ref.offsetHeight*(1-cP);
    ref.style.clip = (counter==1 ? ((window.opera || navigator.userAgent.indexOf('KHTML')>-1)?'':'rect(auto,auto,auto,auto)'):'rect('+clipY+'px,'+ref.offsetWidth+'px,'+ref.offsetHeight+'px,0)');
    
    if(ref.offsetHeight > 200)
        ref.style.height = '200px';
    if(counter==1||(counter<0.01&&!show))
    {
       ref.style.top=ref._fsm_styT;
       ref.style.marginTop=ref._fsm_styMT
    }
    else
    {
        ref.style.top=((0-clipY)+(ref._fsm_offT))+'px';
        ref.style.marginTop='0'
    }
};

function InitMainMenu()
{
// For each menu you create, you must create a matching "FSMenu" JavaScript object to represent
// it and manage its behaviour. You don't have to edit this script at all if you don't want to;
// these comments are just here for completeness. Also, feel free to paste this script into the
// external .JS file to make including it in your pages easier!

// Here's a menu object to control the above list of menu data:
listMenu = new FSMenu('listMenu', true, 'display', 'block', 'none');
ctxListMenu = new FSMenu('ctxListMenu', true, 'display', 'block', 'none');

// The parameters of the FSMenu object are:
//  1) Its own name in quotes.
//  2) Whether this is a nested list menu or not (in this case, true means yes).
//  3) The CSS property name to change when menus are shown and hidden.
//  4) The visible value of that CSS property.
//  5) The hidden value of that CSS property.
//
// Next, here's some optional settings for delays and highlighting:
//  * showDelay is the time (in milliseconds) to display a new child menu.
//  * switchDelay is the time to switch from one child menu to another child menu.
//    Set this higher and point at 2 neighbouring items to see what it does.
//  * hideDelay is the time it takes for a menu to hide after mouseout.
//  * cssLitClass is the CSS classname applied to parent items of active menus.
//  * showOnClick will, suprisingly, set the menus to show on click. Pick one of 3 values:
//    0 = all mouseover, 1 = first level click, sublevels mouseover, 2 = all click.

//listMenu.showDelay = 0;
//listMenu.switchDelay = 125;
//listMenu.hideDelay = 500;
listMenu.cssLitClass = 'highlighted';
ctxListMenu.cssLitClass = 'highlighted';
//listMenu.showOnClick = 1;


// Now the fun part... animation! This script supports animation plugins you can add to each
// menu object you create. Here's two to get you started. To enable animation, add one or
// more functions to the menuObject.animations array, and set menuObject.animSpeed to the
// desired percentage of animation to be completed per frame.
// Animation functions are called with a reference to the menu element being animated,
// and a counter variable that changes from 0 to 100 depending on the animation progress.

// I'm applying them both to this menu and setting the speed to 20%. Delete this to disable.
//listMenu.animations[listMenu.animations.length] = FSMenu.animFade;
//listMenu.animations[listMenu.animations.length] = FSMenu.animClipDown;
ctxListMenu.animations[ctxListMenu.animations.length] = BreadcrumbOpen;
ctxListMenu.animSpeed = 20;


// Finally, on page load you have to activate the menu by calling its 'activateMenu()' method.
// I've provided an "addEvent" method that lets you easily run page events across browsers.
// You pass the activateMenu() function two parameters:
//  (1) The ID of the outermost <ul> list tag containing your menu data.
//  (2) A node containing your submenu popout arrow indicator.
// If none of that made sense, just cut and paste this next bit for each menu you create.

if (document.createElement && document.documentElement)
{
 arrow = document.createElement('img');
 arrow.src = '/img/rightarrow.gif';
 arrow.style.borderWidth = '0';
 arrow.style.marginTop = '3px';
 arrow.className = 'subind';
}

addEvent(window, 'load', new Function('listMenu.activateMenu("listMenuRoot", arrow)'));
addEvent(window, 'load', new Function('ctxListMenu.activateMenu("ctxListMenuRoot", arrow)'));


// You may wish to leave your menu as a visible list initially, then apply its style
// dynamically on activation for better accessibility. Screenreaders and older browsers will
// then see all your menu data, but there will be a 'flicker' of the raw list before the
// page has completely loaded. If you want to do this, remove the CLASS="..." attribute from
// the above outermost UL tag, and uncomment this line:
//addEvent(window, 'load', new Function('getRef("listMenuRoot").className="menulist"'));


// To create more menus, duplicate this section and make sure you rename your
// menu object to something different; also, activate another <ul> list with a
// different ID, of course :). You can have as many menus as you want on a page.

// hide menu when clicked in document
addEvent(document, 'click',  function() {
 listMenu.hideAll();
 ctxListMenu.hideAll();
});


// Activation: Include the ID for your menu in here.
addEvent(window, 'load', new Function('activePageHighlight("listMenuRoot")'));
addEvent(window, 'load', new Function('activePageHighlight("ctxListMenuRoot")'));

}
