///
/// aboug.js ----- shirofotoのabout.html用のスクリプト[#v08061001]
///
/// Copyright (C) 2008, azan workshop
/// #v08061001  matt    New
///
/// ・依存するモジュール
/// 　　‐misc.js（本モジュールよりも先にロードすること）
///
/// ・動作確認環境
/// 　　‐Windows版   6.0、7.0
/// 　　‐Windows版   Firefox 2.0
/// 　　‐Macintosh版 Safari 3.1
///

var IFRAME_HEIGHT = 300;      // コンテンツフレームの大きさ
var IFRAME_WIDTH  = 400;

var CENTER_TOP    = 406;      // 画像を表示する中心位置
var CENTER_LEFT   = 532;
var FRAME_WIDTH   = 12;       // フレームの幅
  // フレームの幅は、フレーム画像と写真画像のマージンとなる

var FADEIN_ENABLED        = true;
var FADEIN_INIT_OPACITY   = -50;
  // 負数にするとフレームの表示とのタイムラグを設定できる
var FADEIN_LAST_OPACITY   = 100;
var FADEIN_INTERVAL       = 50;
var FADEIN_ADD_VALUE      =  5;

var SHOW_DEBUG    = false;

var fTimerId      = null;           // #v08060102
var fFadeInTimer  = null;           // #v08060801

//
// スクリプトロード時の処理
//
AddListener(window, 'load', oLoadDoc);

//---------------------------------------- イベントハンドラ
//
// oLoadDoc --- オンロードハンドラ
//
function oLoadDoc(anEvent) {
  var chk;    // #v08060102
  
  RemoveListener(window, 'load', oLoadDoc);
  
  PrepareButton();
  LoadIframe();
}

//
// LoadIframe --- 画像のロード後のイベントハンドラ
//
function LoadIframe(anEvent) {
  var div, fra, ifr;
  var ifh, ifw, frw, frh, dvt, dvl;
  
  ifr = document.getElementById("fraContents");
  
  div = document.getElementById("divFrame");
  fra = document.getElementById("imgFrame");
  
  ifh = IFRAME_HEIGHT;
  ifw = IFRAME_WIDTH;
  
  frh = ifh + FRAME_WIDTH * 2;
  frw = ifw + FRAME_WIDTH * 2;
  
  dvt = Math.floor(CENTER_TOP - frh / 2);
  dvl = Math.floor(CENTER_LEFT - frw / 2);
  
  ifr.style.top     = FRAME_WIDTH + "px";
  ifr.style.left    = FRAME_WIDTH + "px";
  ifr.style.height  = ifh + "px";
  ifr.style.width   = ifw + "px";
  
  fra.style.height  = frh + "px";
  fra.style.width   = frw + "px";
  
  div.style.top     = dvt + "px";
  div.style.left    = dvl + "px";
  
  fra.style.visibility  = "visible";
  
  FadeInContents(ifr);
}

//---------------------------------------- プライベート
//
// FadeInContents --- コンテンツフレームをフェードイン
//
function FadeInContents(anIframe) {
  var uag, fio;
  
  // sFadeIn -- フェードイン
  var sFadeIn = function() {
    var opc, oie;
    
    fio += FADEIN_ADD_VALUE;
    if (fio <= 0) return;
    
    if(fio > FADEIN_LAST_OPACITY) {
      clearInterval(fFadeInTimer);
      fFadeInTimer  = null;
      fio = FADEIN_LAST_OPACITY;
    }
    
    opc = fio / 100;
    oie = "alpha(opacity=" + fio + ")"; // for IE
    
    anIframe.style.mozOpacity = opc;
    anIframe.style.opacity    = opc;
    anIframe.style.filter     = oie;
  };
  
  // FadeInContents
  if (!FADEIN_ENABLED) {
    anIframe.style.visibility = "visible";
    return;
  }
  
  uag = navigator.userAgent;
  if(uag.indexOf("Opera") >= 0) {
    anIframe.style.visibility = "visible";
    return;
  }
  
  anIframe.style.mozOpacity = 0;
  anIframe.style.opacity    = 0;
  anIframe.style.filter     = "alpha(opacity=0)"
  anIframe.style.visibility = "visible";
  
  fio = FADEIN_INIT_OPACITY;
  if (fFadeInTimer) {
    clearInterval(fFadeInTimer);
    fFadeInTimer = null;
  }
  fFadeInTimer = setInterval(sFadeIn, FADEIN_INTERVAL);
}

//
// PrepareButton --- リンクボタンを準備する
//
function PrepareButton() {
  var hvs = new Array();
  var dws = new Array();
  var ims, img, idx, nrm, hvr, dwn;
  var ptn = /_n\./;
  
  ims = document.getElementsByTagName("img");
  
  for (idx = 0; idx < ims.length; idx++) {
    img = ims[idx];
    if (img.className != "Button") continue;
    
    nrm = img.getAttribute("src");
    hvr = nrm.replace(ptn, "_h.");
    dwn = nrm.replace(ptn, "_d.");
    
    hvs[idx] = new Image();
    hvs[idx].src = hvr;
    
    dws[idx] = new Image();
    dws[idx].src = dwn;   // chg #v08053101 old is hvr;
    
    img.onmouseover = function() {
      var ptn = /_[nhd]\./;
      var osr, nsr;
      
      osr = this.getAttribute("src");
      nsr = osr.replace(ptn, "_h.")
      this.setAttribute("src", nsr);
    }
    
    img.onmouseout = function() {
      var ptn = /_[nhd]\./;
      var osr, nsr;
      
      osr = this.getAttribute("src");
      nsr = osr.replace(ptn, "_n.")
      this.setAttribute("src", nsr);
    }
    
    img.onmousedown = function() {
      var ptn = /_[nhd]\./;
      var osr, nsr;
      
      osr = this.getAttribute("src");
      nsr = osr.replace(ptn, "_d.")
      this.setAttribute("src", nsr);
    }
    
    img.onmouseup = function() {
      var ptn = /_[nhd]\./;
      var osr, nsr;
      
      osr = this.getAttribute("src");
      nsr = osr.replace(ptn, "_n.")
      this.setAttribute("src", nsr);
      this.blur;
    }
  }
}

