/*-----------------------------------------------------------------------------
** colorPick.js:
*----------------------------------------------------------------------------*/
var colClose=false;
var colButton;

openColorPick = function(o) {
  colButton=o;

  var col='';
  if (document.all && !window.opera) // Fix IE 6.0 select z-index bug
    col+='<iframe frameborder="0" width=112 height=112 style="position:absolute;"></iframe>\n';
  col+='<div onmouseout="hideColorPick();" style="position:absolute;border:#000 1px solid;padding:0px;">\n';
  col+=' <div onmouseover="showColorPick();" style="border:#ADAADD 3px outset;">\n';
  col+='  <div style="position:relative;border:#000 1px solid;width:110px;height:110px;_width:130px;_height:112px;">\n';
  col+=   drawColorPick();
  col+='  </div> \n';
  col+=' </div> <!-- inner border -->\n';
  col+='</div> <!-- outer border -->\n';

  // Create an element in the document to put the colorPicker into
  posn = document.createElement('DIV');
  posn.id='colorPickPopUpDiv';
  posn.style.position='relative';
  posn.style.zIndex=2147483646;
  posn.style.left=10+o.offsetLeft+'px';
  posn.style.top='-10px';
  posn.innerHTML=col;
  o.parentNode.appendChild(posn);
};

drawColorPick = function() {
	if (!window.colors) 
  	colors = new Array ('666','999','ccc','fff','600','900','c00','f00','f49','660','990','cc0','ff0','fc0','DAA658','A0A291', 'D7745B', 'DA681D', '7ADCF3', 'B6B8B6', 'CCA2BF', '896207', '71863E', '667699', '8D70D3');

  var table="";
  for (var i=0;i<colors.length;i++) { 
    table+='  <div style="background:#'+colors[i]+';border:#88a 2px outset;width:18px;height:18px;_width:22px;_height:22px;float:left;cursor:pointer;" onmouseover="colHilite(event);" onmouseout="colHilite(event);" onclick="setColor(this);"> </div>\n';
  }
  return table;
};

setColor = function(o) {
  colButton.style.background=o.style.background;
  colClose=true;
  closeColorPick();
};

showColorPick = function() {
  colClose=false;
};

hideColorPick = function() {
  colClose=true;
  setTimeout(closeColorPick,750);
};

closeColorPick = function() {
  if (colClose) {
    var col=document.getElementById("colorPickPopUpDiv");
    if (col)
      col.parentNode.removeChild(col);
    colClose=false;
  }
};

colHilite = function(e) {
  if (!e)
    var e=window.event;
  var o=e.srcElement||e.target;
  switch (e.type) {
    case "mouseover" :
      o.setAttribute("bord",o.style.border);
      o.style.border="#eee 2px inset";
     break;
    case "mouseout" :
      o.style.border=o.getAttribute("bord");
     break;
  }
};
