/* takada.js
 *
 * known bugs:
 *	1.	ie mac does not show the correct image when opening an artist page with an imageNum specified in the URL
 *	2.	win ie pops in the original image before showing the correct image when opening an artist page with an imageNum specified
 *		in the URL
 */

/* preloadImages
 * preload images based on a given image's src. the prototype is:
 *		preloadImages( elementID, image1, image2, image3, ... )
 * where each image is found in the same path as the src attribute for the image element with the given elementID
 */
function preloadImages()
{
	var args = preloadImages.arguments;
	var theElem = args[0];
	var elem = document.getElementById(theElem);
	var path = elem.src;
	path = path.replace(/[^\/]+\.(jpg|gif|png)$/,'');	// peel off the trailing filename, e.g., filename.gif or filename.jpg

	var len = args.length-1;
	var imageArray = new Array(len);
	for(var i=0; i<len; i++)
	{
		imageArray[i] = new Image;
		imageArray[i].src = path+args[i+1];
	}	
}

function preloadLocalImages()
{
	// hack: allow other images to be preloaded by setting the localPreloadImages variable.
	if ( localPreloadImages )
	{
		len = localPreloadImages.length;
		document.imageArray2 = new Array(len);
		for(var i=0; i<len; i++)
		{
			document.imageArray2[i] = new Image;
			document.imageArray2[i].src = localPreloadImages[i];
		}
	}
}


/*	swapImage
 *	used for the artist list.
 *	Pass image name and source values by calling the function elsewhere
 *	Example: swapImage(myImageName, images/myimage.gif)
 */
function swapImage(imageName, imageSrc)
{
	if (document.images)
	{
		var path = document.images[imageName].src;
		path = path.replace(/[^\/]+\.(jpg|gif|png)$/,'');	// peel off the trailing filename, e.g., filename.gif or filename.jpg
		if (imageSrc != "none")
  		{
    		document.images[imageName].src = path + imageSrc;     		
    		document.images[imageName].className = "image";
  		}
  		else
  		{
  			document.images[imageName].src = path + "transparent_thumb.gif";
    		document.images[imageName].className = "imagenoborder";
  		}
  	}
}

