var chipCount = 0;

function rollC(typ, num, name, returnURL) {
	var d = document;
	var inScrapbook = 1;
	var sharedImagePath = "swatch/";
	var imagePath = "images/";
	var colourPath = "swatch/" + num + "_31.jpg";
	var colourScissorsPath = "common/small/" + num + "_31.jpg";
	var returnPath = escape((returnURL)?returnURL:location.href);
	var addLibLink = "xx";
	var colLink = returnURL;
	var colourFilename=colourScissorsPath;
	chipCount++;
	if (inScrapbook)
		colourFilename=colourPath;

	if (typ==1 || typ==3) {		


	var staticContent = "<div id=\"ci[num]\" class=\"swatchClassStyle\">" +
									"<a href=\"#\" onClick=\"changeColor('[ColourFilename]','[colName]')\" onmouseover=\"swatchOn('ci[num]','ciImg[num]','ciRO[num]','ciRoTop[num]','ciRoLeft[num]','ciRoRight[num]');\" onfocus=\"swatchOn('ci[num]','ciImg[num]','ciRO[num]','ciRoTop[num]','ciRoLeft[num]','ciRoRight[num]');\">" + 
										"<img src=\"[ColourFilename]\" width=\"72\" height=\"31\" border=\"0\" alt=\"[colName]\" id=\"ciImg[num]\" />" + 
									"</a>" + 
								"</div>";
								

	var dynamicContent = "<div id=\"ciRO[num]\"" + ROClass + "\">" +
									"<table id=\"ciRoTop[num]\" width=\"92\" cellspacing=\"0\" cellpadding=\"1\" border=\"0\" bgcolor=\"#000066\">" +
										"<tr>" +
											"<td valign=\"top\"><table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" bgcolor=\"#ffffff\">" +
													"<tr valign=\"top\" >" +
														"<td rowspan=\"7\" onmouseout=\"swatchOff();\"><img id=\"ciRoLeft[num]\" src=\"[sharedImagePath]1pix.gif\" width=\"9\" height=\"1\" border=\"0\" alt=\"\" /></td>" +
														"<td height=\"9\" width=\"100%\" onmouseout=\"swatchOff();\"><img src=\"[sharedImagePath]1pix.gif\" width=\"1\" height=\"9\" border=\"0\" alt=\"\" /></td>" +
														"<td rowspan=\"7\" onmouseout=\"swatchOff();\"><img id=\"ciRoRight[num]\" src=\"[sharedImagePath]1pix.gif\" width=\"9\" height=\"1\" border=\"0\" alt=\"\" /></td>" +
													"</tr>" 

        if (typ==1) dynamicContent += "<tr><td><img src=\"[ColourFilename]\" width=\"72\" height=\"31\" border=\"0\" alt=\"\" /></td></tr>";
        if (typ==3) dynamicContent += "<tr><td><a href=\"#\" onClick=\"changeColor('[ColourFilename]','[colName]')\"><img src=\"[ColourFilename]\" width=\"72\" height=\"31\" border=\"0\" alt=\"\" /></a></td></tr>";


  if (typ==1) 	dynamicContent += "<tr><td class=\"tXSmall\">[colName]<br /></td></tr>" 
  if (typ==3) 	dynamicContent += "<tr><td class=\"colourlink\"><a href=\"#\" onClick=\"changeColor('[ColourFilename]','[colName]')\">[colName]</a><br /></td></tr>" 

	dynamicContent += "<tr></tr><tr><td height=\"9\" onmouseout=\"swatchOff();\"><img src=\"[sharedImagePath]1pix.gif\" width=\"1\" height=\"9\" border=\"0\" alt=\"\" /></td></tr>" +
		"</table></td>" +
		"</tr>" +
		"</table>" +
		"</div>";

	}

	

	
	else {



	var addToSchemesHtml = "";
	var addToLibHtml = "";

	var staticContent = 
	"<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"72\">\n"+
	"<tr bgcolor=\"#e0e0dd\">\n"+
	"<td width=\"1\" rowspan=\"2\"><img src=\"[sharedImagePath]1pix.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" /></td>\n"+
	"<td width=\"100%\" height=\"1\"><img src=\"[sharedImagePath]1pix.gif\" width=\"70\" height=\"1\" border=\"0\" alt=\"\" /></td>\n"+
	"<td width=\"1\" rowspan=\"2\"><img src=\"[sharedImagePath]1pix.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" /></td>\n"+
	"</tr>\n"+
	"<tr><td colspan=\"3\" height=\"8\"></td></tr>\n"+
	"</table>\n"+
	"<div id=\"ci[num]\" class=\"swatchClassStyle\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"72\">\n<tr>\n"



	if (typ==2) staticContent += "<td colspan=\"5\"><img \n"+"src=\"[ColourFilename]\" width=\"72\" height=\"31\" border=\"0\" alt=\"[colName]\" id=\"ciImg[num]\" /></td>\n"
	if (typ==4) staticContent += "<td colspan=\"5\"><a href=\"#\" onClick=\"changeColor('[ColourFilename]','[colName]')\"><img \n"+"src=\"[ColourFilename]\" width=\"72\" height=\"31\" border=\"0\" alt=\"[colName]\" id=\"ciImg[num]\" /></a></td>\n"

	staticContent += "</tr>\n"+
	"<tr>\n"+
	"<td width=\"1\" rowspan=\"3\" bgcolor=\"#e0e0dd\"><img src=\"[sharedImagePath]1pix.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" /></td>\n"+
	"<td width=\"3\" rowspan=\"3\"><img src=\"[sharedImagePath]1pix.gif\" width=\"3\" height=\"1\" border=\"0\" alt=\"\" /></td>\n"+
	"<td width=\"64\" height=\"3\"></td>\n"+
	"<td width=\"3\" rowspan=\"3\"><img src=\"[sharedImagePath]1pix.gif\" width=\"3\" height=\"1\" border=\"0\" alt=\"\" /></td>\n"+
	"<td width=\"1\" rowspan=\"3\" bgcolor=\"#e0e0dd\"><img src=\"[sharedImagePath]1pix.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" /></td>\n"+
	"</tr>\n"+
	"<tr valign=\"top\">\n"
	
	if (typ==2) staticContent += "<td height=\"43\" class=\"tXSmall\">[colName]</td>\n"
	if (typ==4) staticContent += "<td height=\"43\" class=\"colourlink\"><a href=\"[colLink]\">[colName]</a></td>\n"


	staticContent += "</tr>\n"+
	"<tr><td height=\"8\"></td></tr>\n"+
	"<tr bgcolor=\"#e0e0dd\"><td colspan=\"5\" height=\"1\"><img src=\"[sharedImagePath]1pix.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" /></td></tr>\n"+
	"</table></div>\n";
	
	
	var dynamicContent = "";

	}
	var fullString = staticContent + dynamicContent;
	
	
	// workaround for NS
	if (document.layers) fullString = "<a href=\"#\" onClick=\"changeColor('[ColourFilename]','[colname]')\" onmouseover=\"swatchOn('ci[num]','ciImg[num]','ciRO[num]','ciRoTop[num]','ciRoLeft[num]','ciRoRight[num]');\" onfocus=\"swatchOn('ci[num]','ciImg[num]','ciRO[num]','ciRoTop[num]','ciRoLeft[num]','ciRoRight[num]');\">" + 
										"<img src=\"[ColourFilename]\" width=\"72\" height=\"31\" border=\"0\" alt=\"[colName]\" id=\"ciImg[num]\" />" + 
									"</a>" +
									"<br /><a href=\"[addLibLink]\" class=\"collect\">Add to scrapbook</a>";
	
	fullString = fullString.replace(/\[num\]/g, num + "_" + chipCount);
	fullString = fullString.replace(/\[sharedImagePath\]/g, sharedImagePath);
	fullString = fullString.replace(/\[ColourFilename\]/g, colourFilename);
	fullString = fullString.replace(/\[colName\]/g, name);
	fullString = fullString.replace(/\[colLink\]/g, colLink);
	fullString = fullString.replace(/\[addLibLink\]/g, addLibLink);
	

	d.write(fullString);

}

