function changeListingColour(name, type, colour, otherColours, currency) {
	// Change buy button.
	document.getElementById(name+"_buy").onclick = function(){ addToCart(name+colour, currency); };
	
	// Change the image.
	document.getElementById(name+"_thumb_img").src = "templates/" + type + "/" + name + "/" + colour + "/thumb/" + name + colour + "_1.gif";
	
	// Change the title.
	document.getElementById(name+"_title").innerHTML = name+colour;
	
	// Change the link.
	document.getElementById(name+"_title").href = "web-preview.php?id=" + name + "&colour=" + colour;
	
	// Change colour links.
	for (var i=0; i<otherColours.length; i++) {
		var link = document.getElementById(name+otherColours[i]+"_colour_link");
		
		if (colour == otherColours[i]) {
			link.innerHTML = "<span class=\"selected-available-colour\">"+convertColourCode(colour).toLowerCase()+"</span>";
		} else {
			var arr = "new Array(";
			for (var j=0; j<otherColours.length; j++) {
				if (j > 0) arr += ",";
				arr += "'" + otherColours[j] + "'";
			}
			arr += ")";
			link.innerHTML = "<a href=\"javascript:changeListingColour('"+name+"','"+type+"','"+otherColours[i]+"', "+arr+", '"+currency+"');\">"+convertColourCode(otherColours[i]).toLowerCase()+"</a>";
		}
	}
	
	// Change layout links.
	if (type == "WEB") {
		
	}
}

function changePreviewColour(name, type, colour, otherColours, currency, noLayouts) {
	// Change buy button.
	document.getElementById(name+"_buy").onclick = function(){ addToCart(name+colour, currency); };

	// Change the image.
	//document.getElementById(name+"_preview_img").src = "templates/" + type + "/" + name + "/" + colour + "/preview/" + name + colour + "_1.jpg";

	// Change the title.
	document.getElementById("page_heading").innerHTML = name+colour;
	
	// Change colour links.
	for (var i=0; i<otherColours.length; i++) {
		var link = document.getElementById(name+otherColours[i]+"_colour_link");
		
		if (colour == otherColours[i]) {
			link.innerHTML = "<span class=\"selected-available-colour\">"+convertColourCode(colour).toLowerCase()+"</span>";
		} else {
			var arr = "new Array(";
			for (var j=0; j<otherColours.length; j++) {
				if (j > 0) arr += ",";
				arr += "'" + otherColours[j] + "'";
			}
			arr += ")";
			link.innerHTML = "<a href=\"javascript:changePreviewColour('"+name+"','"+type+"','"+otherColours[i]+"', "+arr+", '"+currency+"', "+noLayouts+");\">"+convertColourCode(otherColours[i]).toLowerCase()+"</a>";
		}
	}
	
	// Change swf image if there is one.
	if (document.getElementById("flash_object_param") != null) {
		// For IE.
		document.getElementById("flash_object_param").value = "templates/" + type + "/" + name + "/" + colour + "/" + name + ".swf";
	}
	if (document.getElementById("flash_embed") != null) {
		// For all sensible browsers.
		document.getElementById("flash_embed").src = "templates/" + type + "/" + name + "/" + colour + "/" + name + ".swf";
	}
	
	// Change the colour in next/back links.
	document.getElementById("layout_back").innerHTML = "<a href=\"javascript: changeLayoutBack('"+type+"','"+name+"','"+colour+"',"+noLayouts+");\">&lt; back</a>";
	document.getElementById("layout_next").innerHTML = "<a href=\"javascript: changeLayoutNext('"+type+"','"+name+"','"+colour+"',"+noLayouts+");\">next &gt;</a>";
	
	// Reset the layout slideshow.
	changeLayout(type, name, colour, currentLayout, noLayouts);
}

function convertColourCode(colourCode) {
	switch(colourCode) {
		case "RD":
			return "Red";
		case "GR":
			return "Green";
		case "BL":
			return "Blue";
		case "MA":
			return "Magenta";
		case "GRAY":
			return "Gray";
		case "BR":
			return "Brown";
		case "BK":
			return "Black";
		case "WH":
			return "White";
		case "OR":
			return "Orange";
		case "CY":
			return "Cyan";
		case "PU":
			return "Purple";
		case "YL":
			return "Yellow";
		default:
			return "";
	}
}