// JavaScript Document

// initialise counter 

x = 1;

// need these to prevent error messages relating to pop-up window functions below

bigpicWindow = "";
descripWindow="";
infoWindow="";

// preload images to cache for rollovers

if (document.images) {
	about_off = new Image();
	about_off.src = "images/about_off.jpg";
	about_on = new Image();
	about_on.src = "images/about_on.jpg";
	products_off =new Image();
	products_off.src="images/products_off.jpg";
	products_on=new Image();
	products_on.src="images/products_on.jpg";
	contact_off=new Image();
	contact_off.src="images/contact_off.jpg";
	contact_on=new Image();
	contact_on.src="images/contact_on.jpg";
	home_02a=new Image();
	home_02a.src = "images/home4_02a.jpg";
	home_06a=new Image();
	home_06a.src="images/home4_06a.jpg";
	girl1=new Image();
	girl1.src = "images/girl4.jpg";
	home_11=new Image();
	home_11.src = "images/home_11.jpg";
	home_08a=new Image();
	home_08a.src="images/home_08a.jpg";
}
else {

// need these to prevent error messages in browsers which do not understand document.images

	about_off = "";
	about_on="";
	products_off="";
	products_on="";
	contact_off="";
	contact_on="";
	home_02a="";
	home_06a="";
	girl1="";
	home_08a="";
	home_11="";
	document.about = "";
	document.products="";
	document.contact="";
	document.home_02="";
	document.home_06="";
	document.home_07="";
	document.home_08="";
	document.thanksgiving_left2="";
}	

// controls the image changes which occur automatically after the page loads
// triggered by the onLoad eventhandler in the body tag

function showNext() {

	if (x == 1) {

		// defines the first set of automatic image changes

		document.home_02.src = home_02a.src;
		document.home_06.src = home_06a.src;
		document.home_07.src = girl1.src;
		document.home_08.src = home_08a.src;
		document.thanksgiving_left2.src = home_11.src;
		
		x = 0;

		// sets the delay between the first set of automatic image changes and the next

		setTimeout("showNext();",1500);		
	}
	else {
		// defines the second set of automatic image changes

		document.about.src = about_off.src;
		document.products.src = products_off.src;
		document.contact.src = contact_off.src;
	}	
}

// 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 someone maintaining the site forgets to change xxxx to a valid Item#, show an alert
	// instead of a pop-up page without an 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 other windows which may be already 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=430,screenX=160,left=160,screenY=10,top=10");
	descripWindow.focus();
}

// opens new window for RCI web site if visitor clicks on link in design tagline

function newWin(pageName) {

	// close any other windows which may be already open

	closeAllWins();

	infoWindow= window.open(pageName, "Information", "scrollbars=yes,menubar=yes,toolbar=yes,location=yes,status=yes,resizable=yes,width=418,height=360,screenX=10,left=10,screenY=10,top=10");
	infoWindow.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();
	}
	if (infoWindow && !infoWindow.closed) {
		infoWindow.close();
	}
}
	

// this next function is here temporarily to show Steve the different types of images available for the home page
// this will be removed before the site is officially published

function chgImg(showImg) {
	document.home_02.src="images/home4_02.jpg";
	document.home_06.src="images/home4_06.jpg";
	document.home_08.src="images/giftmssg.jpg";
	document.home_07.src= "images/" + showImg + ".jpg";
}
