var s = "";

// generic methods
function showElement(eName) {
	if(document.getElementById) document.getElementById(eName).style.visibility = 'visible';
	else if(document.all) document.all[eName].style.visibility = "visible";
	else if(document.layers) document[eName].visibility = "show";
}


function w(text) {document.write(text);}

// header navigation menus
menu_company = [
	[],
	["Start Here", s + "index.php",,,,,,,,0],
	["About us", s + "about.php",,,,,,,,0],
	["Latest News", s + "news.php",,,,,,,,0],
	["Contact Us", s + "contact.php",,,,,,,,0],
	["Privacy Policy", s + "privacy.php",,,,,,,,0]
]

menu_landlords = [
	[],
	["Start Here", s + "landlords.php",,,,,,,,0],
	["FAQ", s + "landlords_faq.php",,,,,,,,0],
	["Our Services", s + "landlords_services.php",,,,,,,,0],
	["Preparing to Let", s + "landlords_prep.php",,,,,,,,0],
	["Letting to Students", s + "landlords_studentlets.php",,,,,,,,0],
	["Going Overseas", s + "landlords_overseas.php",,,,,,,,0],
	["Tenancy Deposit Scheme", s + "landlords_deposits.php",,,,,,,,0],
	["EPCs", s + "epc_order.php",,,,,,,,0]
]

menu_invest = [
	[],
	["Start Here", s + "invest.php",,,,,,,,0],
	["Buy to Let", s + "invest_buy2let.php",,,,,,,,0],
	["What to Buy", s + "invest_what2buy.php",,,,,,,,0]
]

menu_properties = [
	[],
	["Properties To Let", s + "properties.php",,,,,,,,0],
	["Short-term Lets", s + "property_short_term.php",,,,,,,,0],
	["Sharers", s + "sharers.php",,,,,,,,0],
	["Student Properties", s + "students.php",,,,,,,,0],
	["Coming Soon", s + "property_coming_soon.php",,,,,,,,0],
	["Letting Information", s + "properties_info.php",,,,,,,,0]
]

menu_insurance = [
	[],
	["Landlords Insurance", "insurance_landlords.php",,,,,,,,0],
	["Tenants Insurance", s + "insurance_tenants.php",,,,,,,,0]	
]

menu_sourcing = [
	[],
	["FAQ", s + "sourcing.php",,,,,,,,0],
	["For Landlords", s + "sourcing_landlords.php",,,,,,,,0],
	["Tenant Relocation", s + "tenants_sourcing.php",,,,,,,,0],
	["Company Relocation", s + "relocation.php",,,,,,,,0]
]

menu_tenants = [
	[],
	["General Information", s + "tenants.php",,,,,,,,0],
	["FAQ", s + "tenants_faq.php",,,,,,,,0],
	["Tenancy Deposit Scheme", s + "tenants_deposits.php",,,,,,,,0],
	["Rental Procedure", s + "tenants_rental.php",,,,,,,,0],
	["Email Property Alerts", s + "tenants_mlist.php",,,,,,,,0],
	["Register with BRPL", s + "tenants_register.php",,,,,,,,0]
]

menu_links = [
	[],
	["General", s + "links.php?type=assoc",,,,,,,,0],
	["Gas Contractors", s + "links.php?type=plumb",,,,,,,,0],
	["Property Letting Resources", s + "links.php?type=info",,,,,,,,0],
	["Legal Information and Guidance", s + "links.php?type=legal",,,,,,,,0],
	["Mortgages and Buy-2-Let", s + "links.php?type=finance",,,,,,,,0],
	["Professional Bodies", s + "links.php?type=prof",,,,,,,,0]
]


MENU_ARRAY_PREFIX = "menu_";
MENU_PREFIX = "menu";
ROW_PREFIX = "row";
MENU_WIDTH = 173;
MS_VISIBLE = 800;
FONT_FAMILY = "Lucida Grande, Geneva, Arial, Verdana, sans-serif";
FONT_SIZE = "12px";
LINE_HEIGHT = 17;
CHILD_ARROW = "images/arrow.gif";
CHILD_ARROW_SIZE = 14; // it's square
TXT_ARROW_DRK = "images/n_arrows_grey.gif";
TXT_ARROW_DRL = "images/arrow.gif";
TXT_ARROW_LT = "images/n_arrows_white.gif";
TXT_ARROW_LT = "images/arrow.gif";
TXT_ARROW_SIZE = 7; // it's square
//DFLT_1_FONT = "#333333";
//DFLT_2_FONT = "#333333";
//DFLT_3_FONT = "#FF0000";
//DFLT_1_FONTOVR = "#333333";
//DFLT_2_FONTOVR = "#FFFFFF";
//DFLT_3_FONTOVR = "#ff000000";
//DFLT_1_BG = "#EDEEEC";
//DFLT_2_BG = "#BABDB6";
//DFLT_3_BG = "#6B6C69";
//DFLT_3_BG = "#6494B6";
DFLT_3_BG = "#005ADF";
//DFLT_1_BGOVR = "#BABDB6";
//DFLT_2_BGOVR = "#6B6C69";
//DFLT_3_BGOVR = "#2E3436";
DFLT_3_BGOVR = "#666666";
HDRMENU_1_ID = "company";
HDRMENU_2_ID = "landlords";
HDRMENU_3_ID = "invest";
HDRMENU_4_ID = "properties";
HDRMENU_5_ID = "insurance";
HDRMENU_6_ID = "sourcing";
HDRMENU_7_ID = "tenants";
HDRMENU_8_ID = "links";
HDR_MENU_HGHT = 111;

// setup varables used for storing menu state
currentMenuArray = null;
currentMenuTree = null;
currentMenu = null;
currentMenuLink = null;
hideTimer = null;
showTimer = null;
mouseOverMenu = false;
topLevelMenus = [];
isHdrNavCreated = false;

// left navigation funxtions
function createLeftNav(menuId) {
	if((typeof(document.body) == "undefined") || (document.body == null)) return;
	currentMenuArray = eval(MENU_ARRAY_PREFIX + menuId);
	currentMenuTree = { width:MENU_WIDTH, x:currentMenuArray[0][1], y:currentMenuArray[0][2] }
	currentMenu = null;
	topLevelMenus[topLevelMenus.length] = createLeftMenu(menuId);
}

function createLeftMenu(menuId) {
	currentMenuArray = eval(MENU_ARRAY_PREFIX + menuId);
	var lyr = document.createElement("DIV");
	lyr.id = MENU_PREFIX + menuId;
	with(lyr.style) {
		width = currentMenuTree.width + "px";
		padding= "0px 0px 0px 0px";
		zIndex = 1000;
	}
	navLocation = document.getElementById("leftNavMenus");
	navLocation.appendChild(lyr);
	if(currentMenu) {
		with(lyr.style) {
			visibility = "hidden";
			position = "absolute";
			left = "-200px";
			top = "-200px";
		}
		lyr.parentMenu = currentMenu;
		lyr.parentItem = currentMenu.row;
		lyr.parentItem.child = lyr;
		lyr.hasParent = true;
		lyr.level = lyr.parentMenu.level + 1;
	}
	else {
		with(lyr.style) {
			visibility = "visible";
			position = "absolute";
			left = currentMenuTree.x + "px";
			top = currentMenuTree.y + "px";
		}
		currentMenuTree.treeParent = currentMenuTree.startChild = lyr;
		lyr.level = 1;
	}
	currentMenu = lyr;
	currentMenu.isHdrMenu = false;
	currentMenu.array = currentMenuArray;
	currentMenu.tree  = currentMenuTree;
	currentMenu.itemCount = 0;
	currentMenu.maxItems = currentMenu.array.length - 1;
	currentMenu.showLinks = showLinks;
      currentMenu.onmouseover = onMenuOver;
      currentMenu.onmouseout = onMenuOut;
      currentMenu.hideTree = hideTree;
      currentMenu.hideParents = hideParentMenus;
      currentMenu.hideChildren = hideChildMenus;
      currentMenu.hideTop = hideTop;
      currentMenu.hideSelf = hideSelf;
      currentMenu.hasChildVisible = false;
      currentMenu.isOn = false;
      currentMenu.hideTimer = null;
      currentMenu.currentItem = null;
	while(currentMenu.itemCount < currentMenu.maxItems)
            {
		currentMenu.itemCount++;
		currentMenu.row = createRow(menuId);
		if(currentMenu.row.hasMore)
               {
		   var childMenu = createLeftMenu(menuId + "_" + currentMenu.itemCount);
			if(childMenu) currentMenu = currentMenu.parentMenu;
		   }
            }
      for(var i = 0; i < currentMenu.childNodes.length; i++) 
          {
          var row = currentMenu.childNodes[i];
	    row.style.top = (row.index) ? (parseInt(row.siblingBelow.style.top) + LINE_HEIGHT + 2) + "px" : row.style.top = "0px";
	    }
	currentMenu.style.height = (currentMenu.childNodes.length*20) + "px";
	return currentMenu;
}

// header navigation specific functions
function createHdrNav() {
	if((typeof(document.body) == "undefined") || (document.body == null)) return;
	createHdrMenu(HDRMENU_1_ID, 80, 150);
	createHdrMenu(HDRMENU_2_ID, 161, 180);
	createHdrMenu(HDRMENU_3_ID, 242, 150);
	createHdrMenu(HDRMENU_4_ID, 323, 150);
	createHdrMenu(HDRMENU_5_ID, 404, 150);
	createHdrMenu(HDRMENU_6_ID, 485, 150);
	createHdrMenu(HDRMENU_7_ID, 566, 180);
	createHdrMenu(HDRMENU_8_ID, 647, 200);

	isHdrNavCreated = true;
}

function createHdrMenu(menuId, xPos, mWidth) {
	currentMenu = null;
	currentMenuArray = eval(MENU_ARRAY_PREFIX + menuId);
	currentMenuTree = { width:mWidth, id:menuId, x:xPos, y:HDR_MENU_HGHT }
	topLevelMenus[topLevelMenus.length] = createHdrMenuObject(menuId);
}

function createHdrMenuObject(menuId) {
	currentMenuArray = eval(MENU_ARRAY_PREFIX + menuId);
	var lyr = document.createElement("DIV");
	lyr.id = MENU_PREFIX + menuId;
	with(lyr.style) {
		width = currentMenuTree.width + "px";
		padding= "0px 0px 0px 0px";
		zIndex = 1001;
		visibility = "hidden";
		position = "absolute";
		left = currentMenuTree.x + "px";
		top = currentMenuTree.y + "px";
	}
	navLocation = document.getElementById("hdrNavMenus");
	navLocation.appendChild(lyr);
	if(currentMenu) {
		lyr.parentMenu = currentMenu;
		lyr.parentItem = currentMenu.row;
		lyr.parentItem.child = lyr;
		lyr.hasParent = true;
		lyr.level = lyr.parentMenu.level + 1;
	}
	else {
		currentMenuTree.treeParent = currentMenuTree.startChild = lyr;
		lyr.level = 2;
	}
	currentMenu = lyr;
	currentMenu.isHdrMenu = true;
	currentMenu.array = currentMenuArray;
	currentMenu.tree  = currentMenuTree;
	currentMenu.itemCount = 0;
	currentMenu.maxItems = currentMenu.array.length - 1;
	currentMenu.showLinks = showLinks;
    currentMenu.onmouseover = onMenuOver;
    currentMenu.onmouseout = onMenuOut;
    currentMenu.hideTree = hideTree;
    currentMenu.hideParents = hideParentMenus;
    currentMenu.hideChildren = hideChildMenus;
    currentMenu.hideTop = hideTop;
    currentMenu.hideSelf = hideSelf;
    currentMenu.hasChildVisible = false;
    currentMenu.isOn = false;
    currentMenu.hideTimer = null;
    currentMenu.currentItem = null;
	currentMenu.hdrElement = document.getElementById(menuId);
	while(currentMenu.itemCount < currentMenu.maxItems) {
		currentMenu.itemCount++;
		currentMenu.row = createRow(menuId);
    }
    for(var i = 0; i < currentMenu.childNodes.length; i++) {
        var row = currentMenu.childNodes[i];
	    row.style.top = (row.index) ? (parseInt(row.siblingBelow.style.top) + LINE_HEIGHT + 2) + "px" : row.style.top = "10px";
	}
	currentMenu.style.backgroundColor = DFLT_3_BG;
	currentMenu.style.height = (currentMenu.childNodes.length*20) + 20 + "px";
	return currentMenu;
}

function showHdrMenu(navId) {
	if(!isHdrNavCreated) return;
	var hMenu = document.getElementById(MENU_PREFIX + navId);
	if(!hMenu) return;
	currentMenu = hMenu;
	if(!currentMenu.tree.startChild) currentMenu.tree.startChild = currentMenu;
	if(currentMenu.tree.startChild == currentMenu) hideTopLevelMenus(currentMenu);
    currentMenu.isOn = true;
    mouseOverMenu = true;
    if(currentMenu.hideTimer) clearTimeout(currentMenu.hideTimer);
	showTimer = setTimeout("currentMenu.showLinks(true)", 300);
	with(currentMenu.hdrElement.style) {
		backgroundColor = "#6B6C69";
		cursor = (navigator.vendor == ("Netscape6") || navigator.product == ("Gecko")) ? "pointer" : "hand";
	}
}

function hideHdrMenu(navId) {
	if(!isHdrNavCreated) return;
    this.isOn = false;
    mouseOverMenu = false;
	clearTimeout(showTimer);
	showTimer = null;
	clearTimeout(hideTimer);
	hideTimer = null;
	hideTimer = setTimeout("currentMenu.hideTree()", MS_VISIBLE);
}

// functions common to header and left navigation
function createRow(menuCount) {
	var row = document.createElement("DIV");
	row.id = ROW_PREFIX + menuCount + "_" + currentMenu.itemCount;
	row.menu = currentMenu;
	row.tree = currentMenuTree;
	row.index = currentMenu.itemCount - 1;
	row.isLastItem = (currentMenu.itemCount == currentMenu.maxItems);
	row.array = currentMenu.array[currentMenu.itemCount];
	row.dispText = row.array[0];
	row.linkText = row.array[1];
	row.fontColor = (currentMenu.isHdrMenu) ? "#FFFFFF" : (row.array[2] && row.array[2] != "") ? row.array[2] : eval("DFLT_" + currentMenu.level + "_FONT");
	row.fontColorOver = (currentMenu.isHdrMenu) ? "#FFFFFF" : (row.array[3] && row.array[3] != "") ? row.array[3] : eval("DFLT_" + currentMenu.level + "_FONTOVR");
	row.bgColor = (currentMenu.isHdrMenu) ? DFLT_3_BG : (row.array[4] && row.array[4] != "") ? row.array[4] : eval("DFLT_" + currentMenu.level + "_BG");
	row.bgColorOver = (currentMenu.isHdrMenu) ? DFLT_3_BGOVR : (row.array[5] && row.array[5] != "") ? row.array[5] : eval("DFLT_" + currentMenu.level + "_BGOVR");
	row.hasMore = row.array[9];
	row.arrowSrc = (currentMenu.isHdrMenu) ? TXT_ARROW_LT : (row.array[7] && row.array[7] != "") ? row.array[7] : (currentMenu.level == 3) ? TXT_ARROW_LT : TXT_ARROW_DRK;
	row.arrowSrcOver = (row.array[8] && row.array[8] != "") ? row.array[8] : TXT_ARROW_LT;
	row.childID = row.hasMore ? (MENU_PREFIX + menuCount + "_" + currentMenu.itemCount) : null;
	row.child = null;
    row.onmouseover = rowMouseOver;
    row.onmouseout = rowMouseOut;
	row.showChild = showChildMenu;
	with(row.style) {
		position = "absolute";
		visibility = "inherit";
		backgroundColor = row.bgColor;
		color = row.fontColor;
		padding = "0px 0px 0px 0px";
		fontFamily = FONT_FAMILY;
		fontSize = FONT_SIZE;
		height = (LINE_HEIGHT + 2) + "px";
		lineHeight = LINE_HEIGHT + "px";
		left = "0px";
		width = currentMenuTree.width + "px";
	}
	currentMenu.appendChild(row);
	row.siblingBelow = row.previousSibling;
	if(row.linkText) {
		row.onclick = goToLink;
		row.style.cursor = (navigator.vendor == ("Netscape6") || navigator.product == ("Gecko")) ? "pointer" : "hand";
	}
	row.innerHTML = ((currentMenu.level == 1) ? ("<img src='" + "menu/t3_leftnavhorizline.gif' width='173' height='1' border='0' alt=''><br>&nbsp;&nbsp;" + row.dispText) : "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + row.dispText) + ((currentMenu.level == 1 && row.isLastItem) ? "<br><img src='" + "menu/t3_leftnavhorizline.gif' width='173' height='1' border='0' alt=''>" : "");
    if(row.hasMore) {
		var image = document.createElement("IMG");
		row.imageSrc = CHILD_ARROW;
		row.imageSrcOver = "images/spacer.gif";
		image.src = row.imageSrc;
		image.height = CHILD_ARROW_SIZE;
		image.width = CHILD_ARROW_SIZE;
		with(image.style) {
			position = "absolute";
			top = "3px";
			left = currentMenuTree.width - (CHILD_ARROW_SIZE + 2) + "px";
		}
		row.imageLayer = image;
		row.insertBefore(image,row.firstChild);
	}
	if(currentMenu.level != 1) {
		var arrow = document.createElement("IMG");
		arrow.src = row.arrowSrc;
		arrow.height = TXT_ARROW_SIZE;
		arrow.width = TXT_ARROW_SIZE;
		with(arrow.style) {
			position = "absolute";
			top = "7px";
			left = "8px";
		}
		row.arrowLayer = arrow;
		row.insertBefore(arrow,row.firstChild);
	}
	return row;
}

function onMenuOver() {
	if(!this.tree.startChild) this.tree.startChild = this;
	if(this.tree.startChild == this) hideTopLevelMenus(this)
    this.isOn = true;
    mouseOverMenu = true;
    currentMenu = this;
    if(this.hideTimer) clearTimeout(this.hideTimer);
}

function hideTopLevelMenus(callingmenu) {
	for(var i = 0; i < topLevelMenus.length; i++) {
        var topMenu = topLevelMenus[i].tree.startChild;
		if(topMenu == callingmenu) continue;
        topMenu.isOn = false;
        if(topMenu.hasChildVisible) topMenu.hideChildren();
        topMenu.showLinks(false);
		if(topMenu.isHdrMenu) {
			topMenu.hdrElement.style.backgroundColor = "";
		}
    }    
}

function onMenuOut() {
    this.isOn = false;
    mouseOverMenu = false;
	clearTimeout(hideTimer);
	hideTimer = null;
	hideTimer = setTimeout("currentMenu.hideTree()", MS_VISIBLE);
}

function showChildMenu() {
	this.child.style.left = (parseInt((this.menu.style.left) ? this.menu.style.left : this.menu.offsetLeft) + parseInt(this.style.width)) + "px";
	this.child.style.top = (parseInt((this.menu.style.top) ? this.menu.style.top : this.menu.offsetTop) + this.offsetTop) + "px";
	this.menu.hasChildVisible = true;
	this.menu.visibleChild = this.child;
	this.child.showLinks(true);
}

function rowMouseOver() {
	if(this.menu.currentItem && this.menu.currentItem != this) {
		this.menu.currentItem.style.backgroundColor = this.menu.currentItem.bgColor;
		this.menu.currentItem.style.color = this.menu.currentItem.fontColor;
		if(this.menu.currentItem.hasMore) this.menu.currentItem.imageLayer.src = this.menu.currentItem.imageSrc;
		if(this.menu.level != 1) this.menu.currentItem.arrowLayer.src = this.menu.currentItem.arrowSrc;
	}
	if(this.menu.level != 1) this.arrowLayer.src = this.arrowSrcOver;
    this.style.backgroundColor = this.bgColorOver;
    this.style.color = this.fontColorOver;
	if(this.hasMore)this.imageLayer.src = this.imageSrcOver;
    this.menu.currentItem = this;
	if(this.menu.hasChildVisible) {
		if(this.menu.visibleChild == this.child && this.menu.visibleChild.hasChildVisible) this.menu.visibleChild.hideChildren(this);
		else this.menu.hideChildren(this);
    }
    if(this.hasMore) this.showChild();
	status = this.linkText;
}

function rowMouseOut() {
    if ((this.tree.treeParent==this) && !this.menu.hasChildVisible) {
		if(this.menu.level != 1) this.arrowLayer.src = this.arrowSrc;
        this.style.backgroundColor = this.bgColor;
        this.style.color = this.fontColor;
		if(this.hasMore)this.imageLayer.src = this.imageSrc;
    }
}

function showLinks(on) {
	if(!(this.tree.treeParent == this) || this.isHdrMenu) this.style.visibility = (on) ? "visible" : "hidden";
    if(this.currentItem) {
		this.currentItem.style.backgroundColor = this.currentItem.bgColor;
		this.currentItem.style.color = this.currentItem.fontColor;
		if(this.currentItem.hasMore) this.currentItem.imageLayer.src = this.currentItem.imageSrc;
		if(this.currentItem.menu.level != 1) this.currentItem.arrowLayer.src = this.currentItem.arrowSrc;
    }
    this.currentItem = null;
	if(!on && this.isHdrMenu && this.tree.treeParent==this) {
		this.hdrElement.style.backgroundColor = "";
	}
}

function hideTree() {
    hideTimer = null;
    if(mouseOverMenu) return;
    if(this.hasChildVisible) this.hideChildren();
    this.hideParents();
}

function hideTop() {
	menuToHide = this;
    this.hideTimer = setTimeout("menuToHide.hideSelf()", MS_VISIBLE);
}

function hideSelf() {
    this.hideTimer = null;
    if (!this.isOn && !mouseOverMenu) this.showLinks(false);
}

function hideParentMenus() {
    var menu = this;
    while(menu.hasParent) {
        menu.showLinks(false);
        menu.parentMenu.isOn = false;        
        menu = menu.parentMenu;
    }
	if(!menu.hasParent && menu.isHdrMenu) menu.showLinks(false);
    menu.hideTop();
}

function hideChildMenus(caller) {
    var menu = this.visibleChild;
    while(menu.hasChildVisible) {
        menu.visibleChild.showLinks(false);
        menu.hasChildVisible = false;
        menu = menu.visibleChild;
    }
	if((caller && (!caller.hasMore || this.visibleChild != caller.child)) || (!caller && !this.isOn)) {
        this.visibleChild.showLinks(false);
        this.hasChildVisible = false;
    }
}

function goToLink() {
    if(this.linkText.indexOf("javascript:") != -1) eval(this.linkText)
    else location.href = this.linkText;
}

var hasHdrNav = true;

// Copyright brpl, 2006.  All Rights Reserved.
