// JavaScript Document
var ldImg = new Image();
ldingImg.src = "images/loadingimg.jpg";
var spacerImg = new Image();
spacerImg.src = "images/spacer.gif";

function newImgOnLoad(){
	alert( "image completed loading");
}
function loadSpacer(){
	document.images["BIGIMAGE"].src = spacerImg.src;
}
function loadProduct(id){		
	//get product Item no.	
	for(i in products){
		if(products[i].id == id){			
			id = i;
		};
	}	
	
	var im = document.images["BIGIMAGE"];
	var url;
	im.width = products[id].width;
	im.height = products[id].height;		
	//loadSpacer();
	
	im.src  =  products[id].imgpath; //'images/sofasets/setty-milano-big.jpg';
	changeSpanText("ITEMTITLE", products[id].name.toUpperCase());
	changeSpanText("ITEMDESC", products[id].description);	
	emptyNode("viewOptions");	
	if(products[id].bigpic){
		switch(products[id].bigpic.toLowerCase()){		
			case 'zoom':
				url = "zoom/zoomitem.php?itemid=" + products[id].id + "&itemname=" + products[id].name.toUpperCase() + "&cat=" + category + "&";
				appendTextLink("viewOptions", "Zoom Product", url , "", "_self");
				break;
			case 'enlarge':
				appendTextLink("viewOptions", "View Enlarged Image", "enlargeImage.php", "", "_blank");
				break;
			case 'nobig':
				break;
		}
	}
	if(products[id].items){
		if(products[id].bigpic && products[id].bigpic != "undefined" && products[id].bigpic != "nobig") { appendText("viewoptions", " | "); }
		url = "showitems.php?pageid=" + products[id].id + "&";
		appendTextLink("viewOptions", "Product Details", url, "", "_self");
	}
	window.location = "#TOP";
				 
}
function changeSpanText(id, st) {
	var tg = document.getElementById(id);
	tg.firstChild.nodeValue=st;
}
function emptyNode(id){
	id = document.getElementById(id);
	while(id.firstChild){
		id.removeChild(id.firstChild);
	}
}
function appendTextLink(id, txt, href, title, tg){
	if(!tg){ tg = "_self"; }
	if(!title){ title = ""; }
	var ah = document.createElement('a');
	ah.setAttribute('href', href);
	ah.setAttribute('title', title);
	ah.setAttribute('target', tg);
 	ah.appendChild(document.createTextNode(txt));	
	document.getElementById(id).appendChild(ah);

}
function appendText(id, txt){
	document.getElementById(id).appendChild(document.createTextNode(txt));
}
