/*
	Script: fabrics.js
	
	Copyright: Fishnet NewMedia (c) 2005
	
	Create: 12.06.05
	
	Version: 1.0
	
	Compatibility: JavaScript 1.2
	
	Changes: none
*/

var swatches = null;

// create an object literal to be used as an 
// associative array for storing image objects
var image_cache = {};
image_cache["spacer"] = imageLoad("/images/spacer.gif");
for (var i = 1; i <= swatch_total; i++) {
	var num = i < 10 ? "0" + i.toString() : i;
	image_cache["color_name_" + num] = imageLoad(swatch_path + "color_name_" + num + ".gif");
}

function imageLoad(filename) {
    // create a new image object and returns object to caller
    var img = new Image();
    img.src = filename;
    return img;
}

function initSwatch() {
	// create a reference to all swatches
	swatches = document.getElementsByName("swatch");
	// set the mouseover event handler for all swatches
	for (var i = 0; swatches[i]; i++) {
		swatches[i].onmouseover = mouseOverSwatch;
		swatches[i].onmouseout = mouseOutSwatch;
	}
}

function mouseOverSwatch() {
	// change the swatch border
	this.className = "box_hover";
	// swap the color name image
	var regx = /color_swatch_(\d+)\.gif/;
	var match = null;
	match = regx.exec(this.src);
	document.color_name.src = image_cache["color_name_" + match[1]].src;
}

function mouseOutSwatch() {
	// change the swatch border
	this.className = "box";
}