// JavaScript Document

// need these to prevent error messages relating to pop-up window functions below

bigpicWindow = "";
descripWindow="";

// preload images to cache for rollovers

if (document.images) {
	home_off=new Image();
	home_off.src="images/home3_off.gif";
	home_on=new Image();
	home_on.src="images/home3_on.gif";
	about_off = new Image();
	about_off.src = "images/about3_off.gif";
	about_on = new Image();
	about_on.src = "images/about3_on.gif";
	products_off =new Image();
	products_off.src="images/products3_off.gif";
	products_on=new Image();
	products_on.src="images/products3_on.gif";
	contact_off=new Image();
	contact_off.src="images/contact3_off.gif";
	contact_on=new Image();
	contact_on.src="images/contact3_on.gif";
}
else {

// need these to prevent error messages in browsers which do not understand document.images

	home_off="";
	home_on="";
	about_off = "";
	about_on="";
	products_off="";
	products_on="";
	contact_off="";
	contact_on="";
	document.home="";
	document.about = "";
	document.products="";
	document.contact="";
}	

// controls the image rollovers on the navigation bar across the top of the page
// triggered by the onMouseover and onMouseout eventhandlers in the links

function swapImg(imgName,imgState) {
	document[imgName].src=eval(imgState + ".src");
}


// controls the pop-up window which displays larger versions of thumbnail images
// product thumbnail images are links and this function is triggered by clicking on them
// the link passes a variable to the function which is used to put the correct image in a dynamically-generated document 

function bigPicWin(picName) {

	// close any other windows which may be already open

	closeAllWins();

	// get the item number by trimming DCP_  from the picName variable passed by the link
	
	itemNum = picName.replace("DCP_","");
	
	// in case person maintaining the site forgot to change xxxx to a valid Item#, provide an alert 
	// instead of opening a pop-up with no image
	
	if (itemNum == "xxxx") {
		
			alert("We're sorry, but a larger image of this item is not currently available.");
		}
		else {

	bigpicWindow = window.open("prodimgs.html", "Products", "resizable=yes,width=373,height=440,screenX=10,left=10,screenY=10,top=10");
	bigpicWindow.document.open();
	bigpicWindow.document.write('<html><head><title>Product Images</title></head>');
	bigpicWindow.document.write('<body bgcolor="#336633" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">');
	bigpicWindow.document.write('<div align="center"><img src="products/' + picName + '.jpg" vspace="5"><br>');
	bigpicWindow.document.write('<font face="Arial" color="#ffffff"><b>Item# ' + itemNum + '</b></font></div>');
	bigpicWindow.document.write('</body></html>');
	bigpicWindow.document.close();
	bigpicWindow.focus();
	
	}
} 

// controls the pop-up window which displays detailed product description, triggered by item# links
// the links pass a page name to this function - a separate HTML page  must be created for each product

function descripWin(pageName) {

	// close any windows that may already by open
	
	closeAllWins();

	// add the file extension to the pageName variable passed by the link
	pageName = pageName + ".html";
	descripWindow = window.open(pageName, "Products", "scrollbars=yes,menubar=yes,resizable=yes,width=418,height=420,screenX=10,left=10,screenY=10,top=10");
	descripWindow.focus();
}

// closes all windows which may be open -  called from window opener functions or onUnload eventhandler in body tag
// this function makes sure the visitor is not annoyed by a clutter of pop-ups left open when he or she leaves the site

function closeAllWins() {
	if (bigpicWindow && !bigpicWindow.closed) {
		bigpicWindow.close();
	}
	if (descripWindow && !descripWindow.closed) {
		descripWindow.close();
	}
}
