//
// head
//
function loadHead(id_content, depth) {
  var parent = '';
  var i; for( i = 0; i < depth; i++ ) { parent += '../'; }

  var head = document.getElementById('head');
  
  var h1 = document.createElement('h1');
  var a = document.createElement('a');
  a.href = parent + 'index.html';
  a.innerHTML = '今さら攻略 スーパーマリオブラザーズ 2';
  a.title = '今さら攻略 スーパーマリオブラザーズ 2 トップページへ';
  h1.appendChild(a);

  var navi = document.createElement('div'); navi.id = 'navi';
  var user_ = document.createElement('div'); user_.id = 'user_';
  var user = document.createElement('div'); user.id = 'user';
  
  var dispNavi = function() { navi.style.display = 'block'; }
  var hideNavi = function() { navi.style.display = 'none'; }
  addListener(h1, 'mouseover', dispNavi, false);
  addListener(h1, 'mouseout', hideNavi, false);
  addListener(navi, 'mouseover', dispNavi, false);
  addListener(navi, 'mouseout', hideNavi, false);
  
  head.appendChild(h1);
  head.appendChild(navi);
  head.appendChild(user_);
  head.appendChild(user);

  loadNavigation(id_content, depth);
  return;
}


//
// navi
//
function loadNavigation(id_content, depth) {
  var parent = '';
  var i; for( i = 0; i < depth; i++ ) { parent += '../'; }

  var navi = document.getElementById('navi');

  var createNavigation = function(xml) {
    navi.style.display = 'none';

    var ul = document.createElement('ul');
    for( i = 0; i < getNode(xml, 'navi', -1).length; i++ ) {
      var xml_navi = getNode(xml, 'navi', i);
      var li = document.createElement('li');
      var a = document.createElement('a');
      li.id = getNodeValue(xml_navi, 'id', 0);
      if( li.id == id_content ) { li.className = 'active'; }
      a.innerHTML = getNodeValue(xml_navi, 'name_j', 0);
      a.href = parent + getNodeValue(xml_navi, 'href', 0);
      a.title = getNodeValue(xml_navi, 'name_e', 0) + ' （' + getNodeValue(xml_navi, 'name_j', 0) + '）';
      li.appendChild(a);
      ul.appendChild(li);
    }
    navi.appendChild(ul);
    return;
  }
  var query = new Array();
  query.push('cmd=index_navi');
  httpXMLRequest(dir('cgi', depth) + 'common.cgi', 'POST', array2queryString(query), createNavigation, httpError, 'navi.' + id_content, true);
  return;
}


//
// h2 背景
//
function loadBackground_h2() {
  var i;
  var month = (new Date()).getMonth() + 1;
  var bg_h2 = 'h2_1.png';
  if( 3 <= month  &&  month <= 8 ) { bg_h2 = 'h2_1.png'; }
  else if( 9 <= month  &&  month <= 11 ) { bg_h2 = 'h2_2.png'; }
  else { bg_h2 = 'h2_3.png'; } // month == 12 or 1 or 2
  for( i = 0; i < getNode(document, 'h2', -1).length; i++ ) {
    getNode(document, 'h2', i).style.background = 'url(' + dir('img', 0) + 'bg/' + bg_h2 + ') bottom left no-repeat';
  }
  return;
}


////////////////////////////////////////////////////////////////////////////////
//
// foot
//
////////////////////////////////////////////////////////////////////////////////
function loadFoot(depth) {
  var i;
  var parent = '';
  for( i = 0; i < depth; i++ ) { parent += '../'; }

  var month = (new Date()).getMonth() + 1;
  var bg_foot = 'foot_1.png';
  if( 3 <= month  &&  month <= 8 ) { bg_foot = 'foot_1.png'; }
  else if( 9 <= month  &&  month <= 11 ) { bg_foot = 'foot_2.png'; }
  else { bg_foot = 'foot_3.png'; } // month == 12 or 1 or 2
  document.getElementById('foot').style.background = 'url(' + dir('img', 0) + 'bg/' + bg_foot + ') no-repeat';
  var content = document.getElementById('content_foot');

  var createFootNavigation = function(xml) {
    for( i = 0; i < getNode(xml, 'navi', -1).length; i++ ) {
      var xml_navi = getNode(xml, 'navi', i);
      var a = document.createElement('a');
      a.style.margin = '0 .66em';
      a.innerHTML = getNodeValue(xml_navi, 'name_e', 0);
      a.href = parent + getNodeValue(xml_navi, 'href', 0);
      content.appendChild(a);
      if( i < getNode(xml, 'navi', -1).length - 1 ) { content.appendChild(document.createTextNode('|')); }
    }

    var p_note = document.createElement('p'); p_note.className = 'note';
    p_note.innerHTML = '※ Opera 8，Firefox 1.5 にて動作・表示を確認しています．Internet Explorer 6 でも動作についてはほぼ確認していますが，表示が一部正常に行われません．';
    content.appendChild(p_note);
    return;
  }
  var query = new Array();
  query.push('cmd=index_navi');
  httpXMLRequest(dir('cgi', depth) + 'common.cgi', 'POST', array2queryString(query), createFootNavigation, httpError, 'navi.foot', true);

  return;
}


////////////////////////////////////////////////////////////////////////////////
//
// countaccess
//
////////////////////////////////////////////////////////////////////////////////
function countAccess(id_content) {
  var countaccess = document.getElementById('countaccess');
  // 関数： 読み込み後の処理
  var func = function(xml) {
    var a = document.createElement('a');
    //a.className = 'linklike';
    a.innerHTML += 'Total: ' + getNodeValue(xml, 'all', 0);
    a.innerHTML += '&nbsp; This year: ' + getNodeValue(xml, 'year', 0);
    a.innerHTML += '&nbsp; This month: ' + getNodeValue(xml, 'month', 0);
    a.innerHTML += '&nbsp; Today: ' + getNodeValue(xml, 'day', 0);
    countaccess.appendChild(a);
    return;
  }
  var query = new Array();
  query.push('cmd=count_access');
  query.push('id_content=' + id_content);
  httpXMLRequest(dir('cgi', 0) + 'log.cgi', 'POST', array2queryString(query), func, httpError, 'cgi_log_count_access.' + id_content, true);
  return;
}





//
// ユーザ名を取得する
//
function getUName() { return document.getElementById('user').uname; }
//
// ユーザIDを取得する
//
function getUID() { return document.getElementById('user').uid; }
// ルートならば真
function isRoot() { return ( getUID() == '63a9f0ea7bb98050796b649e85481845' ); }
// ユーザならば真
//function isUser() { return ( getUID().match(/^\d{10}$/) ); }
function isUser() { return ( getUID().match(/^\w{32}$/) ); }


