/* ---------- 名入れイメージ画像表示用スクリプト ---------- */



// イメージ画像と型番・色テキスト表示部分のタグを追加し、対応表セルと表内リンクにイベントを定義
function NaireGalleryIns(){
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;

  var NoteParagraphID = "sampledispnote";
  var TargetTableID   = "print_atmosphere_gallery";

  if (!document.getElementById(NoteParagraphID)) return false;
  if (!document.getElementById(TargetTableID)) return false;

  // [prototype.jsの機能で]説明テキストの終了タグの後に指定した要素を追加
  var AddDefaultImage = '<p id="sampimg"><img id="sample" src="/images/print_sample_default.gif" alt="" /></p>';
  new Insertion.After(NoteParagraphID,AddDefaultImage);
  if (!document.getElementById("sampimg")) return false;

  // [prototype.jsの機能で]id="sampimg"の終了タグの後に指定した要素を追加
  var AddNoteDefinitionList = '<dl><dt id="sampcommodity">ライター型番：</dt><dt id="sampcolor">本体色：</dt><dt id="sampprintcolor">印刷色：</dt></dl>';
  new Insertion.After("sampimg",AddNoteDefinitionList);
  if (!document.getElementById("sampcommodity")) return false;

  var TargetTable = document.getElementById(TargetTableID);
  var TargetCells = TargetTable.getElementsByTagName("td");//alert(TargetCells.length);

  // リンクを含むセルとその中のリンクにイベントを定義
  for (var i=0; i<TargetCells.length; i++){
       var CellInsideAnchors = TargetCells[i].getElementsByTagName("a");//alert(CellInsideAnchors.length);
       if (CellInsideAnchors.length != 0) {
           TargetCells[i].oldClassName = TargetCells[i].className;
           TargetCells[i].onmouseover  = function () {this.className = "highlight hover";};
                                                      // ※テーブルハイライトJSによるclass指定を上書き
           TargetCells[i].onmouseout   = function () {this.className = this.oldClassName;};
           TargetCells[i].onclick      = function () {showPic(this.getElementsByTagName("a")[0]);};

           for (var links=0; links<CellInsideAnchors.length; links++) {
                CellInsideAnchors[links].onclick = function () {showPic(this);return false;}
           }
       };
  }	// for end

}	// function NaireGalleryIns() end


// リンクまたはセルをクリックしたときにイメージ画像と型番・色テキストを変更
function showPic(whichpic) {
  if (!document.getElementById("sample")) return true;

  // クリックされたリンクのhref属性を取得
  var source = whichpic.getAttribute("href");

  // id="sample"（名入れイメージ画像）のsrc属性を書き換え
  var placeholder = document.getElementById("sample");
  placeholder.setAttribute("src",source);

  if (!document.getElementById("sampimg")) return false;

  // リンクのtitle属性の値を／で分割して配列化
  if (whichpic.getAttribute("title")) {
      var text = whichpic.getAttribute("title");
      var TitletextArray = text.split('／');
  } else {
      var text = "";
  }

  // id="samppcommodity"の子ノードテキストを書き換え
  var Sampcommodity = document.getElementById("sampcommodity");
  if (Sampcommodity.firstChild.nodeType == 3) Sampcommodity.firstChild.nodeValue = TitletextArray[0];

  // id="sampcolor"の子ノードテキストを書き換え
  var Sampcolor = document.getElementById("sampcolor");
  if (Sampcolor.firstChild.nodeType == 3) Sampcolor.firstChild.nodeValue = TitletextArray[1];

  // id="sampprintcolor"の子ノードテキストを書き換え
  var Sampprintcolor = document.getElementById("sampprintcolor");
  if (Sampprintcolor.firstChild.nodeType == 3) Sampprintcolor.firstChild.nodeValue = TitletextArray[2];

  return false;	// デフォルトアクションの抑止（リンク先へ飛ばないようにする）
}	// function showPic() end

