// ----------------------------------------------------------------------------
// Name   : safePalette.js
// Desc   : Prints a Browser Safe Palette
// ----------------------------------------------------------------------------
function printSafePalette() {
	// initial values: http://www.aupublishing.com/imotic/home/tutorial/images/palette.gif
	var image   = "palette.gif";
	var color   = "#000000";
	var counter = 0;
	var red     = 0;
	var green   = 0;
	var blue    = 0;

	document.writeln('<!-- Inserting Color Map -->');
	document.writeln('<IMG WIDTH="284" HEIGHT="248" BORDER="0" SRC="' + image + '" USEMAP="#palette" STYLE="cursor: hand">');
	document.writeln('<MAP NAME="palette">');

	for (startHeight = 0; startHeight < 248; startHeight += 18) {
		// loop through each row
		endHeight = startHeight + 14;
		for (startWidth = 0; startWidth < 284; startWidth += 18) {
	    // loop through each box within a row
	    endWidth = startWidth + 14;

	    // avoid printing extra boxes
	    counter++;
	    if (counter <= 216) {
	      // if we're still dealing with colors here, then actually print the line
	      document.writeln('<AREA SHAPE="RECT" COORDS="'+startWidth+','+startHeight+','+endWidth+','+endHeight+'" onClick="if (pcm_click) { pcm_click(\''+color+'\');return true; }" ALT="'+color+'" onMouseOver="if (pcm_mouseover) { pcm_mouseover(\''+color+'\');return true; }" onMouseOut="if (pcm_mouseout) { pcm_mouseout(\''+color+'\');return true; }">');
	    }

	    // go to next color
	    red += 33;
	    if (red == 132) red = "CC"
	    if (red == "CC33") red = "FF"
	    if (red == "FF33") {
	      red = 0;
	      green += 33;
	      if (green == 132) green = 'CC'
	      if (green == "CC33") green = "FF"
	      if (green == "FF33") {
	        green = 0;
	        blue += 33;
	        if (blue == 132) blue = "CC"
	        if (blue == "CC33") blue = "FF"
	      }
	    }

	    // convert to strings
	    redPart = red; greenPart = green; bluePart = blue;
	    if (redPart   == 0)  redPart = "00";
	    if (redPart   == 33) redPart = "33";
	    if (redPart   == 66) redPart = "66";
	    if (redPart   == 99) redPart = "99";
	    if (greenPart == 0)  greenPart = "00";
	    if (greenPart == 33) greenPart = "33";
	    if (greenPart == 66) greenPart = "66";
	    if (greenPart == 99) greenPart = "99";
	    if (bluePart  == 0)  bluePart = "00";
	    if (bluePart  == 33) bluePart = "33";
	    if (bluePart  == 66) bluePart = "66";
	    if (bluePart  == 99) bluePart = "99";

	    // add strings together to get final color value
	    color = "#" + redPart + greenPart + bluePart;
	  }
	}
	document.writeln('</MAP>');
	document.writeln('<!-- Ending Color Map -->');
}

// end of safePalette.js -----------------------------------------------------
