//alert('included hangman-support.js');

/* start: List Building Functions */

function getListData(obj){
  //parse a named <dl> list for <dt>'s and assemble them into a JSON array for a customized hangman wordlist

  var html = ''
  var elArr = obj.getElementsByTagName('dt');
  for(var i=0; i<elArr.length; i++){
    if(html.length>0) html += ',';
    html += "'"+elArr[i].innerHTML.replace(/\'/gim,'').replace(/[^a-zA-Z ]/gim,' ')+"'";
  }
  return html
}

function makeList(sourceObj,tobj){
  //present a generated list 

  var html = getListData(sourceObj);
  var el = document.createElement('div');
  el.innerHTML = '<textarea style="width:100%;height:300px;" onfocus="this.select();">var wordlist = ['+html+'];</textarea>';
  tobj.style.border='2px #ddd solid';
  tobj.style.backgroundColor='#eee';
  tobj.style.padding='5px';
  tobj.style.margin='5px';
  tobj.innerHTML = ''; 
  tobj.appendChild(el);
}

/* end: List Building Functions */





/* start: Button Functions */

function getButtonHTML(text,color,id,href){
  //build a custom button using an anchor and img

  /* find the relative path to the images based on deriving the host name */
  var host = location.host || location.href.match(/\.(com|net|ws|info)\//); host=host[0];
  
//  var tmp = location.href.substr(location.href.indexOf(host),location.
  var path = location.href
  var imgPath = 'http://hostagnostic.com/dictionary/images/button/'; 
  var html=''
  +'<table id="'+id+'"  cellpadding="0" cellspacing="0" width="100"'
  +'  style="height:26px;cursor:pointer;background-color:'+color+'" '
  +'  onclick="'+href+'">'
  +'  <tr>'
  +'    <td><img src="'+imgPath+'button-hangman.gif"></td>'
  +'    <td width="100%" id="'+id+'_text" style="background-image:url('+imgPath+'button-blank.gif);font-family:arial;font-size:12px;font-weight:bold;" nowrap>'+text+'</td>'
  +'    <td><img src="'+imgPath+'button-right.gif"></td>'
  +'  </tr>'
  +'</table>'
  return html
}

function animateIVButton(obj,c){
  /* this needs to know details about the button HTML */
  var mId = obj.id;
  var obj1 = obj;
  var obj2 = document.getElementById(mId+'_text'); /* text label is in another named container */

  if(c && window.fnInt){ clearInterval(window.fnInt); window.fnInt=null; }

  var colr=colorArr[i];
  obj1.style.backgroundColor = (c!=undefined?c:colr);
  obj2.style.color = (c!=undefined?c:colr);

  if(++i>colorArr.length){ clearInterval(window.fnInt); window.fnInt=null; }
}

var colorArr = [
  '#000','#111','#222','#333','#444','#555','#666','#777','#888','#999','#aaa','#bbb','#ccc','#ddd','#eee','#fff',
  '#eee','#ddd','#ccc','#bbb','#aaa','#999','#888','#777','#666','#555','#444','#333','#222','#111','#000',
  '#aaa','#f00','#aaa','#f00','#aaa','#f00','#aaa','#f00','#aaa','#f00','#aaa','#f00','#aaa','#f00','#aaa','#f00','#aaa','#f00','#aaa',
  '#000'
];

/* end: Button Functions */
