  
function GetPageParentFolder()
{
  var url = window.location.pathname;
  if (url.substring(1).indexOf("/") > -1)
  {
    // subdirectory(s) exists
    url = url.substring(1);
    var subdir = url.substring(0, url.indexOf("/"))
    return subdir.toLowerCase();
  }
  else
  {
    // working from root /no subdirectory(s)  
    return "";
  }
}


function Get(elementId)
  {
    var objElement = document.getElementById(elementId);
    if (objElement == null)
      alert('Warning: Element (' + elementId + ') doesnt exist. Check spelling and context.'); ///for debugging, comment me out once you go live Myr.
    else
      return objElement;  
  }
  
  
  // declare arrays, 1 array for each menu item
  var arMenu1;
  var arMenu2;
  var arMenu3;
  var arMenu4;
  var arMenu5;
  var arMenu6;
  var arMenu7;
  var arMenu8;
  
  function Initialise()
  {
    // populate our relative-path arrays for each menu item
    /// NB: all urls lowercase!
    arMenu1 = new Array('/Home/Default.aspx'); /// comma seperate array relative url's.
    arMenu2 = new Array('/Profile/Profile.aspx');
    arMenu3 = new Array('/Community/Community.aspx');
    arMenu4 = new Array('/Business/');
    arMenu5 = new Array('/Travel/');
    arMenu6 = new Array('/Irish-Roots/');
    arMenu7 = new Array('/Ireland/');
    arMenu8 = new Array('/Irish-Shop/');
    
    // save a copy of the current page path name 
    var pagePath = window.location.pathname.toLowerCase();
    var pageFolder = GetPageParentFolder();
    //alert(pageFolder);

        
    // next we loop through all arrays
    // Menu 1
    for (var i=0; i<arMenu1.length; i++)
    {
      //alert('pagePath=' + pagePath + '&arrayitem=' + arMenu1[i]);
      if (pagePath == arMenu1[i].toLowerCase())
	{
         Get('menu1').className = 'selected';        
	 return;
	}
    }
    
    // next we loop through all arrays
    // Menu 2
    /// NB: note that variable i is already declared and cannot be declared by var again, hence we just set variable i back to 0.
    for (i=0; i<arMenu2.length; i++)
    {
      //alert('pagePath=' + pagePath + '&arrayitem=' + arMenu2[i]);
      if (pagePath == arMenu2[i].toLowerCase())
	{
        Get('menu2').className = 'selected';        
	return;
	}
    }   
    
// next we loop through all arrays
    // Menu 2
    /// NB: note that variable i is already declared and cannot be declared by var again, hence we just set variable i back to 0.
    for (i=0; i<arMenu3.length; i++)
    {
      //alert('pagePath=' + pagePath + '&arrayitem=' + arMenu2[i]);
      if (pagePath == arMenu3[i].toLowerCase())
	{
        Get('menu3').className = 'selected';        
	return;
	}
    }    

// next we loop through all arrays
    // Menu 4
    /// NB: note that variable i is already declared and cannot be declared by var again, hence we just set variable i back to 0.
    for (i=0; i<arMenu4.length; i++)
    {
      //alert('pagePath=' + pagePath + '&arrayitem=' + arMenu2[i]);
      if (pagePath == arMenu4[i].toLowerCase())
	{
        Get('menu4').className = 'selected';        
	return;
	}
    }    

// next we loop through all arrays
    // Menu 5
    /// NB: note that variable i is already declared and cannot be declared by var again, hence we just set variable i back to 0.
    for (i=0; i<arMenu5.length; i++)
    {
      //alert('pagePath=' + pagePath + '&arrayitem=' + arMenu2[i]);
      if (pagePath == arMenu5[i].toLowerCase())
	{
        Get('menu5').className = 'selected';        
	return;
	}
    }  
    // next we loop through all arrays
    // Menu 6
    /// NB: note that variable i is already declared and cannot be declared by var again, hence we just set variable i back to 0.
    for (i=0; i<arMenu6.length; i++)
    {
      //alert('pagePath=' + pagePath + '&arrayitem=' + arMenu2[i]);
      if (pagePath == arMenu6[i].toLowerCase())
	{
        Get('menu6').className = 'selected';        
	return;
	}
    }   
     // next we loop through all arrays
    // Menu 7
    /// NB: note that variable i is already declared and cannot be declared by var again, hence we just set variable i back to 0.
    for (i=0; i<arMenu7.length; i++)
    {
      //alert('pagePath=' + pagePath + '&arrayitem=' + arMenu2[i]);
      if (pagePath == arMenu7[i].toLowerCase())
	{
        Get('menu7').className = 'selected';        
	return;
	}
    }  
         // next we loop through all arrays
    // Menu 8
    /// NB: note that variable i is already declared and cannot be declared by var again, hence we just set variable i back to 0.
    for (i=0; i<arMenu8.length; i++)
    {
      //alert('pagePath=' + pagePath + '&arrayitem=' + arMenu2[i]);
      if (pagePath == arMenu8[i].toLowerCase())
	{
        Get('menu8').className = 'selected';        
	return;
	}
    }  
// next we check if we can match root level subdomains 
    // root 
    
    if (window.location.href.toLowerCase().indexOf('http://groups.irishabroad.com') > -1) // does path contain my value
    {
     Get('menu3').className = 'selected'; 
     return;
    }



    if (window.location.href.toLowerCase().indexOf('http://events.irishabroad.com') > -1) // does path contain my value
    {
     Get('menu3').className = 'selected'; 
     return;
    }
    if (window.location.href.toLowerCase().indexOf('http://www.irishstore.org/ia/') > -1) // does path contain my value
    {
     Get('menu7').className = 'selected'; 
     return;
    }
     if (window.location.href.toLowerCase().indexOf('http://personals.irishabroad.com/') > -1) // does path contain my value
    {
     Get('menu3').className = 'selected'; 
     return;
    }
         if (window.location.href.toLowerCase().indexOf('http://www.irishromance.com/') > -1) // does path contain my value
    {
     Get('menu3').className = 'selected'; 
     return;
    }
    if (window.location.href.toLowerCase().indexOf('http://reservations.bookhostels.com') > -1) // does path contain my value
    {
     Get('menu5').className = 'selected'; 
     return;
    }
    // subdirectory  
    else if (pageFolder == 'home') // Note: this will display IrishWorld aka menu4 as selected
    {
      Get('menu1').className = 'selected';  
      return;
    }
     else if (pageFolder == 'error') // Note: this will display IrishWorld aka menu4 as selected
    {
      Get('menu1').className = 'selected';  
      return;
    }
     else if (pageFolder == 'info') // Note: this will display IrishWorld aka menu4 as selected
    {
      Get('menu1').className = 'selected';  
      return;
    }
    // subdirectory  
    else if (pageFolder == 'circle') // Note: this will display IrishWorld aka menu4 as selected
    {
      Get('menu1').className = 'selected';  
      return;
    }
    // subdirectory XYZ -example of use
    else if (pageFolder == 'users') // Note: this will display IrishWorld aka menu4 as selected
    {
      Get('menu1').className = 'selected';  
      return;
    }
        // subdirectory XYZ -example of use
    else if (pageFolder == 'members') // Note: this will display IrishWorld aka menu4 as selected
    {
      Get('menu1').className = 'selected';  
      return;
    }
    // subdirectory XYZ -example of use

    else if (pageFolder == 'profile') // Note: this will display IrishWorld aka menu4 as selected
    {
      Get('menu2').className = 'selected';  
      return;
    }
    // subdirectory XYZ -example of use
    else if (pageFolder == 'discussions') 
    {
      Get('menu3').className = 'selected';  
      return;
    }
     // subdirectory XYZ -example of use
    else if (pageFolder == 'photoalbum') 
    {
      Get('menu3').className = 'selected';  
      return;
    }
      // subdirectory XYZ -example of use
    else if (pageFolder == 'blogs') 
    {
      Get('menu3').className = 'selected';  
      return;
    }
    else if (pageFolder == 'message') 
    {
      Get('menu2').className = 'selected';  
      return;
    }
     else if (pageFolder == 'business') 
    {
      Get('menu4').className = 'selected';  
      return;
    }
      else if (pageFolder == 'irish-world') 
    {
      Get('menu3').className = 'selected';  
      return;
    }
    else if (pageFolder == 'irishworld') 
    {
      Get('menu3').className = 'selected';  
      return;
    }
     else if (pageFolder == 'directory') 
    {
      Get('menu4').className = 'selected';  
      return;
    }
     else if (pageFolder == 'pubs') 
    {
      Get('menu3').className = 'selected';  
      return;
    }
 	else if (pageFolder == 'travel') 
    {
      Get('menu5').className = 'selected';  
      return;
    }
    else if (pageFolder == 'tours') 
    {
      Get('menu5').className = 'selected';  
      return;
    }
    else if (pageFolder == 'irish-roots') 
    {
      Get('menu6').className = 'selected';  
      return;
    }
     else if (pageFolder == 'genealogy') 
    {
      Get('menu6').className = 'selected';  
      return;
    }
     else if (pageFolder == 'yourroots') 
    {
      Get('menu6').className = 'selected';  
      return;
    }
      else if (pageFolder == 'ireland') 
    {
      Get('menu7').className = 'selected';  
      return;
    }
      else if (pageFolder == 'culture') 
    {
      Get('menu7').className = 'selected';  
      return;
    }
       else if (pageFolder == 'postcards') 
    {
      Get('menu7').className = 'selected';  
      return;
    }
      else if (pageFolder == 'irish-shop') 
    {
      Get('menu8').className = 'selected';  
      return;
    }
    else if (pageFolder == 'news') 
    {
      Get('menu7').className = 'selected';  
      return;
    }
    
    else if (pageFolder == '')
    {      
      return;
    }

  }
  
Initialise(); //starting point, typically put all javascript at end of page or end of menu.
  