/**************************************************************************
 *                                                                        *
 *  JAVASCRIPT MENU HIGHLIGHTER v.1.5 (080929)                            *
 * --------------------------------------------                           *
 * ©2005 Media Division (www.MediaDivision.com)                           *
 *                                                                        *
 * Written by Marius Smarandoiu & Armand Niculescu                        *
 *                                                                        *
 * You are free to use, modify and distribute this file, but please keep  *
 * this header and credits                                                *
 *                                                                        *
 * Usage:                                                                 *
 * - the script will apply the .current class to the <a> and its parent   *
 *   <li> that is contained in the element with id="primarynav" and points*
 *   to the current URL                                                   *
 * - works in IE6, Firefox and Opera                                      *
 **************************************************************************/
function extractPageName(hrefString)
{

	var arr = hrefString.split('/');
	return  (arr.length<2) ? hrefString : arr[arr.length-2].toLowerCase() + arr[arr.length-1].toLowerCase();  
	             
}

function setActiveMenu(arr, crtPage) {
    if(crtPage.indexOf("?") > -1)
    {
    crtPage=crtPage.substring(0,crtPage.indexOf("?"));
    }
	for (var i=0; i<arr.length; i++)
	{
	   
		if(extractPageName(arr[i].href) == crtPage)
		{
		  
			if (arr[i].parentNode.tagName != "DIV") {
			    arr[i].className = "selected";
			    arr[i].parentNode.className = "selected";
			    arr[i].setAttribute("class", "selected");
			    arr[i].parentNode.setAttribute("class", "selected");
			}
		}
	}
}

function setPage()
{
    hrefString = document.location.href ? document.location.href : document.location;

    if (hrefString.indexOf("CustomHomes-Images") > -1) {

        hrefString = hrefString.replace("CustomHomes-Images", "Portfolio");
       
    }

    if (hrefString.indexOf("Singlefamilycommunities-Images") > -1) {
        hrefString = hrefString.replace("Singlefamilycommunities-Images", "Portfolio");

    }
    if (hrefString.indexOf("TownhomeDevelopments-Images") > -1) {
        hrefString = hrefString.replace("TownhomeDevelopments-Images", "Portfolio");

  
    }
    if (hrefString.indexOf("Customhomes") > -1 ) {
      
	    hrefString = hrefString.replace("Customhomes", "Portfolio");

	}
	
	if(hrefString.indexOf("Singlefamilycommunities") > -1 )
	{
	    hrefString = hrefString.replace("Singlefamilycommunities", "Portfolio");
	   
	}
	if (hrefString.indexOf("TownhomeDevelopments") > -1)
	{
	    hrefString = hrefString.replace("TownhomeDevelopments", "Portfolio");
	   
	}

	
	if (document.getElementById("bluemenu") != null)
		setActiveMenu(document.getElementById("bluemenu").getElementsByTagName("a"), extractPageName(hrefString));
		
}
