var chipCount = 0;

function rollC(typ, num, name, returnURL) {
	var d = document;
	var d = document;
		var inScrapbook = 1;
		var sharedImagePath = "shared/";
		var imagePath = "images/";
		var colourPath = "swatch/" + num + ".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 || typ==5) {	
	var staticContent = "<div id=\"ci[num]\" class=\"swatchClassStyle\">" +
									"<a href=\"[colLink]\" 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=\"More about [colName]\" id=\"ciImg[num]\" />" + 
									"</a>" + 
								"</div>";
								
	var addToLibHtml = (!inScrapbook && typ !=5 )?"<tr><td height=\"3\"></td></tr>" +
							"<tr>" +
								"<td class=\"collect\"><a href=\"[addLibLink]\" onmouseover=\"roll('arrow', 'shared/', '_1','_add[num]')\" onmouseout=\"roll('arrow', 'shared/', '_0','_add[num]')\">Add to my scrapbook&nbsp;<img src=\"[sharedImagePath]arrow_0.gif\" width=\"7\" height=\"7\" border=\"0\" alt=\"\" name=\"arrow_add[num]\" /></a></td>" +
							"</tr>":"";
	var addToSchemesHtml = 	(typ==1 )?
							"<td class=\"collect\"><a href=\"[colLink]\" onmouseover=\"roll(this)\" onmouseout=\"roll(this)\">Nézze meg a színösszeállításokat&nbsp;<img src=\"shared/arrow_0.gif\" width=\"7\" height=\"7\" border=\"0\" alt=\"\" name=\"arrow_info[num]\" /></a></td>"
							:"";

	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>" +
													"<tr><td><img src=\"[ColourFilename]\" width=\"72\" height=\"31\" border=\"0\" alt=\"\" /></td></tr>" +	
													"<tr><td class=\"cName\">[colName]<br /></td></tr>" +
													"<tr>" +
														addToSchemesHtml + 
													"</tr>" +
													addToLibHtml +
													"<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 = (typ==2)?
	"<td class=\"collect\"><a \n"+
	"href=\"[colLink]\" onmouseover=\"roll(this)\" onmouseout=\"roll(this)\">Nézze meg a színösszeállításokat!&nbsp;<img \n"+
	"src=\"[sharedImagePath]arrow_0.gif\" width=\"7\" height=\"7\" border=\"0\" alt=\"\" name=\"arrow_info[num]\" /></a>\n"+
	"</td></tr><tr><td height=\"3\"></td>":"";
	
	var addToLibHtml = (!inScrapbook)?
	"<td class=\"collect\"><a \n"+
	"href=\"[addLibLink]\" onmouseover=\"roll(this)\">Add to my scrapbook&nbsp;<img \n"+
	"src=\"shared\arrow_0.gif\" width=\"7\" height=\"7\" border=\"0\" alt=\"\" name=\"arrow_add[num]\" /></a>\n"+
	"</td>\n":"";

	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"+
	"<td colspan=\"5\"><a href=\"[colLink]\" onmouseover=\"swatchOn('ci[num]','ciImg[num]','ciRO[num]','ciRoTop[num]','ciRoLeft[num]','ciRoRight[num]');\"><img \n"+
	"src=\"[ColourFilename]\" width=\"72\" height=\"31\" border=\"0\" alt=\"More about [colName]\" id=\"ciImg[num]\" /></a></td>\n"+
	"</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"+
	"<td height=\"43\" class=\"tXSmall\">[colName]</td>\n"+
	"</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 = 
	"<div id=\"ciRO[num]\"" + ROClass + "\">\n" +
	"<table id=\"ciRoTop[num]\" width=\"92\" cellspacing=\"0\" cellpadding=\"1\" border=\"0\" bgcolor=\"#000066\">\n"+
	"<tr>\n"+
	"<td valign=\"top\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" bgcolor=\"#ffffff\">\n"+
	"<tr valign=\"top\" >\n"+
	"<td rowspan=\"7\" onmouseout=\"swatchOff();\"><img id=\"ciRoLeft[num]\" src=\"[sharedImagePath]1pix.gif\" width=\"9\" height=\"1\" border=\"0\" alt=\"\" /></td>\n"+
	"<td height=\"9\" width=\"100%\" onmouseout=\"swatchOff();\"><img src=\"[sharedImagePath]1pix.gif\" width=\"1\" height=\"9\" border=\"0\" alt=\"\" /></td>\n"+
	"<td rowspan=\"7\" onmouseout=\"swatchOff();\"><img id=\"ciRoRight[num]\" src=\"[sharedImagePath]1pix.gif\" width=\"9\" height=\"1\" border=\"0\" alt=\"\" /></td>\n"+
	"</tr>\n"+
	"<tr><td><img src=\"[ColourFilename]\" width=\"72\" height=\"31\" border=\"0\" alt=\"\" /></td></tr>\n"+
	"<tr><td class=\"cName\">[colName]<br /></td></tr><tr>\n" +
	addToSchemesHtml +
	"</tr><tr>\n"+
	addToLibHtml +
	"</tr>\n" +
	"<tr><td height=\"9\" onmouseout=\"swatchOff();\"><img src=\"[sharedImagePath]1pix.gif\" width=\"1\" height=\"9\" border=\"0\" alt=\"\" /></td></tr>\n"+
	"</table></td>\n"+
	"</tr>\n"+
	"</table>\n"+
	"</div><!-- END: Rollover Layer -->\n";
	}
	
	if (typ==1 || typ==2) {
		var fullString = staticContent + dynamicContent;
	} else {
		var fullString = staticContent + dynamicContent;
	}
	
	// workaround for NS
	if (document.layers) fullString = "<a href=\"[colLink]\" 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=\"More about [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);
}

