var TkFragmentSiteMap = Class.create();
TkFragmentSiteMap.prototype = {
  initialize: function(container, id, assetPath, options) {
    this.container = container;
    this.id = id;
    this.assetPath = tkRootCMS + assetPath;
    this.node = g_navNode_Root;
    this.options = {
      className: 'tkFragmentSiteMap',
      overview: false
    }
    Object.extend(this.options, options || {});
  },

  write: function() {
    var list = [];
    list.push('<div id="' + this.id + '">');
    list.push(  '<table class="' + this.options.className + '" cellspacing="0">');
    list.push(    '<tbody>');
    this.writeNode(list, this.node);
    list.push(    '</tbody>');
    list.push(  '</table>');
    list.push('</div>');
    list.each(function(html) { document.write(html) });
  },

  writeNode: function(list, node) {
    var level = node.m_level;
    if (level == 1 || level == 2 || level == 3 || level == 4) {
      var html = '<tr><td class="level' + (level) + '"><div>';
      if (level > 3) {
        html += '<img class="bullet" src="' + this.assetPath + '/image/bullet/blue.gif" alt="-" />';
      } else if (level > 1) {
        html += '<img class="bullet" src="' + this.assetPath + '/image/bullet/blue.gif" alt="-" />';
      }
      if (level == 1) {
        html += '<img class="box" src="' + this.assetPath + '/image/box/blue.gif" alt="-" />';
      }
      if (!this.options.overview && level == 1 && 0 < node.m_subNodes.length) {
        html += node.m_label;
      } else {
        html += '<a href="' + node.m_href + '">' + node.m_label + '</a>';
      }
      html += '</div></td></tr>';
      list.push(html);
    }
    for (var i = 0; i < node.m_subNodes.length; i++) {
      this.writeNode(list, node.m_subNodes[i]); //, node.m_id);
      if (level < 1) {
        list.push('<tr><td>&nbsp;</td></tr>');
      }
    }
  }
}
