<script language="JavaScript">
//Determine how many pages there are and create
//the pagination links
function buildPagination(type)
{
    var pageButtons = "";
    var boldStyle = "";
    var numOfPages = eval("Math.ceil(arr" + type + ".length/(numOfCols * numOfRows))");

    if (numOfPages > 1)
    {
		if (currentPage > 0)
		{
			pageButtons += "<img src='images/LeftArrow.jpg' style='cursor:hand;' "; 
			pageButtons += "onclick=currentPage=" + (currentPage -1) + ";build" + type + "Table();buildPagination('" + type + "');></input>"; 
		}
		else
		{
			pageButtons = "&nbsp;&nbsp;&nbsp;&nbsp;";
		}
		
		//Iterate through number of pages and create the links.
		for (i = 1; i <=numOfPages;i++)
		{
			if (i == (currentPage + 1))
			{
				boldStyle = "font-weight:bold";
			}
			else
			{
				boldStyle = "";
			}
		
			pageButtons += "<input type='text' class='clsPagination' style='" + boldStyle + "' value='" + i + "'";
			pageButtons += "onclick=currentPage=" + (i-1) + ";build" + type + "Table();buildPagination('" + type + "');></input>";     	
		}
		if ((currentPage+1) != numOfPages)
		{
			pageButtons += "<img src='images/RightArrow.jpg' style='cursor:hand;' "; 
			pageButtons += "onclick=currentPage=" + (currentPage+1) + ";build" + type + "Table();buildPagination('" + type + "');></input>"; 
		}
	}			
	
    divPagination.innerHTML = pageButtons;
}


//Build a table using the array of fabrics.
function buildFabricsTable()
{
	//Begin building table.
	var colNum = 0;
	var numOfItems = numOfCols * numOfRows;
	var beginIndex = numOfItems * currentPage;
	var endIndex = beginIndex + numOfItems;
	var fabricTable = "<table>";

	//Iterate through the fabrics array and build the table.

	for (var i = beginIndex; i < endIndex;i++)
	{

		colNum++;

		//If this is the first column, start new row.
		if (colNum == 1)
		{
			fabricTable += "<tr>";
		}


		fabricTable += "<td class='" + cssClassTd + "'>";
		
		if (arrFabrics[i] != null)
		{
		    //Create links if this table is set to have image links.
		    if (hasLink == true)
		    {
		        fabricTable += "<a href=" + arrFabrics[i].link + ">";
		    }
		    
            //Create the image link.
			fabricTable += "<img id='imgFabric" + i + "' class='" + cssClassImg + "' src='" + arrFabrics[i].image + "'";
			
			//Create hover over events if this table is set to show Hover overs.
			if (showHoverWindow == true)
			{
			    fabricTable += " onmouseover=showImage('" + arrFabrics[i].image + "',this," + i + ");";
			    fabricTable += " onmouseout=removeImage('" + arrFabrics[i].image + "',this);";
			}
			
			fabricTable += ">";
			
			if (hasLink == true)
		    {
		        fabricTable += "</a>";
		    }
		    
		    if (showPrepender == true)
		    {
		    	fabricTable += "<br/>Pattern: ";
		    }
		    else
		    {
		    	fabricTable += "<br/>";
		    }
		    		    
			if (showFabricPattern == true)
			{
			    fabricTable += arrFabrics[i].pattern;
			}
			
			if (showFabricColor == true)
			{
			    fabricTable += "<br/>Color: " + arrFabrics[i].color;
			}
			
			if (showFabricPrice == true)
			{
			    fabricTable += "<br/>Price: " + arrFabrics[i].price;
			}
		}
		else
		{
			fabricTable += "&nbsp;";
		}	
			
		fabricTable += "</td>";

		//If this is the last column, close row.
		if (colNum == numOfCols)
		{
			fabricTable += "</tr>";
			colNum = 0;
		}
	}

	fabricTable += "</table>";
	
	//Now place this html inside the content div tag.
	document.getElementById('divContent').innerHTML = fabricTable ;
	

}


//Build a table using the array of fabrics.
function buildClientsTable()
{
	//Begin building table.
	var colNum = 0;
	var numOfItems = numOfCols * numOfRows;
	var beginIndex = numOfItems * currentPage;
	var endIndex = beginIndex + numOfItems;
	var clientTable = "<table>";

	//Iterate through the fabrics array and build the table.

	for (var i = beginIndex; i < endIndex;i++)
	{
		colNum++;

		//If this is the first column, start new row.
		if (colNum == 1)
		{
			clientTable += "<tr>";
		}


		clientTable += "<td class='" + cssClassTd + "'>";
		
		if (arrClients[i] != null)
		{
		    //Create links if this table is set to have image links.
		    if (arrClients[i].link != '')
		    {
		        clientTable += "<a href=" + arrClients[i].link + " target='_blank'>";
		    }
		    
			clientTable += "<span style='font-weight:bold;'>" + arrClients[i].name + "</span>";
			
			if (arrClients[i].link != '')
		    {
		        clientTable += "</a>";
		    }
		    
			clientTable += "<br/>" + arrClients[i].address;
			clientTable += "<br/>" + arrClients[i].phone;
			
		}
		else
		{
			clientTable += "&nbsp;<br/><br/><br/>";
		}	
			
		clientTable += "</td>";

		//If this is the last column, close row.
		if (colNum == numOfCols)
		{
			clientTable += "</tr>";
			colNum = 0;
		}
	}

	clientTable += "</table>";
	
	//Now place this html inside the content div tag.
	document.getElementById('divContent').innerHTML = clientTable;
	

}


//Build a table using the array of fabrics.
function buildBlindsTable()
{
	//Begin building table.
	var colNum = 0;
	var numOfItems = numOfCols * numOfRows;
	var beginIndex = numOfItems * currentPage;
	var endIndex = beginIndex + numOfItems;
	var blindTable = "<table>";

	//Iterate through the fabrics array and build the table.

	for (var i = beginIndex; i < endIndex;i++)
	{
		colNum++;

		//If this is the first column, start new row.
		if (colNum == 1)
		{
			blindTable += "<tr>";
		}


		blindTable += "<td class='" + cssClassTd + "'>";
		
		if (arrBlinds[i] != null)
		{
		    //Create links if this table is set to have image links.
		    if (hasLink == true && arrBlinds[i].link != '')
		    {
		        blindTable += "<a href=" + arrBlinds[i].link + ">";
		    }
		    
			//clientTable += "<img src='" + arrBlinds[i].image + "' class='" + cssClassImg + "'>";
			
			//Create the image link.
			blindTable += "<img id='imgFabric" + i + "' class='" + cssClassImg + "' src='" + arrBlinds[i].image + "'";
			
			//Create hover over events if this table is set to show Hover overs.
			if (showHoverWindow == true )
			{
			    blindTable += " onmouseover=showImage('" + arrBlinds[i].image + "',this," + i + ");";
			    blindTable += " onmouseout=removeImage('" + arrBlinds[i].image + "',this);";
			}
			
			blindTable += ">";
			
			if (hasLink == true && arrBlinds[i].link != '')
		    {
		        blindTable += "</a>";
		    }
		    
		    blindTable += "<br/><span style='font-weight:bold;'>" + arrBlinds[i].name + "</span>";
			blindTable += "<br/>" + arrBlinds[i].text;
			
		}
		else
		{
			blindTable += "&nbsp;";
		}	
			
		blindTable += "</td>";

		//If this is the last column, close row.
		if (colNum == numOfCols)
		{
			blindTable += "</tr>";
			colNum = 0;
		}
	}

	blindTable += "</table>";
	
	//Now place this html inside the content div tag.
	document.getElementById('divContent').innerHTML = blindTable;
	

}

//Build a table using the array of fabrics.
function buildFurnituresTable()
{
	//Begin building table.
	var colNum = 0;
	var numOfItems = numOfCols * numOfRows;
	var beginIndex = numOfItems * currentPage;
	var endIndex = beginIndex + numOfItems;
	var clientTable = "<table>";

	//Iterate through the fabrics array and build the table.

	for (var i = beginIndex; i < endIndex;i++)
	{
		colNum++;

		//If this is the first column, start new row.
		if (colNum == 1)
		{
			clientTable += "<tr>";
		}


		clientTable += "<td class='" + cssClassTd + "'>";
		
		if (arrFurnitures[i] != null)
		{
		    //Create links if this table is set to have image links.
		    if (hasLink == true)
		    {
		        clientTable += "<a href=" + arrFurnitures[i].link + " target='_blank'>";
		    }
		    
			clientTable += arrFurnitures[i].name;
			
			if (hasLink == true)
		    {
		        clientTable += "</a>";
		    }
		}
		else
		{
			clientTable += "&nbsp;";
		}	
			
		clientTable += "</td>";

		//If this is the last column, close row.
		if (colNum == numOfCols)
		{
			clientTable += "</tr>";
			colNum = 0;
		}
	}

	clientTable += "</table>";
	
	//Now place this html inside the content div tag.
	document.getElementById('divContent').innerHTML = clientTable;
	

}

// creates the element (div) to hold Narrative on mouseOver of narrative image.
function showImage(imgURL,e,index)
{
    var d, text, narrText, stemElement;
	var HorzOffset = 0;
    var VertOffset = -200;
    var objDiv;
    var intLeft = 0;
    var intTop = 0;
    var objBase = document.getElementById("imgFabric" + index);
    var intBaseTop = objBase.offsetTop;
    var intBaseLeft = objBase.offsetLeft;
    var scrollbarWidth = 25;
    var Parent = objBase.offsetParent;
    
	var d, img, text, iScrollAmtY, iScrollAmtX, narrText;
	narrText = '';
		
	d = document.createElement("<DIV id='narrElement' class='stemHover'>");
	
	img = document.createElement("<img width='200px' src='" + imgURL + "'>");

		text = document.createTextNode(unescape(narrText));
		d.appendChild(text);
		d.appendChild(img);
		document.body.appendChild(d);
		
		//Set the position of the DIV tag
    objDiv = document.getElementById('narrElement');
    
    while (Parent) { 
        intBaseTop += Parent.offsetTop;
        intBaseLeft += Parent.offsetLeft;
        Parent = Parent.offsetParent;
    }
    
    if (objDiv) {
        intTop = parseInt(parseInt(intBaseTop) + parseInt(objBase.offsetHeight) + parseInt(VertOffset));
        intLeft = parseInt(parseInt(intBaseLeft) + parseInt(objBase.offsetWidth) + parseInt(HorzOffset));
        
        //Check if off screen vertically and fix
        if ((intTop + objDiv.offsetHeight) > (document.documentElement.scrollHeight - scrollbarWidth)) {
            intTop = intBaseTop - objDiv.offsetHeight - VertOffset;
        }

        //Check if off screen horizontally and fix
        if ((intLeft + objDiv.offsetWidth) > (document.documentElement.scrollWidth - scrollbarWidth)) {
            intLeft = parseInt(parseInt(intBaseLeft) + parseInt(objBase.offsetWidth) - parseInt(objDiv.offsetWidth));
        }
        
        objDiv.style.left = intLeft + "px";
        objDiv.style.top = intTop + "px";
        objDiv.style.position = 'absolute';
        objDiv.style.visibility = 'visible';
        objDiv.style.zIndex = 100000000000;

    }
	
}

// destroys div element holding narrative.
function removeImage(){
	// have to make sure the element exists before you try to remove it
	if (document.body.lastChild.id == "narrElement") {
		document.body.removeChild(document.getElementById('narrElement'));	
	}
}

// sets the current top menu
function setTopMenu(){
	if (document.getElementById("menu_" + currentPageName))
	{
		document.getElementById("menu_" + currentPageName).style.background = '#3B3830';
	}
}


</script>
