
var imgWinPad = 45 ;
var imgWinMRatio = 0.85 ;

   function openImg( inode ){

      if( inode.nodeName != 'img' ){

      var n = inode.childNodes ;

      for( var i = 0 ; i < n.length ; i++ )
         if( n[i].getAttribute('name') == 'lbc_img' ){
         inode = n[i] ;
         break ;
         }

      }

   openImgWin( inode.getAttribute('src') , inode.width , inode.height ) ;

   }

   function openImgWin( src , width , height ){

   var maxW = screen.availWidth * 0.85 ;
   var maxH = screen.availHeight * 0.85 ;

   window.open( src , "_blank" , "toolbar=no, location=yes, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width="+( width > maxW ? maxW : width+imgWinPad )+", height="+( height > maxH ? maxH : height+imgWinPad ) );

   return false;

   }

   function LoadImg( anode ){

      if( anode.getAttribute('class') == 'fold_img' ){
      anode.setAttribute('title',lang_img_origin) ;
      anode.innerHTML = '<img name="lbc_img" src="'+anode.getAttribute('href')+'" alt="'+anode.getAttribute('href')+'" onload="CheckImgSize(this);" />' ;
      anode.className = '' ;
      }

   }

var singleClDelay = 400 ;
var doubleClDelay = 1200 ;
var loadingTs = new Array() ;
var tn ;

   function LoadLBCImg( anode ){

   var name = anode.getAttribute('name') ;

      // if this image had clicked once, then load all images
      for( var i = 0 ; i < loadingTs.length ; i++ )
         if( loadingTs[ i ][0].indexOf( name ) >= 0 ){

         //loadingTs[ i ][0] = '' ;
            //if( LoadALLLBCImg( anode ) )openImg( anode ) ;
         return LoadALLLBCImg( anode ) ; // false

         }

      // check with attribute class for check image loaded or not
      if( anode.getAttribute('class') == 'fold_img' ){

         // never clicked before and image not loaded
      loadingTs[ loadingTs.length ] = new Array( name , anode ) ;
      setTimeout( "loadingTs.shift() ;" , doubleClDelay );

         // Laod this img
      setTimeout( "LoadImg( loadingTs[ loadingTs.length-1 ][1] ) ;" , singleClDelay );
      //LoadImg( anode );

      }else
      openImg( anode ); // setTimeout( "loadingTs.shift() ; if( tn[0] != '' ) openImg( tn[1] ) ;" , doubleClDelay );

   return false ;
   }

var loadedNames = new Array() ;

   function LoadALLLBCImg( anode ){

   var name = anode.getAttribute('name') ;

      for( var i = 0 ; i < loadedNames.length ; i++ )
         if( loadedNames[ i ].indexOf( name ) >= 0 )
         return true ;

   loadedNames[ loadedNames.length ] = name ;

   var anode = document.getElementsByName( name );

      for( var i = 0 ; i < anode.length ; i++ )
      LoadImg( anode[i] );

   return false ;

   }

   function CheckImgSize( inode ){

   var resizeRatio = 1 ;
   var width = inode.width ;
   var height = inode.height ;

      if( width > height ){
         if( width > upl_img_pix )
         resizeRatio = upl_img_pix / width ;
      }else{
         if( height > upl_img_pix )
         resizeRatio = upl_img_pix / height ;
      }

      if( arguments.length > 1 ) resizeRatio *= arguments[1] ;

      if( resizeRatio < 1 ){
      inode.width = width * resizeRatio ;
      inode.height = height * resizeRatio ;
      inode.className = 'img_resized' ;
      }

   }

   function CheckAllImgSize(){

   var inode = document.getElementsByName( 'lbc_img' );

      for( var i = 0 ; i < inode.length ; i++ )
      CheckImgSize( inode[i] );

   }

   function expandMedia( node , type ){

   var lasttext = node.nextSibling ;
      if( !String(lasttext.tagName).match(/span/i) )
      return true ;

   var mediablock = lasttext.nextSibling ;
      if( !String(mediablock.tagName).match(/div/i) )
      return true ;

      if( !mediablock.innerHTML ){

      var tmp = node.innerHTML ;
      node.innerHTML = lasttext.innerHTML ;
      lasttext.innerHTML = tmp ;
      mediablock.style.display = "block" ;

      var embedded

      //** IMAGE SECTION
         if( type == "image" )
         mediablock.innerHTML = "<img name=\"lbc_img\" border=\"0\" src=\""+arguments[2]+"\" alt=\""+arguments[2]+"\" onload=\"CheckImgSize(this);\" />" ;
      //** VIDEO SECTION
         else if( embedded=streamEmbedded(type, arguments[2], arguments[3], arguments[4]) )
         mediablock.innerHTML = embedded ;

      }else if( String(mediablock.style.display).match(/none/i) ){
      var tmp = node.innerHTML ;
      node.innerHTML = lasttext.innerHTML ;
      lasttext.innerHTML = tmp ;
      mediablock.style.display = "block" ;
      }else{
      var tmp = node.innerHTML ;
      node.innerHTML = lasttext.innerHTML ;
      lasttext.innerHTML = tmp ;
      mediablock.style.display = "none" ;
      }

   return false ;
   }

   function blockActivate( buttNode ){

   var textNode = buttNode ;
      while( !String(textNode.className).match(/title/i) )
      textNode = textNode.parentNode ;
      while( !String(textNode.className).match(/text/i) )
      textNode = textNode.nextSibling ;

      if( String(textNode.style.display).match(/none/i) ){
      buttNode.innerHTML = "-" ;
      textNode.style.display = "block" ;
      }else{
      buttNode.innerHTML = "+" ;
      textNode.style.display = "none" ;
      }

   return false ;
   }

   function expandAttachment( buttNode ){

   var titleNode = buttNode ;
      while( !String(titleNode.className).match(/sub_atch_title/i) )
      titleNode = titleNode.parentNode ;

   var imageBlock = titleNode ;
      while( !String(imageBlock.className).match(/sub_atch hidden/i) )
      imageBlock = imageBlock.nextSibling ;

   titleNode.style.display = "none" ;
   imageBlock.className = "sub_atch b_left" ;

   return false ;
   }

var images = new Array() ;
   function loadimg( imgnode ){

   imgnode.onload = "" ;

   var value = ( arguments[1] ? arguments[1] : "" ) ;
   var ablock = imgnode.parentNode ;

      // get image path from input name by insert_path
      if( !value ){
      var block = ablock.parentNode ;
      var blockNodes = block.childNodes ;
         for( var i=0 ; i<blockNodes.length ; i++ )
            if( String(blockNodes[i].name).match(/insert_path/i) ){
            value = blockNodes[i].value ;
            break ;
            }
      }

      if( value ){

      var l = images.length ;
      images.push(new Array( ( arguments[2] ? arguments[2] : 98 ) , ablock , imgnode , new Image() )) ;

         function trimimg(l){
            if( images[l] == "" ) return;
         var b = images[l][0];
         var a = images[l][1];
         var m = images[l][2];
         var n = images[l][3];
         m.style.display="none";
         n.onload="";
         var w = n.width;
         var h = n.height ;
         var r = w/h ;
         n.className = m.className ;
         n.width = w ;
         n.height = h ;
         n.style.marginLeft = "-"+Math.round(w/2)+"px";
         n.style.marginTop = "-"+Math.round(h/2)+"px";
            if( w > b && h > b ){
               if( r < 1 ){
               n.width = b ;
               n.height = h = Math.round(b*(1/r)) ;
               n.style.marginTop = "-"+Math.round(h/2)+"px";
               n.style.marginLeft = "-"+Math.round(b/2)+"px";
               }else{
               n.width = w = Math.round(b*r) ;
               n.height = b ;
               n.style.marginTop = "-"+Math.round(b/2)+"px";
               n.style.marginLeft = "-"+Math.round(w/2)+"px";
               }
            }
         a.appendChild(n) ;
         images[l] = "";
         }

      eval('images[l][3].onload = (function(){trimimg('+l+')})') ;

      images[l][3].src = value ;
      }

   }

var more_actives_node=null;
   function more_actives( node, section, cls, blog, time, prev_time ){
   node.innerHTML='<div class="blog_more_actives block_padd t_center"><img src="templates/images/loading40x40.gif" /><div class="line_pab font_size_middle color_note">'+more_actives_loading_text+'</div></div>';
   more_actives_node=node;
   more_actives_trigger_loading=true;
   x_show_more_actives(section, cls, blog, time, prev_time, more_actives_load);
   return false;
   }

   function more_actives_load( posts ){
      if( more_actives_node ){
      more_actives_trigger_loading=false;
      more_actives_next_section++;
      more_actives_node.innerHTML=posts[0];
      more_actives_node.onclick="";
      more_actives_node=null;

      more_actives_prev_time=posts[1];

      more_actives_trigger_waiting=true;
      setTimeout("more_actives_trigger_waiting=false;",more_actives_trigger_min_interval);
      }
   }

// always return 1, except at non-default zoom levels in IE before version 8
  function GetZoomFactor () {
      var factor = 1;
      if (document.body.getBoundingClientRect) {
              // rect is only in physical pixel size in IE before version 8 
          var rect = document.body.getBoundingClientRect ();
          var physicalW = rect.right - rect.left;
          var logicalW = document.body.offsetWidth;

              // the zoom level is always an integer percent value
          factor = Math.round ((physicalW / logicalW) * 100) / 100;
      }
      return factor;
  }

  function GetScrollPositions () {
      if ('pageXOffset' in window) {  // all browsers, except IE before version 9
          var scrollLeft =  window.pageXOffset;
          var scrollTop = window.pageYOffset;
      }
      else {      // Internet Explorer before version 9
          var zoomFactor = GetZoomFactor ();
          var scrollLeft = Math.round (document.documentElement.scrollLeft / zoomFactor);
          var scrollTop = Math.round (document.documentElement.scrollTop / zoomFactor);
      }
      return new Array(scrollLeft, scrollTop);
  }

   function getDocHeight() {
       var D = document;
       return Math.max(
           Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
           Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
           Math.max(D.body.clientHeight, D.documentElement.clientHeight)
       );
   }

   function getViewHeight() {
   return ( window.innerHeight ?
            window.innerHeight :
            (  document.body.clientHeight ? 
               document.body.clientHeight :
               (  document.documentElement.clientHeight ? 
                  document.documentElement.clientHeight :
                  -1
                  )
               )
            );
   }

var quick_reply_def_value=null;
var quick_reply_def_color=null;

   function quick_reply_rsz( input ) {
   var lines=input.value.split('\n');
   input.style.height=null;
   input.style.width=null;
      if( arguments.length>1 )
      input.rows=2;
      else
      input.rows=lines.length>1 ? lines.length : 2 ;
   }

   function quick_reply_shw(input, id){
      if( !quick_reply_def_value || input.value==quick_reply_def_value ){
         if( !quick_reply_def_value ){
         quick_reply_def_value=input.value;
         quick_reply_def_color=input.style.color;
         }
      input.value='';
      input.style.color='#000';
      input.rows=2;
      document.getElementById(id+'_reply_form_thumb').style.display='block';
      document.getElementById(id+'_reply_form_submit').style.display='block';
      }
   }

   function quick_reply_hid(input, id){
      if( input.value=='' ){
      input.rows=1;
      input.value=quick_reply_def_value;
      input.style.color=quick_reply_def_color;
      document.getElementById(id+'_reply_form_thumb').style.display='none';
      document.getElementById(id+'_reply_form_submit').style.display='none';
      }
   }

var submited_posts=new Array();

   function quick_reply_submit(id, aid, last_rid){
      if(   quick_reply_find_submited(id, false) ||
            document.getElementById(id+'_reply_form_input').value=='' )
      return ;
   submited_posts.push(id);
   document.getElementById(id+'_reply_form_input').disabled='disabled';
   document.getElementById(id+'_reply_form_submit').style.display='none';
   document.getElementById(id+'_reply_form_sending').style.display='block';
   document.getElementById(id+'_reply_form_status').style.display='none';
   x_brief_reply(id, aid, document.getElementById(id+'_reply_form_input').value, last_rid, quick_reply_callback);
   }

   function quick_reply_callback( ret ){

      if( !quick_reply_find_submited(ret[1], true) )
      return ;

   var input=document.getElementById(ret[1]+'_reply_form_input');
   input.disabled='';
   var submit=document.getElementById(ret[1]+'_reply_form_submit');
   submit.style.display='block';
   document.getElementById(ret[1]+'_reply_form_sending').style.display='none';

      if( ret[0]=='t' ){
      input.value='';
      quick_reply_hid(input, ret[1]);
      var append=document.createElement('div');
      append.innerHTML=ret[2];
      document.getElementById(ret[1]+'_reply_form_append').appendChild(append);
      submit.setAttribute("onclick", "quick_reply_submit('"+ret[1]+"', '"+ret[3]+"', '"+ret[4]+"');");
      }else{
      var status=document.getElementById(ret[1]+'_reply_form_status');
      status.innerHTML=ret[2];
      status.style.display='block';
      }
   }

   function quick_reply_find_submited( id , del ){
      for( var i=0 ; i<submited_posts.length ; i++ ){
         if( submited_posts[i]==id ){
            if( del )
            submited_posts[i]=null;
         return true;
         }
      }
   return false;
   }

   function expand_more_replies( node , id , aid , expand_depth , expand_nxt_rid , time ){

   var nodes=node.parentNode.childNodes;
      for( var i = 0 ; i < nodes.length ; i++ )
         if( String(nodes[i].tagName).match(/img/i) ){
            if( !String(nodes[i].style.display).match(/none/i) )
            return false;
         nodes[i].style.display='inline';
         break ;
         }

   x_expand_more_replies(id, aid, expand_depth, expand_nxt_rid, time, expand_more_replies_callback);

   return false;
   }

   function expand_more_replies_callback( ret ){
   var expandContain=document.getElementById(ret[1]+'_expand_bft_'+ret[2]);
   var triggerContain=expandContain.previousSibling;
      while( !String(triggerContain.tagName).match(/div/i) )
      triggerContain=triggerContain.previousSibling;

      if( ret[0]=='t' ){
      triggerContain.style.display='none';
      expandContain.innerHTML=ret[3];

      }else{
      var nodes=triggerContain.childNodes;
         for( var i = 0 ; i < nodes.length ; i++ )
            if( String(nodes[i].tagName).match(/img/i) ){
            nodes[i].style.display='none';
            break ;
            }
      }
   }

   function expand_more_text( node , id , aid ){

   var imgNode=node.nextSibling;
      while( !String(imgNode.tagName).match(/img/i) )
      imgNode=imgNode.nextSibling;

      if( !String(imgNode.style.display).match(/none/i) )
      return false;
   imgNode.style.display='inline';

   x_expand_more_text(id, aid, expand_more_text_callback);

   return false;
   }

   function expand_more_text_callback( ret ){

   var textContain=document.getElementById(ret[1]+'_text');

      if( ret[0]=='t' )
      textContain.innerHTML=ret[2];
   }

   function expand_more_attach( node , id , aid ){

   var imgNode=node.nextSibling;
      while( !String(imgNode.tagName).match(/img/i) )
      imgNode=imgNode.nextSibling;

      if( !String(imgNode.style.display).match(/none/i) )
      return false;
   imgNode.style.display='inline';

   x_expand_more_attach(id, aid, expand_more_attach_callback);

   return false;
   }

   function expand_more_attach_callback( ret ){

   var attachContain=document.getElementById(ret[1]+'_attach');

      if( ret[0]=='t' )
      attachContain.innerHTML=ret[2];
   }

