
/* JavaScript lib.js by martin $ 2006/11/01 00:52:51
*/
var d = document;
var ie = (d.selection && !window.opera) ? 1 : 0;
var lt7 = navigator.appVersion.match(/MSIE [56]/) ? 1 : 0;
var moz = (d.getSelection && !window.opera) ? 1 : 0;
var kht = navigator.userAgent.match(/webkit|safari|khtml/i) ? 1 : 0;
var w3c = (d.getElementById && !d.all) ? 1 : 0;
var smilies = {};
var caretSelection = "";
var enableRoundedStyle = true; // 角丸コーナー無効にするなら false
var i = 0, _scripts = d.getElementsByTagName("script"), l = _scripts.length || 1;
while(i < l){ if(typeof _scripts[i] != "undefined" && _scripts[i].id != "") break; i++;};
var ImagePath = (typeof _scripts[i] != "undefined") ? 'theme/'+_scripts[i].id+'/Images' : 'Images';
var loadingAni = new Image().src = ImagePath+'/loading.gif';
var expandImg = new Image().src = ImagePath+'/expand.png';
var unexpandImg = new Image().src = ImagePath+'/unexpand.png';
var screenBack = new Image(1,1).src = ImagePath+'/screen.png';
var closeButton = new Image().src = ImagePath+'/button-close.png';

function googleIt(query){
 window.open(encodeURI("http://www.google.com/search?hl=ja&ie=UTF-8&oe=UTF-8&q="+query));
}
function wikipediaIt(query){
 window.open("http://ja.wikipedia.org/wiki/%E7%89%B9%E5%88%A5:Search?search="+encodeURI(query));
}

if(w3c && Event.prototype){
 try {
  for (var property in Event.prototype){
   if(property.match(/MOUSE|CLICK/)){
    window.addEventListener(property.toLowerCase(), function(e){window.event=e}, true);
   }
  }
 } catch (e){};
};

function getClientWidth(){
 if(d.documentElement && d.documentElement.clientWidth){
  return d.documentElement.clientWidth;
 } else if(self.innerWidth){
  return self.innerWidth;
 } else if(d.body){
  return d.body.clientWidth;
 }
}

function getClientHeight(){
 if(d.documentElement && d.documentElement.clientHeight){
  return d.documentElement.clientHeight;
 } else if(self.innerHeight){
  return self.innerHeight;
 } else if(d.body){
  return d.body.clientHeight;
 }
}

function getDocHeight(){ var h;
 if(d.documentElement){
  h = d.documentElement.scrollHeight;
 } else h = d.body.scrollHeight;
 return (arguments.length==1) ? h + 'px' : h;
}

function getEventPageX(){
 var ev = window.event;
 if(ev.pageX){
  return ev.pageX;
 } else if(ev.clientX){
  if(d.documentElement && typeof d.documentElement.scrollLeft != "undefined"){
   return d.documentElement.scrollLeft + ev.clientX;
  } else if(d.body && typeof d.body.scrollLeft != "undefined"){
   return d.body.scrollLeft + ev.clientX;
  }
 }
 return 0;
}

function getEventPageY(){
 var ev = window.event;
 if(ev.pageY){
  return ev.pageY;
 } else if(ev.clientY){
  if(d.documentElement && typeof d.documentElement.scrollTop != "undefined"){
   return d.documentElement.scrollTop + ev.clientY;
  } else if(d.body && typeof d.body.scrollTop != "undefined"){
   return d.body.scrollTop + ev.clientY;
  }
 }
 return 0;
}

function getElementPosition(){
 var _x = _y = 0, ev = window.event;
 var ob = ev.target || ev.srcElement;
 if(ob && ob.offsetParent){
  while (ob.offsetParent){
   _x += ob.offsetLeft; _y += ob.offsetTop;
   ob = ob.offsetParent;
  }
 }
 return [_x, _y];
}

function getScrollY(){
 if(self.pageYOffset){
  return self.pageYOffset;
 } else if(d.documentElement && typeof d.documentElement.scrollTop != "undefined"){
  return d.documentElement.scrollTop;
 } else if(d.body && typeof d.body.scrollTop != "undefined"){
  return d.body.scrollTop;
 }
 return 0;
}

my_confirm = function(text,add){
 if(arguments.length==1) text += "削除しますか？";
 if(!confirm(text)) return false;
 else return true;
}

readMore = function(id, self){
 var ob = o(id);
 if(ob.style.display!="block"){
  ob.parentNode.firstChild.title = '記事をたたむ';
  ob.parentNode.firstChild.innerHTML = '&laquo;やっぱり隠す';
  ob.parentNode.firstChild.style.backgroundPosition = "0 100%";
  ob.style.display = "block";
 } else if(ob.style.display=="block") {
  ob.parentNode.firstChild.title = '続きをよむ';
  ob.parentNode.firstChild.innerHTML = '&raquo;続きを読む';
  ob.parentNode.firstChild.style.backgroundPosition = "0 0";
  ob.style.display = "none";
 }
}

function toggleMenu(id, ob){
 var p = ob.parentNode.parentNode;
 var t = 'sidebar-'+id;
 for(var i=0,l=p.childNodes.length;i<l;i++){
  if(p.childNodes[i].className && p.childNodes[i].className.indexOf(t) > 0){
   var el = p.childNodes[i]; break;
  } else el = '';
 }
 if(el=='') return;
 var bgPos = ob.style.backgroundPosition;
 ob.style.backgroundPosition = bgPos=='0px 100%' ? '0px 0px' : '0px 100%';
 ob.title = bgPos=='0px 100%' ? '閉じます' : '展 開！';
 el.style.display = el.style.display=="none" ? 'block' : 'none';
}

Caret = { // マウスで指定したポイントあるいは文字列に要素を挿入
 get : function(){
  if(typeof ed == "undefined"){
   if(o("Page1")!=null) ed = o("Page1");
   else if(o("c_com")!=null) ed = o("c_com");
   else ed = d.getElementsByTagName("TEXTAREA")[0];
  }
  if(ie){
   if(!d.selection.createRange()) ed.focus();
   ed.selected = d.selection.createRange().duplicate();
  } else if(d.getSelection){
   ed.selected = ed.value.substring(ed.selectionStart, ed.selectionEnd);
  } else ed.selected = ' ';
  return caretSelection = (ie) ? ed.selected.text : ed.selected;
 },
 set : function(string){
  if(typeof caretSelection == "undefined" || typeof ed == "undefined") Caret.get();
  if(ie){
   if(caretSelection.length > 0){
    ed.selected.text = string;
    ed.selected.select();
   } else {
    ed.focus();
    ed.selected = d.selection.createRange().duplicate();
    ed.selected.text = string;
   }
  } else if(d.getSelection && caretSelection.length>=0 && ed.selectionStart>=0){
    var s = ed.selectionStart;
    var scrollTop = ed.scrollTop;
    ed.value = ed.value.slice(0,s)+ed.value.slice(s).replace(caretSelection, string);
    ed.setSelectionRange(eval(s+string.length), eval(s+string.length));
    ed.scrollTop = scrollTop;
    ed.focus();
  } else ed.value += string;
 }
}

hackFirefoxToolTip = function(){
 var imgs = d.getElementsByTagName('IMG');
 MozToolTip = Element("DIV", {backgroundColor:"ivory", border:"1px solid #333", padding:"1px 3px", font:"500 11px arial", zIndex:10000, top:-100});
 MozToolTipShadow = Element("DIV", {MozOpacity:0.3, MozBorderRadius:"3px", background:"#000", zIndex:(MozToolTip.style.zIndex - 1)})
 var i = 0, l = imgs.length;
 while(i<l){
  if(imgs[i].getAttribute('title') != null || imgs[i].getAttribute('alt') != null){
   addEvent(imgs[i], "mouseover", function(){
    if(typeof MozToolTip == 'undefined') return;
    this._title = this.getAttribute('title')!=null ? this.getAttribute('title') : this.getAttribute('alt');
    this.setAttribute('title', '');
    this._title = this._title.replace(/[\r\n]+/g,'<br/>').replace(/\s/g,'&nbsp;');
    if(this._title=='') return;
    setXY(MozToolTip, 20 + event.pageX, 30 + event.pageY);
    MozToolTip.innerHTML = this._title;
    setWH(MozToolTipShadow, MozToolTip.offsetWidth -2, MozToolTip.offsetHeight -2);
    setXY(MozToolTipShadow, parseInt(MozToolTip.style.left) + 5, parseInt(MozToolTip.style.top) + 5);
   });
   addEvent(imgs[i], "mouseout", function(){
    if(typeof MozToolTip == 'undefined') return;
    this.setAttribute('title', MozToolTip.innerHTML.replace(/<br\/>/g,'&#13;&#10;').replace(/&nbsp;/g,' '));
    if(typeof setXY == "function"){
     setXY(MozToolTip, -1000, -1000);
     setXY(MozToolTipShadow, -1000, -1000);
     MozToolTip.innerHTML = '';
    }
   });
  }
  i++;
 }
 if(d.body){
  d.body.appendChild(MozToolTipShadow);
  d.body.appendChild(MozToolTip);
 }
}

function roundedStyle(elm, quote){
 var RS = d.getElementsByClassName("rounded", elm);
 if(quote) { var RS = d.getElementsByClassName("quoted", elm, "BLOCKQUOTE"); }
 var RS_Content = [], cord = 0.93;
 var contents, upper, lower, pbg, border, alias, bg, wd, base, c, quoteFontStyle;
 var i = 0, l = RS.length;
 while(i<l){
  contents = RS[i].innerHTML;
  upper = '<span><span></span><span><span></span></span><span><span></span></span>'
   + '<span><span></span></span><span><span></span></span></span>';
  lower = '<span><span><span></span></span><span><span></span></span>'
   + '<span><span></span></span><span><span></span></span><span></span></span>';

  pbg = backgroundRGB(RS[i].parentNode), bg = backgroundRGB(RS[i]);
  border = "rgb("+parseInt(bg[0] * cord)+", "+parseInt(bg[1] * cord)+", "+parseInt(bg[2] * cord)+")";
  alias = "rgb("+parseInt(eval(pbg[0]+bg[0])*.5)+", "+parseInt(eval(pbg[1]+bg[1])*.5)+", "+parseInt(eval(pbg[2]+bg[2])*.5)+")";
  bg = "rgb("+bg[0]+","+bg[1]+","+bg[2]+")";
  wd = getRuntimeStyle(RS[i], 'width', 'CSS'); wd = (wd=='auto') ? 'auto' : wd + 'px';
  if(!quote) border = getRuntimeStyle(RS[i], 'borderTopColor');
  RS[i].style.cssText = "line-height:1.0;border-color:transparent;background-color:transparent;margin:1.5em auto;width:"+wd+";padding:0;";
  RS[i].innerHTML = upper;
  base = 'display:block; height:1px; overflow:hidden; font-size:1px; background:'+bg+';'
   + ' border-width:0 1px; border-color:'+border+'; border-style: solid;';
  
  c = RS[i].getElementsByTagName("SPAN");
  c[0].style.cssText = 'display: block;';
  c[1].style.cssText = base + 'border-color:'+alias+'; padding:0 1px; margin:0 4px; background:'+border+';';
  c[2].style.cssText = base + 'border-color:'+alias+'; padding:0 2px; margin:0 2px; background:'+border+';';
  c[3].style.cssText = base + 'border-color: '+alias+';';
  c[4].style.cssText = base + 'border-color:'+alias+'; padding:0 1px; margin:0 1px; background:'+border+';';
  c[5].style.cssText = base + 'border-color: '+alias+';';
  c[6].style.cssText = base + 'margin:0 1px;'; c[7].style.cssText = base + 'border-color: '+alias+';';
  c[8].style.cssText = base + 'border-color: '+alias+';'; c[9].style.cssText = base + 'border-color: '+border+';';
  
  if(quote){
   quoteFontStyle = "font:600 50px Georgia; color:#ddd;";
   contents = '' + // wrpapper DIV's padding-bottom = latter quote P's margin-bottom
    '<div style="margin:0; border:solid 1px '+border+'; border-width:0 1px; padding:0 30px 15px 35px;background:'+bg+';">' +
    '<p style="margin:0 0 -45px -40px;'+quoteFontStyle+'line-height:1;padding:5px 0 0 0;">&nbsp;“</p>' + contents +
    '<p style="'+quoteFontStyle+'line-height:0;text-align:right; margin:0 -25px -15px 0;">&nbsp;”</p></div>';
   RS[i].innerHTML += contents;
  } else {
   RS[i].innerHTML += '<div style="border:solid 1px '+border+'; border-width:0 1px; padding:10px;background:'+bg+';">'+contents+'</div>';
  }
  RS[i].innerHTML += lower;
  c[10].style.cssText = c[0].style.cssText;  c[11].style.cssText = c[8].style.cssText;
  c[12].style.cssText = c[9].style.cssText;  c[13].style.cssText = c[6].style.cssText;
  c[14].style.cssText = c[7].style.cssText;  c[15].style.cssText = c[4].style.cssText;
  c[16].style.cssText = c[5].style.cssText;  c[17].style.cssText = c[2].style.cssText;
  c[18].style.cssText = c[3].style.cssText;  c[19].style.cssText = c[1].style.cssText;
  i++;
 }
}

function customBox(ob){
 var contents = ob.innerHTML;
 ob.innerHTML = "";
 var _bt = d.createElement("DIV");
 _bt.style.cssText = "background:url(Images/cssbox.png) no-repeat 100% 0;margin:0 0 0 17px;height:17px;padding:0;";
 _bt.innerHTML = '<div style="position:relative;left:-17px;width:17px;height:17px;margin:0;background:url(Images/cssbox.png) no-repeat 0 0;line-height:0;font-size:0;"></div>';
 ob.insertBefore(_bt, ob.firstChild);
 var _bb = d.createElement("DIV");
 _bb.style.cssText = "background:url(Images/cssbox.png) no-repeat 100% 100%;height:17px;margin:0 0 0 17px;";
 _bb.innerHTML = '<div style="position:relative;left:-17px;width:17px;height:17px;margin:0;background:url(Images/cssbox.png) no-repeat 0 100%;line-height:0;font-size:0;"></div>';
 var _bl = d.createElement("DIV");
 _bl.style.cssText = "background:url(Images/bl.png) repeat-y 0 0; padding-left: 12px;height:100%;";
 _bl.innerHTML = '<div style="background: url(Images/br.png) repeat-y 100% 0;padding:0;height:100%;"><div style="background:#fff;height:100%;margin:0 12px 0 0px;padding:1em;">'+contents+'</div></div>';
 ob.insertBefore(_bl, ob.firstChild.nextSibling);
 ob.insertBefore(_bb, null);
}

var Ajax = {
 request : function(){
  return window.XMLHttpRequest ? 
  new XMLHttpRequest() : (window.ActiveXObject) ?
  new ActiveXObject(navigator.appVersion.match(/MSIE 5/) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP") : null;
 },
 get : function(url, func){
  var r = Ajax.request();
  try {
   r.open("GET", url, true);
   r.onreadystatechange = function(){
    Ajax.debug("Now Loading.. "+ url + " : " + r.readyState);
    if(r.readyState==4){
     if(func) func(r.responseText);
     Ajax.debug("");
    }
   }
   r.setRequestHeader("If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT");
   r.send(null);
  } catch (e){Ajax.debug(e,1)}
 },
 post : function(url, data, func){
  var r = Ajax.request();
  try {
   r.open("POST", url, true);
   r.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   r.onreadystatechange = function(){
    if(r.readyState==4){
     if(func) func(r.responseText);
    }
   }
   r.send(data);
  } catch (e){Ajax.debug(e,1)}
 },
 cloneScript : function(src){
  var id = src.split(/\//).pop().replace(/\./, '_');
  var s = d.createElement("script");
  var r = Ajax.request();
  s.setAttribute('type', 'text/javascript');
  s.setAttribute('id', id);
  s.setAttribute('charset', 'euc-jp');
  if(kht) s.setAttribute('src', src);
  if(!d.getElementById(id)){
   d.getElementsByTagName("head")[0].appendChild(s);
  } else return true; // cached
  r.open("GET", src, false); // Not async.
  r.setRequestHeader("If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT");
  r.send(null);
  if(r.readyState==4){
   if(r.status==200){
    s.text = r.responseText; // text property!
    return true;
   }
  }
  if(d.getElementById(id)){
   d.getElementById(id).parentNode.removeChild(d.getElementById(id));
   Ajax.debug("404 error : " + src);
  }
  return false;
 },
 debug : function(d, a){!a ? (window.status=d) : alert("Ajax debug: "+d);}
}

comments_in_situ = function(uid, author, allowed){
 Ajax.cloneScript("ajax.php?type=info");
 var FILTER = {'&#96;':"`", '&#44;':",", '&#124;':"|", '&#36;':"$", '&yen;':'\\', '&quot;':"\""};
 var ob = window.event.target || window.event.srcElement;
 var loaded = Ajax.cloneScript('ajax.php?type=json&aim=owner/smiley.ini.php');
 var articleBottom = gc("article-bottom", o("UID"+uid))!=null ?
  gc("article-bottom", o("UID"+uid)) : gc("article-united-bottom", o("UID"+uid));
 var eX = getEventPageX(), eY = getEventPageY();
 if(o("ajaxToolTip")==null){
  toolTip = Element("DIV#ajaxToolTip",
   {backgroundColor:"ivory", border:"1px solid #333", padding:"2px 3px", width:140, font:"500 13px MS P Gothic, Osaka", textAlign:"center",
    zIndex:10000, left:eX + (getClientWidth()/2<eX?-200:200), top:eY}
  );

  toolTip.innerHTML = 'コメント読み込み中...';
  d.body.appendChild(toolTip);
 } else {
  toolTip = o("ajaxToolTip");
  toolTip.innerHTML = 'コメント読み込み中...';
  setXY(toolTip, eX + 100, eY);
 }
 var externalLink = ' <img src="'+ImagePath+'/external-link.png" width="12" height="12" alt="Link" title="外部リンク" />';
 var callback = function(data){
  var commentDiv = Element("DIV.comment-div", {position:"relative", marginLeft:"13px"});
  data = data.replace(/\[\[(.+?):http:\/\/(.+?)\]\]/gm,
   function (s0, s1, s2){
    return '<a href="http://'+s2+'" onclick="window.open(this.href,\'\');return false;" rel="nofollow">'+s1+'</a>'+externalLink;
  });
  data = data.replace(/[^"\|]http:\/\/([;\/\?:@&=\+\$,\w\-\.!~%#]+)/gm,
   function (s0, s1){
    return '<a href="http://'+s1+'" onclick="window.open(this.href,\'\');return false;" rel="nofollow">http://'+s1+'</a>'+externalLink;
   });
  data = data.replace(/\[q\]`?(.+?)`?\[\/q\]/gm, '<p class="comment-quote">$1</p>');
  for (var i in smilies){
   var r = new RegExp(i.toString().replace(/(\W)/, "\\$1"), "g");
   data = data.replace(r, smilies[i]);
  }
  var cmt = '', nondisc = '', aj = data.split("\n"), ajlen = aj.length;
  if(typeof ADMIN == "undefined") ADMIN = false;
  if(ajlen > 1){
   var ID = aj[0].split('|')[0], NO = isNondiscUsr = 0, tip = '';
   for(i=1; i < ajlen-1; i++){
    var a = aj[i].split('|'); // a[1] = submitter
    var cip = a[4]!=0 ? ' IP: '+a[4] : ' IP: -';
    var cmail = (a[6]=='') ? '' : ' <span style="color:rgb(250, 60, 5);font-size:11px;">メールアドレス登録あり</span>';
    if(document.cookie.match(/PPBLOG_UCONF=(.+?);/)){
     var tip = unescape(RegExp.$1).split(',').pop();
     if(tip==encodeURIComponent(a[1]+a[4])) isNondiscUsr = a[1];
    }
    if(a[7]==1){
     if(!OADMIN){
      if(a[1]==ONAME){
       if(isNondiscUsr && aj[i-1].indexOf("|"+isNondiscUsr+"|")!=-1){
        isNondiscUsr = a[1];
       } else continue;
      } else {
       if(tip==encodeURIComponent(a[1]+a[4])){ // 非公開指定したユーザーっぽい
        isNondiscUsr = a[1];
       } else continue;
      }
      if(isNondiscUsr){ NO++; c_nondisc = ' non-disclosure'; }
     } else { // ADMINなら
      NO++; c_nondisc = ' non-disclosure';
     }
    } else { NO++; c_nondisc = ''; }
    var d = new Date(a[0]*1000), Y = d.getFullYear(), mn = d.getMonth()+1, day = d.getDate();
    var h = d.getHours(), mt = d.getMinutes(), s = d.getSeconds();
    h = (h < 10) ? "0"+h : h; mt = (mt < 10) ? "0"+mt : mt; s = (s < 10) ? "0"+s : s;
    var u = a[5]!='' ? ' <a href="'+a[5]+'" onclick="window.open(this.href,\'\');return false;"><img src="'+ImagePath+'/home.png" alt="Website" title="Website" class="home-icon" /></a>' : '';
    var cbody = a[3].replace(/`/gm, " <br /> ");
    var cntrl = (OADMIN || UNAME==a[1]) ?
     '<span class="comment-cntrl"><a  href="admin.php?mode=edit_comment&amp;UID='+uid+'&amp;CID='+a[0]+'"><img src="'+ImagePath+'/edit-comment.png" alt="Edit" title="このコメントの編集" /></a> <a  href="admin.php?mode=delete_comment&amp;UID='+uid+'&amp;CID='+a[0]+'" onclick="return my_confirm(\'このコメントを\')"><img src="'+ImagePath+'/del-comment.png" alt="Delete" title="このコメントの削除" /></a> ' : '';
    var res = (OADMIN || UNAME==a[1]) ?
     '<a href="admin.php?mode=res_comment&amp;UID='+uid+'&amp;CID='+a[0]+'"><img src="'+ImagePath+'/reply.png" alt="Reply" title="このコメントに返事を書く" /></a></span>' : '';
    cmt += (author==a[1] ? ' <div class="comment-entry-owner">\n' : ' <div class="comment-entry'+c_nondisc+'">\n');

    if(author==a[1]){ // owner
     cmt += ('  <p><a class="owner" id="CID'+a[0]+'" title="Permalink" href="index.php?UID='+ID+'#CID'+a[0]+'"> <img src="'+ImagePath+'/owner-comment.png" class="comment-owner" title="Permalink" alt="Owner Comment" /></a> '+a[1]+u+' &mdash; '+Y+'/'+mn+'/'+day+'@'+h+':'+mt+':'+s+'</p>\n');
    } else {
     cmt += ('  <p class="comment-index"><a class="No" id="CID'+a[0]+'" title="Permalink" href="index.php?UID='+ID+'#CID'+a[0]+'">'+NO+'.</a> '+a[1]+u+' &mdash; '+Y+'/'+mn+'/'+day+'@'+h+':'+mt+':'+s+' '+(ADMIN?cip+' '+cmail:'')+'</p>\n');
    }
    cmt += ('  <div class="comment-body" style="color:#'+a[2]+';">'+cbody+cntrl+res+'</div>\n');
    cmt += '</div>\n';
    if(i < ajlen-1 ) cmt += '<hr class="comment-separator" />\n';
   } //for-loop
   if(allowed){
    cmt += '<div class="commentFormHere"><button type="button" onclick="loadCommentForm('+uid+');return false;" title="コメントする">Add your comment</button></div>\n';
   } else {
    cmt += '<p class="comment-closed">この記事に対するコメントは締め切られています</p>\n';
   }
   cmt += '</div><!--#comment-div-->\n';
  }
  for (var i in FILTER){ cmt = cmt.replace(new RegExp(i, "g"), FILTER[i]); }
  commentDiv.innerHTML = cmt;
  articleBottom.appendChild(commentDiv);
  if(ob){
   ob.firstChild.data = ob.firstChild.data.replace(/\[\+\]/,"[-]");
   ob.title = "表示したコメントを隠します";
  }
  toolTip.innerHTML = ' コメント読み込み完了！ ';
  setTimeout('toolTip.style.top = "-1000px"', 500);
 } //#callback
 if(articleBottom.innerHTML.match(/comment-div/)){ // already loaded and displayed
  var comment = gc("comment-div", articleBottom);
  toolTip.style.display = "none";
  if(comment.style.display!="none"){
   comment.style.display = "none";
   if(ob) ob.firstChild.data = ob.firstChild.data.replace(/\[\-\]/,"[+]");
   return;
  } else {
   comment.style.display = "block";
   if(ob) ob.firstChild.data = ob.firstChild.data.replace(/\[\+\]/,"[-]");
   return;
  }
 }
 if(!loaded){
  return;
 } else {
  Ajax.get('ajax.php?type=text&aim=comments/'+uid+'.log', callback);
 }
}

function loadCommentForm(uid,ob){
 var loaded1 = Ajax.cloneScript("ajax.php?type=info");
 var loaded2 = Ajax.cloneScript("ajax.php?type=clone&aim=js/comment.js");
 if(loaded1 && loaded2){
  Ajax.get("ajax.php?type=commentform&UID="+uid, function(data){gc("commentFormHere",o("UID"+uid)).innerHTML=data;});
 }
}

function loadPage(uid, page){
 var uid = uid.replace(/d$/,'');
 Ajax.get("ajax.php?type=page&UID="+uid+"&page="+page, function(data){
  var oContent = o("UID"+uid);
  var articleContent = gc("article-content", oContent);
  articleContent.style.lineHeight = 1.7;
  if(gc("comment-expand", o("UID"+uid))!=null){
   data += '<p class="comment-expand" title="ここでコメントを展開します">'
        + gc("comment-expand", o("UID"+uid)).innerHTML
        + '</p>\n';
  }
  oContent.scrollIntoView();
  if(window.opera){
   articleContent.innerHTML = '';
   articleContent.innerHTML = data;
   setTimeout(function(){ roundedEffects(articleContent)}, 50);
  } else {
   articleContent.innerHTML = data;
   roundedEffects(articleContent);
  }
  if(moz) hackFirefoxToolTip();
 });
}

function loadArticle(uid){
 var uid = uid.replace(/d$/,'');
 var pos = getElementPosition();
 var wrapperWidth = parseInt(getClientWidth()-120);
 var offsetY = 160;
 var oriY = getEventPageY();
 var orgY = getScrollY() - offsetY;
 Ajax.get("ajax.php?type=article&UID="+uid, function(data){
  if(o("UID"+uid)){ o("article-wrapper").style.visibility = "visible"; return; }// now loaded and showing
  if(o("article-wrapper")==null){
   var articleWrapper = Element("DIV#article-wrapper", {top:160, zIndex:5000, width:wrapperWidth}, null);
   var closeImg = Element("IMG.closeButton", {top:5, width:75, height:16, cursor:"pointer"});
   var articleContent = Element("DIV#article-content-container", { position:"relative", background:"#fff" })
   closeImg.src = closeButton;
   closeImg.title = "閉じる";
   var closeImg2 = closeImg.cloneNode(true);
   articleWrapper.appendChild(closeImg);
   articleWrapper.appendChild(articleContent);
   articleWrapper.appendChild(closeImg2);
   customBox(articleWrapper);
  }
  var data = data.split("$");
  var articleWrapper = o("article-wrapper");
  var closeButtons = d.getElementsByClassName("closeButton", articleWrapper);
  var closeImg1 = closeButtons[0], closeImg2 = closeButtons[1];
  var articleContent = gc("article-content", articleWrapper);

  o("article-content-container").innerHTML = (data[0] + data[1] + data[0]);
  if(lt7) o("article-content-container").style.height = "1%"; // for buggy IE6
  if(window.opera){
   setTimeout(function(){ roundedEffects(gc("article-content", o("UID"+uid)));}, 50);
  } else roundedEffects(gc("article-content", o("UID"+uid)));
  
  articleWrapper.style.visibility = "visible";
  addEvent(closeImg1, 'click', function(){ articleWrapper.style.visibility = "hidden";});
  addEvent(closeImg2, 'click', function(){ articleWrapper.style.visibility = "hidden"; window.scrollTo(0, 0);});
  var wrapperHeight = getRuntimeStyle(articleWrapper, "height");
  setXY(closeImg1, parseInt(wrapperWidth - 100), 15);
  setXY(closeImg2, parseInt(wrapperWidth - 100), parseInt(wrapperHeight - 35));
  setXY(articleWrapper, 60, offsetY);
  window.scrollTo(0, offsetY - 50);
  if(moz) hackFirefoxToolTip();
 });
}

function AjaxLogIn(){
 o("loginSubmit").disabled = true;
 var MD5_module = Ajax.cloneScript("./js/md5.js");
 eval(MD5_module);
 if(MD5_module){
  var auto = (o("auto_login") && o("auto_login").checked) ? 1 : 0;
  Ajax.post("admin.php", "mode=login&ID="+MD5.$(o("ID").value)+"&PWD="+MD5.$(o("PWD").value)+"&type=ajax&auto_login="+auto,
   function(to){
    if(to.match(/\.php[\?|]$/)){
     d.write('<script type="text\/javascript">window.location.href="'+to+'";<\/script>');
    } else {
     alert(to);
     o("loginSubmit").disabled = false;
     o("ID").focus();
    }
   }
  );
 } else alert("md5.js module Not Loaded!");
}

function AjaxLogInForm(){
 Ajax.cloneScript("ajax.php?type=info");
 var loginCS = new Image(14,14).src = ImagePath+"/dialog-close.png";
 var BS = Element("DIV", {width:getClientWidth(), height:getDocHeight(), backgroundColor:"#708090", zIndex:999});
 var IO = Element("DIV",
  {left:Math.round((getClientWidth()-270)/2), top:-160, width:270, height:160, zIndex:1000, textAlign:"center",
   border:"outset 3px #aaa", borderTopWidth:0, background:"#ccc url("+ImagePath+"/login-bg.png) repeat-x", padding:"20px 20px 0 20px" });
 var CS = Element("IMG", { left:287, top:4, width:14, height:14, cursor:"pointer"});
 CS.src = loginCS;  CS.title = " 閉じる ";
 
 if(typeof AUTO_LOGIN != 'undefined'){
  if(AUTO_LOGIN){
   setXY(IO, null, 0);
   setWH(IO, null, 120);
   var UI = '<h3>ppBlog*Login</h3>\n'
   + '<p style="line-height:1.3;">自動ログインが有効です.<br />ログインモードに移ります.</p>'
   + '<p><input id="auto_login" name="auto_login" type="hidden" value="1" /></p>';
  } else {
   var UI = '<h3>ppBlog*Login</h3>\n'
   + '<p><label for="ID"> I D </label><input type="text" name="ID" id="ID" /><br />'
   + '<label for="PWD">PWD </label><input type="password" name="PWD" id="PWD" /></p>'
   + (SOLO ? '<p><label for="auto_login" title="次回から自動ログインモードになります">auto-login mode?</label> '
   + '<input id="auto_login" name="auto_login" type="checkbox" value="1" /><br /></p>\n' : '\n')
   + '<p><button type="submit" id="loginSubmit">&nbsp;</button></p>';
  }
 }
 IO.innerHTML = UI;
 addEvent(CS, "click", function(){d.body.removeChild(BS);d.body.removeChild(IO);});
 
 if(ie){
  BS.style.filter = "alpha(opacity=73)";
 } else BS.style.opacity = 0.73;
 IO.appendChild(CS);
 d.body.appendChild(BS);
 d.body.appendChild(IO);
 
 if(typeof AUTO_LOGIN != 'undefined' && AUTO_LOGIN){
  Ajax.post("admin.php", "mode=login&type=auto_login&ref="+location.search, function(to){
   if(to.match(/\.php/)){
    setTimeout('window.location.replace("'+to+'");', 1200);
   }
  });
 } else {
  var fieldcss = "color:#333; height:16px; vertical-align:middle; padding:3px 8px; width:160px; border-width:0;"
              + "margin-bottom: 5px; background: transparent url("+ImagePath+"/txtfield-bg.png) no-repeat 0 0;";
  var btncss = "margin:9px auto 0 auto;width:64px; height:28px; border-width:0; cursor:pointer;"
              + "background: transparent url("+ImagePath+"/submit-button.png) no-repeat;";
  if(o("loginSubmit")) o("loginSubmit").style.cssText = btncss;
  o("ID").style.cssText = o("PWD").style.cssText = fieldcss;
  o("ID").previousSibling.style.cssText = "margin-left:15px;font: 600 15px Arial;color:#444;";
  o("PWD").previousSibling.style.cssText = "font: 600 15px Arial;color:#444;";
  o("loginSubmit").title = "Check it out";
  if(o("ID")) o("ID").focus();
  addEvent(o("loginSubmit"), "click", AjaxLogIn);
  var slideDown = function(ob){ob.style.top = (parseInt(ob.style.top)+10) +"px"};
  slideDown.loop(1, 16)(IO);
 }
}

function gc(clsName, pElement){
 var children = pElement.getElementsByTagName("*");
 var i = 0, l = children.length;
 while(i<l){
  if(children[i].className==clsName) return children[i];
  i++;
 }
 return null;
}

d.getElementsByClassName = function(className, pElement, tagName){
 var cls, gets = [], pElement = pElement || d;
 var obs = pElement.getElementsByTagName((!tagName?"*":tagName));
 var i=0, l=obs.length, j, k;
 while(i < l){
  cls = obs[i].className.split(/\s+/);
  j = 0; k = cls.length;
  while( j < k){
   if(cls[j]==className){
    gets.push(obs[i]); break;
   }
   j++;
  }
  i++;
 }
 return gets;
}

imagePop = function (e, path, w, h){
 var gcW = getClientWidth(), gcH = getClientHeight(), ratio, ow = w, oh = h;
 if(o("article-wrapper")!=null) o("article-wrapper").style.visibility = "hidden";
 if(w > gcW-20 || h > gcH-70){
  ratio = Math.min((gcW-20)/w, (gcH-70)/h);
  w = Math.round(w * ratio); h = Math.round(h * ratio);
 } else ratio = 1;
 if(typeof imgPop == "undefined") imgPop = null;
 if(imgPop==null){
  var imgWrap = Element("DIV", {left:Math.round((gcW-w) / 2), top:Math.round((gcH-h-67) / 2 + getScrollY()), width:w, height:(h+45), backgroundColor:"#fff", zIndex:9999, border:"1px solid #aaa", padding: "10px"});
  var imgCaption = Element("P", {left:0, top:(h+20), width:w, textAlign:"right", font:"500 9pt/1.5 MS P Gothic", color:"navy", display:"none"});
  imgPop = Element("IMG", {left:10, top:10, width:w, height:h, backgroundColor:"#fff", border:"1px solid #aaa", display:"none"});
  var Screen = Element("DIV", {width:gcW, height:getDocHeight(), zIndex:999, background:"url("+ImagePath+"/screen.png)"});
  var loadingImg = Element("IMG", {left:Math.round(parseInt(imgWrap.style.width)/2), top:Math.round(parseInt(imgWrap.style.height)/2), backgroundColor:"#fff", zIndex:999});
  var closeImg = Element("IMG", {left:(parseInt(imgWrap.style.width)-68), top:15, width:75, height:16, cursor:"pointer"});
  closeImg.src = closeButton;
  closeImg.title = "閉じる";
  if(ratio < 1){
   var expand = Element("IMG", {left:12, top:12, width:34, height:34, zIndex:1000, cursor:"pointer", display:"none"});
   expand.src = expandImg; expand.title = " 実物大で表示 ";
   expand.on = false;
  }
  loadingImg.src = loadingAni;
  Screen.style.backgroundImage = "url("+screenBack+")";
  d.body.appendChild(Screen);
  
  if(ie){
   if(lt7) Screen.style.filter = "alpha(opacity=73)";
   e.target = e.srcElement;
  }
  imgWrap.appendChild(loadingImg);
  imgWrap.appendChild(imgCaption);
  imgWrap.appendChild(imgPop);
  imgWrap.appendChild(closeImg);
  d.body.appendChild(imgWrap);
  if(ratio < 1) imgWrap.appendChild(expand);
  var caption = (typeof e.target._title=="undefined") ? e.target.title : e.target._title;
  caption = caption.replace(/[\r\n]+/g,'<br/>').replace(/\s/g,'&nbsp;');
  caption = caption.split(/<br\/?>/);
  if(caption.length > 1){
   imgCaption.innerHTML = (caption[0]+"<br />"+caption[1]+" ("+ow+"×"+oh+")");
  } else imgCaption.innerHTML = '画像をクリックすると閉じます <img src="'+ImagePath+'/info2.png" width="21" height="14" alt="info" />';
  if(!kht){
   if(loadingImg.complete) { imgPop.src = path; };
   if(imgPop.complete){
    imgPop.style.display = imgCaption.style.display = "block";
    loadingImg.style.display = "none";
    if(expand) expand.style.display = "block";
   };
  } else imgPop.src = path;
  addEvent(imgPop, "load", function(){
   imgPop.style.display = imgCaption.style.display = "block";
   loadingImg.style.display = "none";
   if(expand) expand.style.display = "block";
  });
  addEvent(closeImg, "click", function(){
   if(o("article-wrapper")!=null){
    o("article-wrapper").style.visibility = "visible";
    if(lt7){ // for buggy IE6
     var _uid = d.getElementsByClassName("article", o("article-wrapper")); _uid = _uid[0].id.slice(3);
     d.body.removeChild(o("article-wrapper"));
     loadArticle(_uid);
    }
   }
   d.body.removeChild(imgWrap);
   d.body.removeChild(Screen);
   imgPop = null;
  });
  addEvent(imgPop, "click", function(){
   if(o("article-wrapper")!=null){
    o("article-wrapper").style.visibility = "visible";
    if(lt7){ // for buggy IE6
     var _uid = d.getElementsByClassName("article", o("article-wrapper")); _uid = _uid[0].id.slice(3);
     d.body.removeChild(o("article-wrapper"));
     loadArticle(_uid);
    }
   }
   d.body.removeChild(imgWrap);
   d.body.removeChild(Screen);
   imgPop = null;
  });
  if(ratio < 1){
   addEvent(expand, "click", function(){
    if(expand.on==false){
     setXY(imgWrap, 0, getScrollY());
     setWH(imgWrap, ow+3, oh);
     setWH(imgPop, ow, oh);
     setXY(closeImg, (parseInt(imgWrap.style.width)-69), null);
     expand.src = unexpandImg; expand.title = " ウィンドウのサイズに合わせる ";
     expand.on = true;
    } else {
     setXY(imgWrap, Math.round((gcW-w) / 2), Math.round((gcH-h-67) / 2 + getScrollY()));
     setWH(imgWrap, w, h+45);
     setWH(imgPop, w, h);
     setXY(closeImg, (parseInt(imgWrap.style.width)-66), null);
     expand.src = expandImg; expand.title = " 実物大で表示 ";
     expand.on = false;
    }
   });
  } //#ratio==1
  imgPop.title = "マウスクリックで閉じます";
 } //#imgPop==null
}

initCSSHover = function(){
 if(ie){
  if(o("theme-selector")){
   var root = o("theme-selector");
   addEvent(root, "mouseover", tsOver);
   addEvent(root, "mouseout", tsOut);
  }
 }
}
function tsOver(){this.className+=" over";}
function tsOut(){this.className=this.className.replace(/ over/, "");}
function noCSS(){
 if(d.styleSheets) for(var i=0,l=d.styleSheets.length;i<l;i++)d.styleSheets.item(i).disabled = true;
 for(var i=0, link = d.getElementsByTagName("link"), l = link.length; i < l; i++){
  if(link[i].rel.match(/stylesheet/i)) link[i].disabled = true;
 }
 for(var e = d.getElementsByTagName("*"), i=0, l=e.length; i < l; i++) e[i].style.cssText = "";
}
function addEvent(obj, evType, fn){
 if(!obj["_"+evType]){
  obj["_"+evType] = [];
  if(obj["on" + evType] != null) obj["_"+evType].push(obj["on" + evType]);
  obj["on" + evType] = function(e){
   var e = e || window.event;
   for(var i in this["_"+e.type]) this["_"+e.type][i].apply(this,[e]);
  }
 } else for(var i in obj["_"+evType]) if(obj["_"+evType][i]===fn) return;
 obj["_"+evType].push(fn);
 obj = null; // necessary for IE memory-leak
};
function removeEvent(obj, evType, fn){
 if(obj["_"+evType]){
  for(var i in obj["_"+evType]){
   if(obj["_"+evType][i]===fn) delete obj["_"+evType][i];
  }
 }
};

function o(a){
 if(typeof a == "object") return a;
 if(typeof a == "string"){
  if(a.match(/(^[a-zA-Z0-9_-]+$)/)){ // Unique ID
   return d.getElementById(a);
  } else if(a.match(/([a-zA-Z0-9\*]*?)\.([a-zA-Z0-9_-]+$)/)){ // tagName.className
   return d.getElementsByClassName("$2", d, "$1");
  }
 }
 return null;
};

function Element(tag, prop, parent){
 var el = d.createElement(tag.split(/[#\.]/)[0]);
 var es = el.style;
 
 es.position = "absolute";
 es.top = 0; es.left = 0;
 es.padding = 0; es.margin = 0;
 es.width = el.offsetWidth || "auto" || 0;
 es.height = el.offsetHeight || "auto" || 0;
 if(prop){
  for (var i in prop){
   if(/top|right|bottom|left|width|height/.test(i)){
    if(/px|%/.test(prop[i])) es[i] = prop[i]; else es[i] = prop[i] + "px";
   } else es[i] = prop[i];
  }
 }
 if(es.left=="" && es.right=="") es.left = 0;
 if(es.top=="" && es.bottom=="") es.top = 0;
 if(tag.split(/#/)[1]) el.id = tag.split(/#/)[1];
 if(tag.split(/\./)[1]) el.className = tag.split(/\./)[1];
 if(parent) parent.appendChild(el); else d.body.appendChild(el);
 return el;
}

function setXY(ob, x, y){
 if(!ob) return;
 ob.style.position = "absolute";
 if(x != null) ob.style.left = parseInt(x) + "px";
 if(y != null) ob.style.top = parseInt(y) + "px";
}

function setWH(ob, w, h){
 if(!ob) return;
 if(w != null) ob.style.width = parseInt(w) + "px";
 if(h != null) ob.style.height = parseInt(h) + "px";
}

function getRuntimeStyle(ob, style, css){
 var val = null;
 if(w3c){
  style = style.replace(/([A-Z])/g,"-$1").toLowerCase();
  if(css) val = ob.style[style] || 'auto';
  val = (val=='auto') ? 'auto' : d.defaultView.getComputedStyle(ob, "").getPropertyValue(style);
 } else if(ob.currentStyle){
  if(css){
   val = ob.currentStyle[style];
  } else {
   if(style=='width'){
    val = ob.offsetWidth;
   } else if(style=='height'){
    val = ob.offsetHeight;
   } else val = ob.currentStyle[style];
  } 
 } else val = ob.style[style];
 return val.toString().match(/px/) ? parseInt(val) : val;
}

Function.prototype.await = function(ms){
 var self = this;
 var f = function(){
  var a = f.arguments, t = this;
  var callee = function(){self.apply(t, a);};
  setTimeout(callee, ms);
 };
 return f;
}

Function.prototype.loop = function(ms, limit){
 var count = 0, self = this;
 return function(a){
  if(limit <= count) return;
  count++;
  self.await(ms)(a);
  arguments.callee.await(ms)(a);
 }
}

function backgroundRGB(ob){
 bg = getRuntimeStyle(ob, 'backgroundColor');
 bg = (bg==''||bg=='transparent'||bg=='inherit') ? "rgb(246, 245, 247)" : bg;
 if(bg.toLowerCase().match(/#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/)){
  return [ Number(hex2dec(RegExp.$1)), Number(hex2dec(RegExp.$2)), Number(hex2dec(RegExp.$3)) ];
 }
 if(bg.toLowerCase().match(/rgb\((\d+?), (\d+?), (\d+?)\)/)){
  return [ Number(RegExp.$1), Number(RegExp.$2), Number(RegExp.$3) ];
 }
 return [ Number(246), Number(245), Number(247) ];
}

function dec2hex(d){ return (d < 16) ? ("0" + Number(d).toString(16)) : Number(d).toString(16);}
function hex2dec(h){ return Number(parseInt(h, 16));}

function roundedEffects(ob){
 if(enableRoundedStyle){
  roundedStyle(ob);
  roundedStyle(ob, true);
 }
}

DOM = { /* window.onload alternative ref http://dean.edwards.name/weblog/2006/06/again/ */
 complete : function(){
  if(arguments.callee.done) return;
  arguments.callee.done = true;
  if(typeof _timer != 'undefined'){
   clearInterval(_timer);
   _timer = null;
  }
  DOM.onload();
 },
 check : function(){
  if(d.addEventListener){
   d.addEventListener("DOMContentLoaded", DOM.complete, false);
  }
  if(kht){ // safari
   var _timer = setInterval(function(){if(d.readyState.match(/loaded|complete/))DOM.complete();}, 50);
  }
   /*@cc_on @*/
   /*@if (@_win32)
    d.write('<script id="_decoy_" defer src="javascript:void(0)"><\/script>');
    o("_decoy_").onreadystatechange = function(){if(this.readyState=='complete')DOM.complete();};
   /*@end @*/
  addEvent(window, "load", DOM.complete);
 },
 onload : function(){}
}
DOM.check();

DOM.onload = function(){
 roundedEffects(d);
 if(lt7) initCSSHover();
 if(moz) hackFirefoxToolTip();
}


getByClass = function(className, pElement, tagName){
 var cls = gets = [], pElement = pElement || d;
 var obs = pElement.getElementsByTagName((!tagName?"*":tagName));
 var i=0, l=obs.length, j, k;
 while(i < l){
  cls = obs[i].className.split(/\s+/);
  j = 0; k = cls.length;
  while( j < k){
   if(cls[j]==className){
    gets.push(obs[i]); break;
   } j++;
  } i++;
 }
 return gets.length > 0 ? gets : null;
}


     function feeds_initialize() {
        var oidx = 0;
        var containers = getByClass("feed",document, "div");
        for( var lc=0; lc<containers.length; lc++) {
          var feed = new google.feeds.Feed(containers[lc].id);
          feed.load(function(result) {
          if (!result.error) {
            containers[oidx].innerHTML = '<ul><li><a href="'+result.feed.link+'"><font size="1">'+result.feed.title+'</font></a><br>';
            containers[oidx].innerHTML += '<font size="1">::'+result.feed.entries[0].title+'</font></li></ul>';
            oidx++;
          }
        });
      }
    }

