function resizeIMG(o, w){
  w = w || 530;

  if(o.width > w){
    o.resized = true;
    o.width = w;
  }
}

// 小屋未用，for 哈啦區
function attachIMG(o, event){
  if(!getCookie('BAHAID') && 'Y' == attachMediaLogin){
    if(confirm('您需要先登入才能觀看喔')){
      o.href = "https://user.gamer.com.tw/login.php";
      return true;
    }
    else{
      return false;
    }
  }

  imgid = 'IMG'+o.id;
  newHTML = '<IMG src="'+o.id+'" border=0 onload=resizeIMG(this)>';

  if('click' == event){
    if(newHTML.toLowerCase().replace(/["]/g,'').substr(0, 28) != o.innerHTML.toLowerCase().replace(/["]/g,'').substr(0, 28)){
      o.innerHTML = newHTML;
      return false;
    }
    else if(o.id != o.href){
      confirmLink( o.href );
      return false;
    }
    else{
      window.open( o.href , '', '');
      return false;
    }
  }
  else if('show' == event){
    if(newHTML.toLowerCase().replace(/["]/g,'') != o.innerHTML.toLowerCase().replace(/["]/g,'')){
      o.innerHTML = newHTML;
      return false;
    }
  }

  return false;
}

function attachMOVIE(o){
  if(!getCookie('BAHAID') && 'Y' == attachMediaLogin){
    if(confirm('您需要先登入才能觀看喔')){
      o.href = "https://user.gamer.com.tw/login.php";
      return true;
    }
    else{
      return false;
    }
  }
  
  src = o.id;

  if(src == o.href){
    embedid = 'embed'+src;
    newHTML = '<embed id="'+embedid+'" src="'+src+'" quality="best" wmode="transparent" width="425" height="355"></embed>';
    o.innerHTML = newHTML;
    document.getElementById(embedid).src = src;
    o.href="javascript:void(0)";
  }

  return false;
}

function showMediaClick(t){
  if('movie' == t){
    //document.write('<div style="width:340; height:273; border-style:1pt solid #ff9900">請點選觀看影片</div>');
    var movie = document.getElementsByName('attachMovieName');
    var movieLength = movie.length;
    for (i=0; i<movieLength; i++) {
      attachMOVIE(movie[i]);
    }
  }else if('image' == t){
    var images = document.getElementsByName('attachImgName');
    var imgLength = images.length;
    for (i=0; i<imgLength; i++) {
      attachIMG(images[i], 'show');
    }
  }
}

// 小屋 重設圖片大小
function resizeIMG2(){
  oo = document.getElementsByTagName("div");

  for(var i=0; i<oo.length; i++){
    if( 'OUTPIC1' == oo[i].id )
    {
      o = oo[i].firstChild;
      
      if( o.firstChild ){
        if( 'IMG' === o.firstChild.nodeName ){
          resizeIMG( o.firstChild, 704 );
        }
      }else{
        if( 'IMG' === o.nodeName ){
          resizeIMG( o, 704 );
        }
      }
    }
  }

  if( document.getElementById('blogContent') ){
    //新版的文章改成直接轉內文blogContent這個div下所有的IMG tag
    ii = document.getElementById('blogContent').getElementsByTagName("IMG");
    for(var i=0; i<ii.length; i++){
      resizeIMG( ii[i], 704 );
    }
  }
}
