/** Custom accordion menu code January 2007 Mike Karikas (mike@karikas.com) **/
/** Uses Yahoo!'s YUI Animation script **/
var navList = new Array();
navList.push( {open: false, navId: 'btnSearch', subId: 'subSearch', maxHeight: 95} );
navList.push( {open: false, navId: 'btnOpenHouse', subId: 'subOpenHouse', maxHeight: 0} );
navList.push( {open: false, navId: 'btnAgents', subId: 'subAgents', maxHeight: 80} );
navList.push( {open: false, navId: 'btnServices', subId: 'subServices', maxHeight: 100} );
navList.push( {open: false, navId: 'btnArea', subId: 'subArea', maxHeight: 37} );
navList.push( {open: false, navId: 'btnMarket', subId: 'subMarket', maxHeight: 100} );
navList.push( {open: false, navId: 'btnAbout', subId: 'subAbout', maxHeight: 140} );

var navTimer;
var navAnim;
var navAnimClose = new Array();

function openNav(what)
{
	for(i=0; i<navList.length; i++)
	{
		// Find the item that matches 'what' and expand it (if it's not already open)
		// Also 'close' any navs that are hanging open
		// Make sure it isn't supposed to be open (this would be true for those)
		if (navList[i].open == false)
		{
			if (navList[i].subId == what)
			{
				clearTimeout(navTimer);
				navTimer = setTimeout("openSubNav('"+i+"')", 500);
			} else {
				//navAnim.stop();
				checkHeight = document.getElementById(navList[i].subId).style.height;
				if (checkHeight != '0px' && checkHeight != '')
				{
					closeNav(navList[i].subId);
				}
			}
		}
	}
}

function openSubNav(num)
{
	// If this is our target, open it up
	document.getElementById(navList[num].subId).style.display = 'block';
	navAnim = new YAHOO.util.Anim(navList[num].subId, {height: {to: navList[num].maxHeight} }, 0.3, YAHOO.util.Easing.easeOut);
	navAnim.animate();
}

function closeNav(what)
{
	for(i=0; i<navList.length; i++)
	{
		// Find the item that matches 'what' and close it (unless it's supposed to be open already)
		if (navList[i].open == false)
		{
			if (navList[i].subId == what)
			{				
				navAnimClose[i] = new YAHOO.util.Anim(what, {height: {to: 0} }, 0.2, YAHOO.util.Easing.easeOut);
				navAnimClose[i].animate();
			}
		}
	}
}

// Set active nav item
function setNav(target, subtarget)
{
  rollover(target);
  currNav = target;

  // Set for accordion code
	for(i=0; i<navList.length; i++)
	{
		// Find the item that matches 'what' and set it
		if (navList[i].navId == target)
		{
			navList[i].open = true;
			document.getElementById(navList[i].subId).style.height = navList[i].maxHeight + 'px';
			document.getElementById(navList[i].subId).style.display = 'block';
		}
	}

	if (subtarget)
	{
		document.getElementById(subtarget).style.backgroundColor = '#f3eddb';
	}
}