/**
 * javascript
 *
 * @package garakuichi.com
 * @version $Id: garakuichi.js 42 2009-06-11 18:47:16Z  $
 * @copyright copyright 2009 Garakuichi.com rights reserved.
 * @author FUKAPONTA Garakuichi.com <info@garakuichi.com>
 *
 */

$(document).ready(function(){
   $('#popup').hide();
   /**
    * cell type hilight
    */
   $('*.cell').mouseover(function(){
        $(this).addClass('sel');
   });
   $('*.cell').mouseout(function(){
        $(this).removeClass('sel');
   });
   /**
    * menu LI cell hilight
    */
   $('#menu li').mouseover(function(){
        $(this).addClass('sel');
   });
   $('#menu li').mouseout(function(){
        $(this).removeClass('sel');
   });

   /**
    * comment popup
    */
   $('[rel*=respop]').click(function(event){
      return false;
   });

   $('[rel*=respop]').mouseover(function(event){
      target_id = $(this).attr('title');
      if(target_id == 'undefined'){
         return false;
      }
      ids = target_id.split(',');
      respop = '';
      i=0;
      $.each(ids, function(){
         if(i>2){
            respop += '<br />-- 以下省略 --';
            return false;
         }
         id = this;
         m = id.match(/^(\d+)-(\d+)$/);
         if(m == null){
            respop += $('#c'+id).html();
            i++
         }else{
            s = m[1]*1;
            e = m[2]*1;
            for(j=s;j<=e;j++){
               respop += $('#c'+j).html();
               i++;
               if(i>2){
                  respop += '<br />-- 以下省略 --';
                  return false;
               }
            }
         }
         return true;
      })
      p = $('#popup');
      $('#popup').empty().html(
      '<ul id="pComment"><li>'+respop+'</li></ul>').css('top',event.pageY+10).css('left',event.pageX+10);
      p.show();
      return false;
   })
   $('[rel*=respop]').mouseout(function(event){
      $('#popup').hide();
   })
//   $('.deleteCancelBtn').hide();
//   $('.deleteForm').hide();
   $('.links ul li:odd').addClass('odd');
   $('.links ul li:even').addClass('even');
   $('.links ul li a').attr('target', '_blank');
   select_up_type();
});

var options = 'scrollbars=yes';

function img(bbs_code,thread_id,comment_id){
   url = '/' + bbs_code + '/img/' + thread_id + '/' + comment_id;
   if(!window.open(url, 'img', options)){
      location.href = url;
   }
   return true;
}

function backOrClose(){
   if(self.name=='mainFrame'){
      history.back();
   }else{
      window.close();
   }
   return false;
}

function select_up_type(){
    type = $("input[@name='up_type',@type='radio']:checked").val();
    $('#up_img').hide();
    $('#up_youtube').hide();
    $('#up_woopie').hide();
    $('#up_'+type).show();
}

function delete_form(i, mode){
   if(mode){
      $('#deleteBtn'+i).hide();
      $('#deleteForm' + i).show();
//      $('#deleteCancelBtn' + i).show();
   }else{
      $('#deleteBtn'+i).show();
      $('#deleteForm' + i).hide();
//      $('#deleteCancelBtn' + i).hide();
   }
}