var _use_images = true;
var _table_bgcolor = "#ffffff";

var _selected_image = "/images/_selected.gif";
var _blank_image = "/images/_blank.gif";
var _image_width = 10;

var _outer_table_width = 192;
var _outer_table_border = 0;
var _outer_table_cellspacing = 0;
var _outer_table_cellpadding = 0;

var _inner_table_border = 0;
var _inner_table_cellspacing = 0;
var _inner_table_cellpadding = 1;

var _temp_current_item = window.location.search.substring(1);
var _current_item;

if ( _temp_current_item == "" )
{
	_current_item = "";
}
else
{
	_current_item = _temp_current_item;
}

function is_sub_item(_p_s) 
{
	for ( var i = 0; i < _p_s.length; i++ ) 
	{
		if ( _p_s.charAt(i) == '.' )
		{
			return true;
    }
  }

  return false;
}

function get_open_start_point(_p_s)
{
	var _out = "";
	
	for ( var i = 0; i < _p_s.length; i++ ) 
	{
		if ( _p_s.charAt(i) == '.' )
		{
			break;
    }
    
    _out += _p_s.charAt(i);
  }
  
  return _out;
}

function is_open(_p_current_item, _p_code)
{
	var _code_is_sub = is_sub_item(_p_current_item);
	var _code_start = "";

	if ( _code_is_sub )
	{
		_code_start = get_open_start_point(_p_code);
	}

	var _current_item_is_sub = is_sub_item(_p_current_item);
	var _current_item_start = "";

	if ( _current_item_is_sub )
	{
		_current_item_start = get_open_start_point(_p_current_item);
	}
	
	if ( _current_item_start == "" || _code_start == "" )
	{
		return false;
	}
	
	if ( _current_item_start == _code_start )
	{
		return true;
	}
	
	return false;
}

var _is_sub = is_sub_item(_current_item);
var _open_start = "";

if ( _is_sub )
{
	_open_start = get_open_start_point(_current_item);
}

function menu_item(text, type, code, action, link, link_internal, normal_image, over_image, normal_color, over_color) 
{ 
   this.text = text;
   this.type = type;
   this.code = code;
   this.action = action;
   this.link = link;
   this.link_internal = link_internal;
   this.normal_image = normal_image;
   this.over_image = over_image;
   this.normal_color = normal_color;
   this.over_color = over_color;

} 

var _jsmenu_items = new Array() 

var _index = 0;


_jsmenu_items[_index++] = new menu_item("top level item 1", "top", "1.", "link", "/products-services/products-services.asp", true, "/images/products.gif", "/images/products-on.gif", "#cccccc", "#efefef");		
	_jsmenu_items[_index++] = new menu_item("Property Management", "sub", "1.1", "link", "/products-services/property-management.asp", true, "", "", "#ffffff", "#efefef");
	_jsmenu_items[_index++] = new menu_item("Facilities Management", "sub", "1.2", "link", "/products-services/facilities-management.asp", true, "", "", "#ffffff", "#efefef");
	_jsmenu_items[_index++] = new menu_item("Asset Management", "sub", "1.3", "link", "/products-services/asset-management.asp", true, "", "", "#ffffff", "#efefef");
	_jsmenu_items[_index++] = new menu_item("Services", "sub", "1.4", "link", "/products-services/services.asp", true, "", "", "#ffffff", "#efefef");

_jsmenu_items[_index++] = new menu_item("top level item 2", "top", "2.", "link", "/customers/customers-main.asp", true, "/images/customers.gif", "/images/customers-on.gif", "#cccccc", "#efefef");
	_jsmenu_items[_index++] = new menu_item("Markets", "sub", "2.1", "link", "/customers/markets.asp", true, "", "", "#ffffff", "#efefef");
	_jsmenu_items[_index++] = new menu_item("Case Studies", "sub", "2.21", "link", "/customers/case-studies.asp", true, "", "", "#ffffff", "#efefef");


_jsmenu_items[_index++] = new menu_item("", "top", "3.", "link", "/about-raindrop/about-raindrop.asp", true, "/images/about.gif", "/images/about-on.gif", "#cccccc", "#efefef");

_jsmenu_items[_index++] = new menu_item("top level item 4", "top", "4.", "link", "/newsevents/events.asp", true, "/images/news.gif", "/images/news-on.gif", "#cccccc", "#efefef");
_jsmenu_items[_index++] = new menu_item("Manhattan Presentations", "sub", "4.1", "link", "/newsevents/presentations.asp", true, "", "", "#ffffff", "#efefef");
_jsmenu_items[_index++] = new menu_item("Press Room/White Paper", "sub", "4.2", "link", "/newsevents/press-releases.asp", true, "", "", "#ffffff", "#efefef");


_jsmenu_items[_index++] = new menu_item("", "top", "5.", "link", "/brochure/brochure-request.asp", true, "/images/brouchure.gif", "/images/brouchure-on.gif", "#cccccc", "#efefef");	

_jsmenu_items[_index++] = new menu_item("", "top", "6.", "link", "/contact/contact-main.asp", true, "/images/contact.gif", "/images/contact-on.gif", "#cccccc", "#efefef");
_jsmenu_items[_index++] = new menu_item("Contact Inquiry Form", "sub", "6.1", "link", "/contact/contact-request.asp", true, "", "", "#ffffff", "#efefef");



_jsmenu_items[_index++] = new menu_item("", "top", "7.", "link", "/careers/careers-main.asp", true, "/images/jobs.gif", "/images/jobs-on.gif", "#cccccc", "#efefef");		

_jsmenu_items[_index++] = new menu_item("", "top", "8.", "link", "/index.asp", true, "/images/home.gif", "/images/home.gif", "#cccccc", "#efefef");		

function td_over_color(_p_element, _p_image_element, _p_color, _p_image)
{
//	var _the_style = eval('document.all.' + _p_element + '.style');
 	var _the_style = document.getElementById(_p_element).style;

	if ( !_use_images || _p_image == "" )
	{
		_the_style.backgroundColor = _p_color;
	}
	else
	{
		_the_style.backgroundColor = _table_bgcolor;
		
		if (document.images)
		{
			document.images[_p_image_element].src = _p_image;
		}
	}
}

function td_out_color(_p_element, _p_image_element, _p_color, _p_image)
{
//	var _the_style = eval('document.all.' + _p_element + '.style');
	var _the_style = document.getElementById(_p_element).style;
	
	if ( !_use_images || _p_image == "" )
	{
		_the_style.backgroundColor = _p_color;
	}
	else
	{
		_the_style.backgroundColor = _table_bgcolor;

		if (document.images)
		{
			document.images[_p_image_element].src = _p_image;
		}
	}
}

function td_click(_p_element)
{
	var _stemp = _p_element.substring(3, _p_element.length);
	var _itemp = make_int(_stemp);

	if ( _itemp > -1 && _itemp < _jsmenu_items.length )
	{
		if ( _jsmenu_items[_itemp].action.toLowerCase() == "link" )
		{
			if ( _jsmenu_items[_itemp].link_internal )
			{
				_current_item = _jsmenu_items[_itemp].code;
				//var obj = document.getElementById("menu_goes_here");
				//obj.innerHTML = write_menu();
				location.href = _jsmenu_items[_itemp].link + "?" + _current_item;
			}
			else
			{
				_current_item = _jsmenu_items[_itemp].code;
				//var obj = document.getElementById("menu_goes_here");
				//obj.innerHTML = write_menu();
				location.href = _jsmenu_items[_itemp].link;
			}
		}
		else if ( _jsmenu_items[_itemp].action.toLowerCase() == "open" )
		{
			_current_item = _jsmenu_items[_itemp].code;
			var obj = document.getElementById("menu_goes_here");
			obj.innerHTML = write_menu();
		}
	}
}

function make_int(_p_string)
{
	var _out = -1;
	
	_out = parseInt(_p_string);
	
	return _out;
}

function write_menu()
{
	var s = "<table width='" + _outer_table_width + "'"
				+ " border='" + _outer_table_border + "'"
				+ " cellspacing='" + _outer_table_cellspacing + "'"
				+ " cellpadding='" + _outer_table_cellpadding + "'"
				+ " bgcolor='" + _table_bgcolor + "'>";
	var j = 1;
	for ( var i = 0; i < _jsmenu_items.length; i++ )
	{
		var _mouse_over_action = "td_over_color('td_" + i + "','img_" + i + "','" 
			+ _jsmenu_items[i].over_color + "','" + _jsmenu_items[i].over_image + "');";
		var _mouse_out_action = "td_out_color('td_" + i + "','img_" + i + "','" 
			+ _jsmenu_items[i].normal_color + "','" + _jsmenu_items[i].normal_image + "');";
		var _mouse_click = "td_click('td_" + i + "');";
		
		var _item_text;
		var _was_text;		
		
		if ( !_use_images || _jsmenu_items[i].normal_image == "" )
		{
			_item_text = _jsmenu_items[i].text;
			_was_text = true;
		}
		else
		{
			_item_text = "<img id='img_" + i + "' src='" + _jsmenu_items[i].normal_image + "'>";
			_was_text = false;
		}

		if ( _jsmenu_items[i].type.toLowerCase() == "top" )
		{
			if ( make_int(_current_item) == j ) 
			{
//alert('Should Be Image Over And Sticky')
				_item_text = "<img id='img_" + i + "' src='" + _jsmenu_items[i].over_image + "'>";
			}
			j++;
		}

		if( _jsmenu_items[i].type.toLowerCase() == "sub" )
		{
			if ( is_open(_current_item, _jsmenu_items[i].code) )
			{
				s += "<tr><td><table width=192"
								+ " border='" + _inner_table_border + "'"
								+ " cellspacing='" + _inner_table_cellspacing + "'"
								+ " cellpadding='" + _inner_table_cellpadding + "'"
								+ " bgcolor='" + _table_bgcolor + "'>";
								s += "<tr>";
									s += "<td width='" + _image_width + "'"
										+  " bgcolor='" + _table_bgcolor + "'>";
										if ( _jsmenu_items[i].code == _current_item )
										{
											s += "<img src='" + _selected_image + "'>";
										}
										else
										{
											s += "<img src='" + _blank_image + "'";
										}
									s += "</td>";
									if ( _jsmenu_items[i].code == _current_item )
									{
										s += "<td bgcolor='" + _jsmenu_items[i].normal_color + "'>";
											s += _item_text;
										s += "</td>";
									}
									else
									{
										s += "<td id='td_" + i + "' bgcolor='" + _jsmenu_items[i].normal_color + "' ";
											s += 'onmouseover="' + _mouse_over_action + '"';
											s += ' onmouseout="' + _mouse_out_action + '"';
											s += ' onclick="' + _mouse_click + '"';
										s += ">";
											s += _item_text;
										s += "</td>";
									}
								s += "</tr>";
							s += "</table>";
					s += "</td>";
				s += "</tr>";
			}
		}
		else
		{
			s += "<tr><td><table width=192"
							+ " border='" + _inner_table_border + "'"
							+ " cellspacing='" + _inner_table_cellspacing + "'"
							+ " cellpadding='" + _inner_table_cellpadding + "'"
							+ " bgcolor='" + _table_bgcolor + "'>";
						s += "<tr>";
							if ( _was_text )
							{
								s += "<td id='td_" + i + "' bgcolor='" + _jsmenu_items[i].normal_color + "' ";
							}
							else
							{
								s += "<td id='td_" + i + "' bgcolor='" + _table_bgcolor + "' ";
							}
						
							if ( make_int(_current_item) != j - 1 ) 
							{
								s += 'onmouseover="' + _mouse_over_action + '"';
								s += ' onmouseout="' + _mouse_out_action + '"';
							}
else
{
//alert('Suspend over and out')
}						
							s += ' onclick="' + _mouse_click + '"';
							
							s += ">";
							s += _item_text;
							s += "</td>";
						s += "</tr>";
					s += "</table>";
				s += "</td>";
			s += "</tr>";
		}
	}
	
	s += "</table>";
	
	return s;
}

function do_menu()
{
	var obj = document.getElementById("menu_goes_here");
	obj.innerHTML = write_menu();
}
