/***********************************************************************
*	ROOM & BOARD GLOBAL JAVASCRIPT FILE
*	Copyright (c) 2005 Room & Board. All rights reserved.
*	Authored by: Spencer H. Bennett
***********************************************************************/

//-- USER AGENT OBJECT

var oUa, popup, iHome = 0, iAux = 0;

function clsUa(){
	this.ua=navigator.userAgent.toLowerCase();
	this.mac=(this.ua.indexOf("mac")!=-1);
	this.ns4=(document.layers);
	this.ns6=(this.ua.indexOf('netscape6/6.0')!=-1);
	this.w3c=(document.getElementById)?1:0;
	this.ieX=(document.all)?1:0;
	this.ie5=(this.ieX && this.w3c)?1:0;
	this.ieMac=(this.ieX && this.mac)?1:0;
	this.oContent = document.getElementById('content');
	this.oNavB = document.getElementById('navB');
	this.oNavC = document.getElementById('navC');
	this.oNavD = document.getElementById('navD');
	this.oNavZ = document.getElementById('navZ');
	this.oOn = 0;
	}

//-- GLOBAL FORM METHODS

function clearField(x){
	x.value = '';
	}

//-- GLOBAL POP-UP WINDOW METHODS

function openWindow(sUrl,iW,iH,bScr,bTbr,bRsz,sWin) {
	var iAW = screen.availWidth, iAH = screen.availHeight,
		sArg = 'toolbar=' + bTbr + ',location=0,directories=0,status=0,scrollbars=' + bScr + ',resizable=' + bRsz + ',width=' + iW + ',height=' + iH + ',left=' + (iAW-iW)/2 + ',top=' + (iAH-iH)/2;
	if (sWin) {
		sWin = window.open(sUrl,sWin,sArg);
		sWin.focus();
	} else {
		oWin = window.open(sUrl,'newWin',sArg);
		oWin.focus();
		}
	}

function closeRedirect(x){
	opener.location.href = x;
	opener.focus();
	window.close();
	}

//-- SWATCH VIEW METHODS

function swapSwatch(x){
	document.getElementById('imgLabel').innerHTML = arrSwatch[x][0];
	document.bigImage.src = arrSwatch[x][1];
	sRepeatName = arrSwatch[x][0];
	sRepeatUrl = arrSwatch[x][1];
//	document.getElementById('matDetail').innerHTML = arrSwatch[x][2];
	}

//-- SECONDARY NAVIGATION : RESET METHODS

function reset(){
	oUa.oTo = setTimeout(hide,500);
	}

function hide(){
	off(oUa.oOn);
	if (oUa.oOn.oChild){
		oUa.oOn.oChild.style.visibility = 'hidden';
		if (oUa.oOn.oChild.oChildOn) oUa.oOn.oChild.oChildOn.style.visibility = 'hidden';
		}
	oUa.oOn = 0;
	}

//-- SECONDARY NAVIGATION : OPTION DISPLAY METHODS

function on(x){
	clearTimeout(oUa.oTo);
	x.style.zIndex = 750;
	if (!x.bTop) x.style.borderTop = '1px solid #FFFFFF';
	if (!x.bBot) x.style.borderBottom = '1px solid #FFFFFF';

	if (x.oTtl) x.oTtl.style.color = '#797979';

	x.style.background = '#EAECEE';
	x.style.cursor = (oUa.ieX && !oUa.mac) ? 'hand' : 'pointer';
	window.status = x.sUrl;
	}

function off(x){
	x.style.zIndex = 500;
	if (!x.bTop) x.style.borderTop = (iAux) ? '1px solid #C8D5CE' : '1px solid #DDDDDD';
	if (!x.bBot) x.style.borderBottom = (iAux) ? '1px solid #C8D5CE' : '1px solid #DDDDDD';

	if (x.oTtl) x.oTtl.style.color = '#FFFFFF';

	x.style.background = (iAux) ? '#C8D5CE' : '#DDDDDD';
	window.status = '';
	}

//-- SECONDARY NAVIGATION : ROOT OBJECT METHODS

function mover(x){
	if (oUa.oOn && oUa.oOn != x){
		off(oUa.oOn);
		if (oUa.oOn.oChild){
			oUa.oOn.oChild.style.visibility = 'hidden';
			if (oUa.oOn.oChild.oChildOn) oUa.oOn.oChild.oChildOn.style.visibility = 'hidden';
			}
		}
	on(x); oUa.oOn = x;
	if (x.oChild){
		var iX = oUa.oContent.offsetLeft + 140,
			iY = oUa.oContent.offsetTop,
			iXoffset = (oUa.ns6 || oUa.mac) ? 10 : 0,
			iYoffset = (oUa.ns6 || oUa.mac) ? 10 : 0;
		oUa.oNavC.style.left = (iX + iXoffset) + 'px';
		oUa.oNavC.style.top = (iHome + iY + iYoffset) + 'px';
		oUa.oNavC.style.visibility = 'visible';
		x.oChild.style.visibility = 'visible';
		if (!oUa.ns6){
			if (oUa.ieX && oUa.mac) iXoffset = 12;
			oUa.oNavD.style.left = (oUa.ieX) ? (iX + iXoffset + 139) + 'px' : (iX + iXoffset + 141) + 'px';
			oUa.oNavD.style.top = iHome + iY + iYoffset + 'px';
			oUa.oNavD.style.visibility = 'visible';
			}
		}
	}

function mout(x){
	if (!x.oChild) off(x);
	}

function mclick(x){
	window.location.href = x;
	}

//-- SECONDARY NAVIGATION : CHILD OBJECT METHODS

function hideC(){
	this.style.visibility = 'hidden'; off(this.oParent);
	if (this.oParent.oParentDiv) this.oParent.oParentDiv.style.visibility = 'hidden';
	if (this.oParent.oParentNav) off(this.oParent.oParentNav);
	if (this.oChildOn) this.oChildOn.style.visibility = 'hidden';
	}

function moverC(){
	if (this.oParentDiv.oOn) off(this.oParentDiv.oOn);
	if (this.oParentDiv.oChildOn){
		clearTimeout(this.oParentDiv.oChildOn.oTo);
		this.oParentDiv.oChildOn.style.visibility = 'hidden';
		}
	if (this.oParentNav.oParentDiv) clearTimeout(this.oParentNav.oParentDiv.oTo);
	clearTimeout(this.oParentDiv.oTo);
	on(this.oParentNav); on(this);
	if (this.oChild){
		this.oChild.style.visibility = 'visible';
		this.oParentDiv.oChildOn = this.oChild;
		}
	this.oParentDiv.oOn = this;
	}

function moutC(){
	off(this); this.oParentDiv.oTo = setTimeout(this.oParentDiv.sHide,500);
	}

//-- SECONDARY NAVIGATION : INITIALIZATION

var bNoInit = 0;

function init(){
	oUa = new clsUa();
	if (oUa.ns4 || bNoInit) return;
/*
	if (!iAux && !oUa.ieMac){
		arrNav.splice(0,0,new Array('New for 2005','http://search.roomandboard.com/exec/?query=&status=n'));
	} else if (!iAux && oUa.ieMac) {
		arrNav[arrNav.length] = new Array('New for 2005','http://search.roomandboard.com/exec/?query=&status=n');
		}
*/
	var sHTML = '', xHTML = '', iOffset = (oUa.ieX && !oUa.mac) ? 23 : 25;
	for (var i = 0; i < arrNav.length; i++) sHTML += '<div id="nav_' + i + '" style="top:' + i * iOffset + 'px;" onmouseover="mover(this);" onmouseout="mout(this);" onclick="mclick(this.sUrl);"><div id="navTtl_' + i + '">' + arrNav[i][0] + '</div></div>';
	oUa.oNavB.innerHTML = sHTML;
	sHTML = '';
	for (var i = 0; i < arrNav.length; i++){
		arrNav[i][0] = document.getElementById('nav_' + i);
		arrNav[i][0].sUrl = arrNav[i][1];
		if (i == iAux - 1){
			arrNav[i][0].oTtl = document.getElementById('navTtl_' + i);
			arrNav[i][0].oTtl.style.color = '#FFFFFF';
			}
		if (arrNav[i][2]){
			sHTML += '<div id="navC_' + i + '" class="navC"></div>';
			arrNav[i][0].oChild = 1;
			}
		}
	oUa.oNavC.innerHTML = sHTML;
	for (var i = 0; i < arrNav.length; i++){
		if (arrNav[i][0].oChild){
			arrNav[i][0].oChild = document.getElementById('navC_' + i); sHTML = '';
			for (var ii = 0; ii < arrNav[i][2].length; ii++) sHTML += '<div id="navC_' + i + '_' + ii + '" style="top:' + (ii * iOffset) + 'px;" onmouseover="arrNav[' + i + '][2][' + ii + '][0].mover();" onmouseout="arrNav[' + i + '][2][' + ii + '][0].mout();" onclick="mclick(this.sUrl);"><div>' + arrNav[i][2][ii][0] + '</div></div>';
			arrNav[i][0].oChild.innerHTML = sHTML;
			arrNav[i][0].oChild.style.top = arrNav[i][0].style.top;
			arrNav[i][0].oChild.oParent = arrNav[i][0];
			arrNav[i][0].oChild.hide = hideC;
			arrNav[i][0].oChild.sHide = 'arrNav[' + i + '][0].oChild.hide()';
			for (var ii = 0; ii < arrNav[i][2].length; ii++){
				arrNav[i][2][ii][0] = document.getElementById('navC_' + i + '_' + ii);
				arrNav[i][2][ii][0].sUrl = arrNav[i][2][ii][1];
				if (!ii){
					arrNav[i][2][ii][0].bTop = 1;
					arrNav[i][2][ii][0].style.borderTop = '0px';
					if (oUa.ieX && !oUa.mac) arrNav[i][2][ii][0].style.height = '24px';
					}
				if (ii == arrNav[i][2].length - 1){
					arrNav[i][2][ii][0].bBot = 1;
					arrNav[i][2][ii][0].style.borderBottom = '0px';
					arrNav[i][0].oChild.style.height = (oUa.ieX && !oUa.mac) ? parseInt(arrNav[i][2][ii][0].style.top) + 27 + 'px' : parseInt(arrNav[i][2][ii][0].style.top) + 26 + 'px';
					}
				if (oUa.ieX && !oUa.mac) arrNav[i][2][ii][0].style.width = '138px';
				arrNav[i][2][ii][0].oParent = arrNav[i][0];
				arrNav[i][2][ii][0].oParentNav = arrNav[i][0];
				arrNav[i][2][ii][0].oParentDiv = arrNav[i][0].oChild;
				arrNav[i][2][ii][0].mover = moverC;
				arrNav[i][2][ii][0].mout = moutC;
				arrNav[i][2][ii][0].sHide = 'arrNav[' + i + '][2][' + ii + '][0].hide()';
				if (!oUa.ns6 && arrNav[i][2][ii][2]){
					xHTML += '<div id="navCC_' + i + '_' + ii + '" class="navC"></div>';
					arrNav[i][2][ii][0].oChild = 1;
					}
				}
			}
		}
	if (!oUa.ns6){
		oUa.oNavD.innerHTML = xHTML;
		for (var i = 0; i < arrNav.length; i++){
			if (arrNav[i][0].oChild){
				for (var ii = 0; ii < arrNav[i][2].length; ii++){
					if (arrNav[i][2][ii][0].oChild){
						arrNav[i][2][ii][0].oChild = document.getElementById('navCC_' + i + '_' + ii);
						sHTML = '';
						for (var iii = 0; iii < arrNav[i][2][ii][2].length; iii++){
							sHTML += '<div id="navC_' + i + '_' + ii +  '_' + iii + '" style="top:' + (iii * iOffset) + 'px;" onmouseover="arrNav[' + i + '][2][' + ii + '][2][' + iii + '][0].mover();" onmouseout="arrNav[' + i + '][2][' + ii + '][2][' + iii + '][0].mout();" onclick="mclick(this.sUrl);"><div>' + arrNav[i][2][ii][2][iii][0] + '</div></div>';
							}
						arrNav[i][2][ii][0].oChild.innerHTML = sHTML;
						var iX = !(parseInt(arrNav[i][2][ii][0].style.top)) ? 0 : 1;
						arrNav[i][2][ii][0].oChild.style.top = parseInt(arrNav[i][0].style.top) + parseInt(arrNav[i][2][ii][0].style.top) + iX + 'px';
						arrNav[i][2][ii][0].oChild.oParent = arrNav[i][2][ii][0];
						arrNav[i][2][ii][0].oChild.hide = hideC;
						arrNav[i][2][ii][0].oChild.sHide = 'arrNav[' + i + '][2][' + ii + '][0].oChild.hide()';
						for (var iii = 0; iii < arrNav[i][2][ii][2].length; iii++){
							arrNav[i][2][ii][2][iii][0] = document.getElementById('navC_' + i + '_' + ii +  '_' + iii);
							arrNav[i][2][ii][2][iii][0].sUrl = arrNav[i][2][ii][2][iii][1];
							if (!iii){
								arrNav[i][2][ii][2][iii][0].bTop = 1;
								arrNav[i][2][ii][2][iii][0].style.borderTop = '0px';
								if (oUa.ieX && !oUa.mac) arrNav[i][2][ii][2][iii][0].style.height = '24px';
								}
							if (iii == arrNav[i][2][ii][2].length - 1){
								arrNav[i][2][ii][2][iii][0].bBot = 1;
								arrNav[i][2][ii][2][iii][0].style.borderBottom = '0px';
								if (!oUa.ieX && !oUa.mac) arrNav[i][2][ii][2][iii][0].style.height = '24px';
								arrNav[i][2][ii][0].oChild.style.height = (oUa.ieX && !oUa.mac) ? parseInt(arrNav[i][2][ii][2][iii][0].style.top) + 27 + 'px' : (!parseInt(arrNav[i][2][ii][0].oChild.style.top)) ? parseInt(arrNav[i][2][ii][2][iii][0].style.top) + 26 + 'px' : parseInt(arrNav[i][2][ii][2][iii][0].style.top) + 25 + 'px';
								}
							if (oUa.ieX && !oUa.mac) arrNav[i][2][ii][2][iii][0].style.width = '138px';
							arrNav[i][2][ii][2][iii][0].oParentNav = arrNav[i][2][ii][0];
							arrNav[i][2][ii][2][iii][0].oParentDiv = arrNav[i][2][ii][0].oChild;
							arrNav[i][2][ii][2][iii][0].mover = moverC;
							arrNav[i][2][ii][2][iii][0].mout = moutC;
							arrNav[i][2][ii][2][iii][0].sHide = 'arrNav[' + i + '][2][' + ii + '][2][' + iii + '][0].hide()';
							}
						}
					}
				}
			}
		}
	oUa.oNavZ.style.display = 'none';
	oUa.oNavB.style.display = 'block';
	}

onload = init;
