// Cascading Popup Menus v5.2 - Single Frame Menu example script.



var hBar = new ItemStyle(40, 1, '', 0, 0, '15#1763aa', '10#C7D5F1', 'highText', 'mText', '', '',
 null, null, 'hand', 'default')

var subM = new ItemStyle(20, 0, '&#187;', -15, 3, '#0e65b7', '#C7D5F1', 'subMText', 'mText',
 'itemBorder', 'itemBorder', null, 90, 'hand', 'default');

var subBlank = new ItemStyle(20, 1, '&#187;', -15, 3, '#CCCCDD', '#C7D5F1', 'lowText', 'highText',
 'itemBorderBlank', 'itemBorder', null, null, 'hand', 'default');

var button = new ItemStyle(20, 1, '&gt;', -15, 2, '10#FFFFFF', '10#CC6600', 'buttonText', 'buttonHover',
 'buttonBorder', 'buttonBorderOver', 80, 95, 'crosshair', 'default');



var pMenu = new PopupMenu('pMenu');
with (pMenu)
{
startMenu('root', true, 20, 112, 150, hBar, '', false);
addItem('&nbsp; Home', 'http://www.mrcmekong.org', '', null, 17);
addItem('&nbsp; About the MRC', 'http://www.mrcmekong.org/about_mrc.htm', '', null, 17);
addItem('&nbsp; About the Mekong', 'http://www.mrcmekong.org/about_mekong/about_mekong.htm', '', null, 17);
addItem('&nbsp; MRC Agreements <br /> &nbsp; and Procedures', 'http://www.mrcmekong.org/agreement_95/Agreement-procedures-guidelines.htm', '', null, 30);
addItem('&nbsp; The Mekong <br /> &nbsp; Programme', 'mProgramme', 'sm:', hBar, 30, 1, '&#187;', 141);
addItem('&nbsp; Sustainable <br /> &nbsp; Hydropower', 'mHydropower', 'sm:', hBar, 30, 1, '&#187;', 141);
addItem('&nbsp; Climate Change and <br /> &nbsp; Adaptation Initiative', 'http://www.mrcmekong.org/ccai/Climate-change-n-adaptation-initiative.htm', '', null, 30);
addItem('&nbsp; Annual Work <br /> &nbsp; Programme & Funding', 'http://www.mrcmekong.org/work-pro-funding.htm', '', null, 30);
addItem('&nbsp; MRC News', 'http://www.mrcmekong.org/MRC_news/press_releases.htm', '', null, 17);
addItem('&nbsp; Publications', 'mInformationProducts', 'sm:', hBar, 17, 1, '&#187;', 141);
addItem('&nbsp; Annual Report', 'http://www.mrcmekong.org/annual_report/2008/2008-tab-content.htm', '', null, 17);
addItem('&nbsp; Financial Reporting', 'http://www.mrcmekong.org/financial_reporting/', '', null, 17);
addItem('&nbsp; Annual Flood Report', 'http://www.mrcmekong.org/flood_report/2008/table_of_content08.htm', '', null, 17);
addItem('&nbsp; River Monitoring', 'mWater', 'sm:', hBar, 17, 1, '&#187;', 141);
//addItem('&nbsp; River Monitoring', 'http://ffw.mrcmekong.org', '', null, 17);
addItem('&nbsp; Development Partners', 'http://www.mrcmekong.org/funding-partners.htm', '', null, 17);
addItem('&nbsp; Mekong From Space', 'window.open("http://www.mrcmekong.org/MfS/index.html")', 'js:', null, 17);
addItem('&nbsp; River Awareness Kit', 'window.open("http://www.mrcmekong.org/RAK/index.html")', 'js:', null, 17);
addItem('&nbsp; Employment', 'http://www.mrcmekong.org/employment/vacancies.htm', '', null, 17);
addItem('&nbsp; Tenders', 'http://www.mrcmekong.org/tenders/tenders.htm', '', null, 17);
addItem('&nbsp; Internships', 'http://www.mrcmekong.org/internships/internship.htm', '', null, 17);
addItem('&nbsp; MekongInfo', 'window.open("http://www.mekonginfo.org")', 'js:', null, 17);



startMenu('mProgramme', true, 151, 0, 160, subM, '', false);
addItem('The Mekong <br /> Programme', 'http://www.mrcmekong.org/mekong_program.htm', '', subM, 33);
addItem('Basin Development <br />Plan', 'mBDP','sm:', subM, 35, 0, '&#187;', 147);
addItem('Water Utilisation ', 'mWUP', 'sm:', subM, 20, 0, '&#187;', 147);
addItem('Environment', 'mEnvironment', 'sm:', subM, 20, 0, '&#187;', 147);
addItem('Flood Management <br /> and Mitigation', 'mFMMP', 'sm:', subM, 35, 0, '&#187;', 147);
addItem('Fisheries', 'mFisheries', 'sm:', subM, 20, 0, '&#187;', 147);
addItem('Agriculture, Irrigation <br />& Forestry', 'mAIFP', 'sm:', subM, 35, 0, '&#187;', 147);
addItem('Navigation', 'mNavigation', 'sm:', subM, 20, 0, '&#187;', 147);
//addItem('Sustainable Hydropower', 'mHydropower', 'sm:', subM, 20, 0, '&#187;', 147);
addItem('Information and <br /> Knowledge Management', 'mIKMP', 'sm:', subM, 35, 0, '&#187;', 147);
//addItem('Information and <br /> Knowledge Management', 'mDSIMP', 'sm:', subM, 35, 0, '&#187;', 147); *** This for dropdown menu
addItem('Integrated Capacity Building', 'mICBP', 'sm:', subM, 35, 0, '&#187;', 147);
//addItem('Tourism','mTourism', 'sm:', subM, 20, 0, '&#187;', 147);



startMenu('mInformationProducts', true, 152, 0, 120, subM, '', false);
//addItem('MRC Archive', 'http://www.mrcmekong.org/publications/Cat_MRC_archive.asp?intCatalogID=9&strCatalog_NAME=MRC Archive', '', subM, 20);
addItem('For Sale', 'mForSale', 'sm:', subM, 20, 0, '&#187;', 108);
addItem('Free Downloads', 'http://www.mrcmekong.org/free_download/research.htm', '', subM, 20);

startMenu('mWater', true, 152, 0, 120, subM, '', false);
addItem('Water Level', 'http://ffw.mrcmekong.org', '', subM, 20);
addItem('Water Flow', 'http://www.mrcmekong.org/programmes/wup/WUP-monitoring.htm', '', subM, 20);



// Leftwards popout with a negative x and y relative to its trigger. The item has a custom height.
//Basin Development Plan Programme pop out.
startMenu('mBDP', true, 160, 0, 160, subM, '', false);
addItem('About the Programmme ', 'http://www.mrcmekong.org/programmes/bdp.htm', '', subM, 22);
addItem('Publications', 'http://www.mrcmekong.org/programmes/bdp/bdp-publication.htm', '', subM, 22);

//Water Utilisation Programme pop out.
startMenu('mWUP', true, 160, 0, 160, subM, '', false);
addItem('About the Programmme ', 'http://www.mrcmekong.org/programmes/wup.htm', '', subM, 22);
addItem('Decision Support Framework (DSF)', 'http://www.mrcmekong.org/programmes/wup/DSF/DSF_introduction.htm', '', subM, 32);
addItem('Publications', 'http://www.mrcmekong.org/programmes/wup/WUP-publication.htm', '', subM, 22);

//Environment pop out.
startMenu('mEnvironment', true, 160, 0, 160, subM, '', false);
addItem('About the Programmme ', 'http://www.mrcmekong.org/programmes/environment.htm', '', subM, 22);
addItem('Publications', 'http://www.mrcmekong.org/publications/pubByCategory.asp?intCatalogID=7&strCatalog_NAME=Environment', '', subM, 22);

//Flood Management and Mitigation Programme pop out.
startMenu('mFMMP', true, 160, 0, 160, subM, '', false);
addItem('About the Programmme ', 'http://www.mrcmekong.org/programmes/flood.htm', '', subM, 22);
addItem('Publications', 'http://www.mrcmekong.org/publications/pubByCategory.asp?intCatalogID=4&strCatalog_NAME=Flood+management+and+mitigation', '', subM, 22);

//Fisheries Programme pop out.
startMenu('mFisheries', true, 160, 0, 160, subM, '', false);
addItem('About the Programme ', 'http://www.mrcmekong.org/programmes/fisheries.htm', '', subM, 22);
addItem('Publications', '', '', subM, 22);
addItem('&nbsp;&nbsp; - Hard copies<br /> &nbsp;&nbsp;&nbsp;&nbsp;(order online)', 'http://www.mrcmekong.org/publications/pubByCategory.asp?intCatalogID=2&strCatalog_NAME=Fisheries', '', subM, 32);
addItem('&nbsp;&nbsp; - Download (free)', 'http://www.mrcmekong.org/free_download/research.htm', '', subM, 22);
//Agriculture, Irrigation and Forestry Programme pop out.
startMenu('mAIFP', true, 160, 0, 160, subM, '', false);
addItem('About the Programme ', 'http://www.mrcmekong.org/programmes/agriculture.htm', '', subM, 22);
addItem('Publications', 'http://www.mrcmekong.org/programmes/AIFP/publications.htm', '', subM, 22);

//Navigation Programme pop out.
startMenu('mNavigation', true, 160, 0, 160, subM, '', false);
addItem('About the Programme ', 'http://www.mrcmekong.org/programmes/navigation.htm', '', subM, 22);
addItem('Publications', 'http://www.mrcmekong.org/publications/pubByCategory.asp?intCatalogID=3&strCatalog_NAME=Navigation', '', subM, 22);

//Hydropower Programme pop out.
startMenu('mHydropower', true, 160, 0, 160, subM, '', false);
addItem('About the initiative ', 'http://www.mrcmekong.org/ish/ish.htm', '', subM, 22);
addItem('Publications', 'http://www.mrcmekong.org/programmes/hydropower/hydropower-pub.htm', '', subM, 22);

//Information Management Programme pop out.
startMenu('mIKMP', true, 160, 0, 160, subM, '', false);
addItem('About the Programme ', 'http://www.mrcmekong.org/programmes/info_management.htm', '', subM, 22);
addItem('Decision Support Framework (DSF)', 'http://www.mrcmekong.org/programmes/wup/DSF/DSF_introduction.htm', '', subM, 32);
addItem('Publications', 'http://www.mrcmekong.org/publications/pubByCategory.asp?intCatalogID=6&strCatalog_NAME=Hydrology', '', subM, 22);

// Integrated Capacity Building Programme pop out
startMenu('mICBP', true, 160, 0, 160, subM, '', false);
addItem('About the Programme ', 'http://www.mrcmekong.org/programmes/capacity_building.htm', '', subM, 22);
addItem('JRP Project', 'http://www.mrcmekong.org/programmes/capacity_building/jrp-project.htm', '', subM, 22);

// Tourism Programme pop out
//startMenu('mTourism', true, 160, 0, 160, subM, '', false);
//addItem('About the Programme ', 'http://www.mrcmekong.org/programmes/tourism.htm', '', subM, 22);
//addItem('Publications', 'http://www.mrcmekong.org/programmes/tourism/publication.htm', '', subM, 22);

startMenu('mForSale', true, 120, 0, 160, subM, '', false);
addItem('MRC Publications ', 'http://www.mrcmekong.org/publications/', '', subM, 22);
addItem('Spatial and Time-series Data', 'http://www.mrcmekong.org/spatial/spatialdata.htm', '', subM, 32);

}

addMenuBorder(pMenu, window.subBlank,
 null, '#666666', 1, '#CCCCDD', 2);




addDropShadow(pMenu, window.subM,
 [40,"#333333",6,6,-4,-4], [40,"#666666",4,4,0,0]);
addDropShadow(pMenu, window.subBlank,
 [40,"#333333",6,6,-4,-4], [40,"#666666",4,4,0,0]);




if ((navigator.userAgent.indexOf('rv:0.')==-1) &&
    !(isOp&&!document.documentElement) && !(isIE4&&!window.external))
{
 pMenu.showMenu = new Function('mN','menuAnim(this, mN, 10)');
 pMenu.hideMenu = new Function('mN','menuAnim(this, mN, -15)');

}







// This is the "positioning from page anchors" code used by the advanced positioning expressions.
page.elmPos=function(e,p)
{
 var x=0,y=0,w=p?p:this.win;
 e=e?(e.substr?(isNS4?w.document.anchors[e]:getRef(e,w)):e):p;
 if(isNS4){if(e&&(e!=p)){x=e.x;y=e.y};if(p){x+=p.pageX;y+=p.pageY}}
 else if (e && e.focus && e.href && this.MS && /Mac/.test(navigator.platform))
 {
  e.onfocus = new Function('with(event){self.tmpX=clientX-offsetX;' +
   'self.tmpY=clientY-offsetY}');
  e.focus();x=tmpX;y=tmpY;e.blur()
 }
 else while(e){x+=e.offsetLeft;y+=e.offsetTop;e=e.offsetParent}
 return{x:x,y:y};
};





function menuAnim(menuObj, menuName, dir)
{
 // The array index of the named menu (e.g. 'mFile') in the menu object (e.g. 'pMenu').
 var mD = menuObj.menu[menuName][0];
 // Add timer and counter variables to the menu data structure, we'll need them.
 if (!mD.timer) mD.timer = 0;
 if (!mD.counter) mD.counter = 0;

 with (mD)
 {
  // Stop any existing animation.
  clearTimeout(timer);


  // If the layer doesn't exist (cross-frame navigation) quit.
  if (!lyr || !lyr.ref) return;
  // This next line is not strictly necessary, but it stops the one-in-a-hundred menu that
  // shows and doesn't hide on very quick mouseovers.
  if (!visNow && dir>0) dir = 0-dir;
  // Show the menu if that's what we're doing.
  if (dir>0) lyr.vis('visible');
  // Also raise showing layers above hiding ones.
  lyr.sty.zIndex = dir>0 ? mD.zIndex + 1 : 1001;


 lyr.clip(0, 0, menuW+2, (menuH+2)*Math.pow(Math.sin(Math.PI*counter/200),0.75) );

  counter += dir;
  if (counter>100) { counter = 100; lyr.sty.zIndex = mD.zIndex }
  else if (counter<0) { counter = 0; lyr.vis('hidden') }
  else timer = setTimeout('menuAnim('+menuObj.myName+',"'+menuName+'",'+dir+')', 40);
 }
};





function addMenuBorder(mObj, iS, alpha, bordCol, bordW, backCol, backW)
{
 // Loop through the menu array of that object, finding matching ItemStyles.
 for (var mN in mObj.menu)
 {
  var mR=mObj.menu[mN], dS='<div style="position:absolute; background:';
  if (mR[0].itemSty != iS) continue;
  // Loop through the items in that menu, move them down and to the right a bit.
  for (var mI=1; mI<mR.length; mI++)
  {
   mR[mI].iX += bordW+backW;
   mR[mI].iY += bordW+backW;
  }
  // Extend the total dimensions of menu accordingly.
  mW = mR[0].menuW += 2*(bordW+backW);
  mH = mR[0].menuH += 2*(bordW+backW);

  // Set the menu's extra content string with divs/layers underneath the items.
  if (isNS4) mR[0].extraHTML += '<layer bgcolor="'+bordCol+'" left="0" top="0" width="'+mW+
   '" height="'+mH+'" z-index="980"><layer bgcolor="'+backCol+'" left="'+bordW+'" top="'+
   bordW+'" width="'+(mW-2*bordW)+'" height="'+(mH-2*bordW)+'" z-index="990"></layer></layer>';
  else mR[0].extraHTML += dS+bordCol+'; left:0px; top:0px; width:'+mW+'px; height:'+mH+
   'px; z-index:980; '+
   (alpha!=null?'filter:alpha(opacity='+alpha+'); -moz-opacity:'+alpha+'%; opacity:'+(alpha/100):'')+
   '">'+dS+backCol+'; left:'+bordW+'px; top:'+bordW+'px; width:'+(mW-2*bordW)+'px; height:'+
   (mH-2*bordW)+'px; z-index:990"></div></div>';
 }
};

function addDropShadow(mObj, iS)
{
 // Pretty similar to the one above, just loops through list of extra parameters making
 // dropshadow layers (from arrays) and extending the menu dimensions to suit.
 for (var mN in mObj.menu)
 {
  var a=arguments, mD=mObj.menu[mN][0], addW=addH=0;
  if (mD.itemSty != iS) continue;
  for (var shad=2; shad<a.length; shad++)
  {
   var s = a[shad];
   // Safari 1.2 bug: it inherits alpha values SIDEWAYS!?!? What were they thinking?
   var alpha = (s[0]!=null && navigator.userAgent.indexOf('AppleWebKit') == -1);
   if (isNS4) mD.extraHTML += '<layer bgcolor="'+s[1]+'" left="'+s[2]+'" top="'+s[3]+'" width="'+
    (mD.menuW+s[4])+'" height="'+(mD.menuH+s[5])+'" z-index="'+(arguments.length-shad)+'"></layer>';
   else mD.extraHTML += '<div style="position:absolute; background:'+s[1]+'; left:'+s[2]+
    'px; top:'+s[3]+'px; width:'+(mD.menuW+s[4])+'px; height:'+(mD.menuH+s[5])+'px; -z-index:'+
    (a.length-shad)+'; '+
    (alpha?'filter:alpha(opacity='+s[0]+'); -moz-opacity:'+s[0]+'%; opacity:'+(s[0]/100):'')+
    '"></div>';
   addW=Math.max(addW, s[2]+s[4]);
   addH=Math.max(addH, s[3]+s[5]);
  }
  mD.menuW+=addW; mD.menuH+=addH;
 }
};