(function () {
    var hd = document.createElement('div');
    var str = '';

    str += '<table cellspacing="0" id="dlsiteHeader">';
    str += '<tr>';
    str += '	<th><a href="http://blog.dlsite.com/" class="dlsiteBlog"><img src="http://parts.blog.livedoor.jp/img/user_blog/dlsite/logo_dlsite.png" alt="DLsite blog" border="0" /></a></th>';
    str += '	<td class="catprbox"><span>[ ';
    if (typeof(ld_blog_vars) == 'object' && ld_blog_vars.blog_category) {
       for (var i = 0; i < ld_blog_vars.blog_category.hierarchy.length; i++) {
          if (i > 0) { str += ' - ' }
          str += '<a href="' + ld_blog_vars.blog_category.hierarchy[i].permalink + '">' + ld_blog_vars.blog_category.hierarchy[i].name + '</a>';
       }
    }
    str += ']  </span></td>';
    str += '	<td class="dlsiteLogo"><a href="http://www.dlsite.com/" class="dlsiteLink"><img src="http://parts.blog.livedoor.jp/img/user_blog/dlsite/icon_dlsite.png" alt="DLsite" border="0" /></a><a href="http://www.dlsite.com/">DLsite.com</a></td>';
    str += '	<td class="dlsiteSearch"><form action="http://maniax.dlsite.com/fs" method="post" name="fs" target="_blank"><span><input type="hidden" name="jump" value="true" /><input type="hidden" name="target_site" value="112" /><input type="text" id="header2_query" name="ck" class="searchText" /><input type="hidden" name="blog_circle_id" value="' + ld_blog_vars.name + '" /><input type="hidden" name="blog_category" value="' + (ld_blog_vars.blog_category.hierarchy.length >= 2  ? ld_blog_vars.blog_category.hierarchy[1].name : '') + '" /><input type="image" src="http://parts.blog.livedoor.jp/img/user_blog/dlsite/btn_search.gif" alt="' + unescape('%u691C%u7D22')  + '"name="_submit" class="searchBtn" /></span></form></td>';
    str += '</tr>';
    str += '</table>';
    str += '<style type="text/css">';
    str += '#dlsiteHeader{font-size:13px;border-bottom:1px solid #ccc;background:#fff;width:100%;color:#333;}';
    str += '#dlsiteHeader th{width:1%;}';
    str += '#dlsiteHeader th img{margin:2px 10px;}';
    str += '#dlsiteHeader td.catprbox{width:1%;white-space:nowrap;}';
    str += '#dlsiteHeader td.catprbox span{margin-right:15px;}';
    str += '#dlsiteHeader a:link{color:#039;text-decoration:underline;}';
    str += '#dlsiteHeader a:visited{color:#69c;text-decoration:underline;}';
    str += '#dlsiteHeader a:active,table#dlsiteHeader a:hover{color:#f06;text-decoration:none;}';
    str += '#dlsiteHeader form{margin:0;padding:0;}';
    str += '#dlsiteHeader .dlsiteSearch{text-align:right;width:1%;white-space:nowrap;padding:0 0 0 10px;}';
    str += '#dlsiteHeader .dlsiteLogo{white-space:nowrap;text-align:right;}';
    str += '#dlsiteHeader .dlsiteLogo img{vertical-align:middle;margin:2px 5px 2px 0;}';
    str += '#dlsiteHeader .dlsiteSearch span{border-left:1px solid #ccc;padding:0 5px 0 10px;}';
    str += '#dlsiteHeader .dlsiteSearch input.searchText{font-size:12px;width:150px;border:1px solid #7f9db9;vertical-align:middle;}';
    str += '#dlsiteHeader .dlsiteSearch input.searchBtn{vertical-align:middle;margin:2px 10px 2px 2px;}';
    str += '#dlsiteHeader a.dlsiteLink,#dlsiteHeader a.dlsiteBlog{zoom:1;}';
    str += '* html #dlsiteHeader a.dlsiteBlog{filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=crop,src=http://parts.blog.livedoor.jp/img/user_blog/dlsite/logo_dlsite.png);width:96px;height:20px;cursor:pointer;}';
    str += '* html #dlsiteHeader a.dlsiteLink{filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=crop,src=http://parts.blog.livedoor.jp/img/user_blog/dlsite/icon_dlsite.png);width:16px;height:16px;vertical-align:middle;margin:2px 2px 2px 0;cursor: pointer;}';
    str += '* html #dlsiteHeader a.dlsiteLink img,* html #dlsiteHeader a.dlsiteBlog img{display: none;}';
    str += '</style>';

    hd.innerHTML = str;

    document.body.appendChild(hd);


    var add_listener = (
       function() {
          if ( window.addEventListener ) {
             return function(target, type, func) {
                target.addEventListener(type, func, false);
                return true;
             };
          } else if( window.attachEvent ) {
             return function(target, type, func) {
                target.attachEvent("on"+type, func);
                return true;
             };
          } else {
             return function(target, type, func) {
                return false;
             };
          }
       })();
    
    add_listener(document, "mouseup",
       function(){
          var txt = '';
          if (window.getSelection) { txt = window.getSelection(); }
          else if (document.getSelection) { txt = document.getSelection(); }
          else if (document.selection) { txt = document.selection.createRange().text; }

          if (txt && txt != '') {
             var elm = document.getElementById('header2_query');
             if (elm) { elm.value = txt; }
          }
       }
    );

})();
