(function(){
  var host = "http://tategakibunko.mydns.jp";
  var tmp = document.getElementsByTagName("iframe");
  var tbcount = 0;
  for( var i = 0; i < tmp.length; i++ ){
    if(tmp[i].className == "tb-thumb-frame"){
      tbcount++;
    }
  }
  var par = "?v=1";
  var qid = "random";
  var cgi = "thumb";
  if(typeof nid != 'undefined'){
    qid = nid;
  }
  if(typeof width != 'undefined'){
    par += "&w=" + width;
  } else {
    witdh = 180;
  }
  if(typeof height != 'undefined'){
    par += "&h=" + height;
  } else {
    height = 300;
  }
  if(typeof novel_font_color != 'undefined'){
    par += "&nfc=" + novel_font_color.replace("#","");
  }
  if(typeof novel_bg_color != 'undefined'){
    par += "&nbc=" + novel_bg_color.replace("#","");
  }
  if(typeof link_color != 'undefined'){
    par += "&lc=" + link_color.replace("#","");
  }
  if(typeof border_color != 'undefined'){
    par += "&bc=" + border_color.replace("#","");
  }
  if(typeof font_size != 'undefined'){
    par += "&fsz=" + font_size;
  }
  if(typeof font_no != 'undefined'){
    par += "&fno=" + font_no;
  }
  if(typeof font_family != 'undefined'){
    par += "&fname=" + encodeURIComponent(font_family);
  }
  if(typeof pager_link_color != 'undefined'){
    par += "&plc=" + pager_link_color.replace("#","");
  }
  if(typeof ruby_color != 'undefined'){
    par += "&rc=" + ruby_color.replace("#","");
  }
  if(typeof auth != 'undefined'){
    par += "&auth=" + encodeURIComponent(auth);
  }
  if(typeof tag_name != 'undefined'){
    par += "&tag_name=" + encodeURIComponent(tag_name);
  }
  if(typeof summary_enable != 'undefined'){
    par += "&sum=" + summary_enable;
  }
  if(typeof background_image != 'undefined'){
    par += "&bgimg=" + encodeURIComponent(background_image);
  }
  if(typeof shell_bg_color != 'undefined'){
    par += "&shbc=" + shell_bg_color.replace("#","");
  }
  if(typeof shell_font_color != 'undefined'){
    par += "&shc=" + shell_font_color.replace("#","");
  }
  var url = [host, cgi, qid + par].join("/");

  //同一ページへのサムネールは3つまで許可
  if(tbcount < 3){
    var val = ("<iframe class='tb-thumb-frame' style='margin:0; padding:0;'" +
	       " allowtransparency=true width=" +
	       (width + 2) +
	       " height=" +
	       (height + 10) +
	       " frameborder=0 " +
	       " src ='" +
	       url + "'></iframe>");
  } else {
    var val = "<a target='_blank' href='" + url + "'>open novel</a>";
  }
  document.open();
  document.write(val);
  document.close();
})()
