// JavaScript to show & hide text
// used for artwork titles

var baseopacityImg=70;
var baseopacityText=10;
var highlightingText;
var highlightingImg;

function swap_item(item_id, item_title, item_price, item_width, item_height, item_depth, item_note, units, item_medium, image_list) {
//function swap_item(itemArray, picArray) {

//  Initialize variables	
	cnt = 0;
	var i;
	preLoad = new Array();
	caption = new String();

//	alert('imageDir='+imageDir);
//	alert('image_list: '+image_list);
//	alert('item_title: '+item_title);
//	Split the item list into an array
	picArray = image_list.split(" ");
	max = picArray.length;
//	alert("max="+max); // preLoad[i].src);
	for (i=0; i<max; i++) {
		preLoad[i] = new Image();
		preLoad[i].src = imageDir+picArray[i];
	}
//	Display the first image of the series 
	document.images.SlideShow.src = preLoad[0].src;
//	changeImages('SlideShow', preLoad[0].src);
//	MM_swapImage('SlideShow', '', item_image, 1)
//	Display the item caption

	display_price = ( item_price==0 ) ? "NFS" : item_price;
	caption = item_title+"<br />"+item_medium.small()+" - "+item_width.small() +
				" x "+item_height.small()+" x "+item_depth.small()+" "+units+"<br />"+ ( display_price.match(/[^0-9]/) ? "" : "$")+display_price.small() +(item_note.localeCompare("") ? " - " + item_note.small() : "" );

//	caption = itemArray[0]+"<br />"+itemArray[1].small()+" - "+itemArray[2].small()+"W x "+itemArray[3]+"H x "+itemArray[4]+"D<br />"+ ( itemArray[5].match(/[^0-9]/) ? "" : "$")+itemArray[5].small() +(itemArray[6].localeCompare("") ? " - " + itemArray[6].small() : "" );
//	alert('caption: '+caption);
	showtext(caption);

}

function showtext(thetext){
	if (!document.getElementById)
		return
	textcontainerobj=document.getElementById("imagetitle")
	browserdetect = textcontainerobj.filters? "ie" : typeof textcontainerobj.style.MozOpacity=="string"? "mozilla" : ""
	document.getElementById("imagetitle").innerHTML=thetext;
	instantsetText(baseopacityText);
//	alert(document.getElementById("imagetitle").innerHTML);
	// setInterval is a built-in Javascript function which executes the first argument
	// for the duration of the second argument (milliseconds).
	// It returns a unique interval ID which can be used to clear the interval
	highlightingText=setInterval("gradualfadeText(textcontainerobj)",50)
}

function hidetext(){
	cleartimerText()
	instantsetText(baseopacityText)
}


function fadein(which2){
	imgobj=which2
	browserdetect = which2.filters? "ie" : typeof which2.style.MozOpacity=="string"? "mozilla" : "" 
	instantsetImg(baseopacityImg)
	// setInterval is a built-in Javascript function which executes the first argument
	// for the duration of the second argument (milliseconds).
	// It returns a unique interval ID which can be used to clear the interval
	highlightingImg=setInterval("gradualfadeImg(imgobj)",50)
}

function fadeout(which2){
	cleartimerImg()
	instantsetImg(baseopacityImg)
}


function instantsetText(degree){
	if (browserdetect=="mozilla")
		textcontainerobj.style.MozOpacity=degree/100
	else if (browserdetect=="ie")
		textcontainerobj.filters.alpha.opacity=degree
	else if (document.getElementById && baseopacityText==0)
		document.getElementById("imagetitle").innerHTML=""
}


function instantsetImg(degree){
	if (browserdetect=="mozilla")
		imgobj.style.MozOpacity=degree/100
	else if (browserdetect=="ie")
		imgobj.filters.alpha.opacity=degree
}

function cleartimerText(){
	if (window.highlightingText) clearInterval(highlightingText)
}

function cleartimerImg(){
	if (window.highlightingImg) clearInterval(highlightingImg)
}

function gradualfadeText(cur2){
	if (browserdetect=="mozilla" && cur2.style.MozOpacity<1)
		cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.1, 0.99)
	else if (browserdetect=="ie" && cur2.filters.alpha.opacity<100)
		cur2.filters.alpha.opacity+=10
	else if (window.highlightingText)
		clearInterval(highlightingText)
}


function gradualfadeImg(cur2){
	if (browserdetect=="mozilla" && cur2.style.MozOpacity<1)
		cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.1, 0.99)
	else if (browserdetect=="ie" && cur2.filters.alpha.opacity<100)
		cur2.filters.alpha.opacity+=10
	else if (window.highlightingImg)
		clearInterval(highlightingImg)
}

/* */

function MM_swapImgRestore() { //v3.0 
	var i,x,a=document.MM_sr;
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; 
	}

function MM_preloadImages() { //v3.0
	var d=document; 
	if(d.images) { 
		if(!d.MM_p) d.MM_p=new Array(); 
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
		for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0) {
			d.MM_p[j]=new Image;
			d.MM_p[j++].src=a[i];
		}
	}
}

function MM_findObj(n, d) { //v3.0
	var p,i,x; 
	if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all)
		x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++)
		x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
		x=MM_findObj(n,d.layers[i].document);
	return x;
}

function MM_swapImage() { //v3.0 
	var i,j=0,x,a=MM_swapImage.arguments;
	document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
		if ((x=MM_findObj(a[i]))!=null) {
			document.MM_sr[j++]=x;
			if(!x.oSrc)
				x.oSrc=x.src; 
			x.src=a[i+2];
		}
}
