var sPicDir = 'pics/', aParams = [], bQueryLoaded = false, sBigImgPopup = null;

function getElem(pElem)
{
	return document.getElementById(pElem);
}

function getQueryValue(pKey)
{
	if (!bQueryLoaded)
		loadParams();
	
	return aParams[pKey] ? aParams[pKey] : "";
}

function loadParams()
{
	var str = document.location.search;
	if (str.length == 0)
		return;
	
	str = unescape(str.substr(1));
	var ps = str.split("&"), psLen = ps.length;

	for (var i=0; i<psLen; i++)
	{
		var p = ps[i].split("=");
		aParams[p[0]] = p[1];
	}

	bQueryLoaded = true;
}

function setRollover()
{
	for (var i=0; i<iNumTns; i++)
	{
		var im = getElem(sTnPrefix + i);
		if (im)
		{
			im.iIndex = i;
			im.style.cursor = 'pointer';
			im.onmouseover = function()
			{
				this.style.cursor = "hand";
				setImageSource(sMainImg, aBigImgs[this.iIndex]);

				if (typeof aBigPopup != 'undefined')
					sBigImgPopup = aBigPopup[this.iIndex];
			}
		}
	}
}

function setImageSource(pElem, pSrc)
{
	var im = document.images[pElem];
	if (im)
		im.src = sPicDir + pSrc;

}

function prefetch(pImgs)
{
	for (var i=0, l=pImgs.length; i<l; i++)
	{
		var im = new Image();
		im.src = sPicDir + pImgs[i];
	}
}

function init ()
{
	if (typeof bSetRollover != 'undefined' &&  bSetRollover)
		setRollover();
	
	if (typeof bPrefetch != 'undefined' && bPrefetch)
		prefetch(aBigImgs);
}

function openBigViewPopup(pObj)
{
	if (sBigImgPopup)
		pObj.href = 'http://www.bermancabinetmakers.com/' + sBigImgPopup + '.html';
	
	return true;
}

/*** write Header/footer untility *******/
function writeHeader()
{
	var s = "";
	s += '<table cellspacing="0" cellpadding="0" border="0"><tr><td>';
	s += '<map name="logo"><area shape="rect" coords="51,12,340,82" href="home.html"/></map>';
	s += '<img src="pics/logo.jpg" alt="Berman Cabinetmakers" border="0" usemap="#logo" /></td>';
	s += '<td valign="bottom" class="nav1"><map name="nav1">';
	s += '<area shape="rect" coords="14,14,83,35" href="services.html" />';
	s += '<area shape="rect" coords="111,14,186,35" href="aboutus.html" />';
	s += '<area shape="rect" coords="210,14,329,35" href="media.html" />';
	s += '<area shape="rect" coords="355,14,442,35" href="contactus.html" />';
	s += '<area shape="rect" coords="472,14,517,35" href="home.html" /></map>';
	s += '<img src="pics/header_nav.jpg" alt="" border="0" hspace="30" usemap="#nav1"/>';
	s += '</td></tr></table>';
	s += '<div class="nav2">';
	s += '<a href="kitchen.html">Kitchens</a>|';
	s += '<a href="bedsbath.html">Beds &amp; Baths</a>|';
	s += '<a href="libs.html">Libraries &amp; Home Offices</a>|';
	s += '<a href="cabinets.html">Cabinets</a>|';
	s += '<a href="entcenters.html">Entertainment Centers</a>|';
	s += '<a href="bookshelves.html">Bookshelves</a>|';
	s += '<a href="tables.html">Tables</a>|';
	s += '<a href="desks.html">Desks</a>';
	s += '</div>';
	
	document.write(s);
}

function writeFooter()
{
	var s = "";
	s += '<div id="footer">';
	s += '"A Thing of Beauty is a Joy Forever"&nbsp;&nbsp;&nbsp;';
	s += '(415) 925-9211&nbsp;&nbsp;&nbsp;(707) 795-8495</div>';

	document.write(s);
}

/**************** Header/Footer Utility *****************/

window.onload = init;