/**
 * @copyright 2009 NTT Communications
 * @author    NTT Communications CO.,LTD.
 * @version   $Id$
 * @link      http://photofriend.jp/
 */

/**
 * @requires prototype.js
 * @description 写真一覧表示制御用JS
 */

var ie = false;
var ie6 = false;
var ie7 = false;
var opera = window.opera ? true : false;

// 以下はieバージョン判定用コード
/*@cc_on
  ie = true;
  if (window.XMLHttpRequest) {
    ie7 = true;
  } else {
    ie6 = true;
  }
//alert("ie:" + ie + " ie6:" + ie6 + " ie7:" + ie7);
@*/

var C_NOIMAGE_BKCOLOR = "#c0c0c0";

//var C_NOIMAGE_MSG 	= "<img src='/images/ajax-loader.gif'/>";
//var C_NOIMAGE_MSG 	= "<p>画像未取得</p>";

var C_PICT_TITLE_LENGTH = 0;   // =0: auto >0: limit to C_PICT_TITLE_LENGTH.

/**
 * 画像を取得していない時に表示する情報を設定
 * @param title エスケープ済みタイトル情報
 * @return 加工した差し込みタグ
 */
function pf_photoview_title_callback(title)
{
    return "<img src='/images/progress_90x90.gif' alt='" + title + "' title='" + title +"'/>";
//    return C_NOIMAGE_MSG; // alt属性値などを設定しない場合は、文字列定数を返してもよい。
}

var C_DIVTAG_NAME_FOR_IMG = "name_pictArea";
var C_DIVTAG_IDBASE_FOR_IMG = "id_pictArea_";
var C_DIVTAG_IDBASE_FOR_TITLE = "id_titleArea_";
var C_MARGIN = 5;
var C_TITLE_BAR_HEIGHT = 25;
var C_PICT_HEIGHT = 90;
var C_PICT_WIDTH = 90;
var C_PICT_TITLE_HEIGHT = 16;

var C_NOIMAGE_CLASS = "delayed-image";

var C_OCCUPATION_TIME = 10;         // 次回処理占有時間までの間隔 = 10ms

// タイマー関連
var m_timerId = 0;
var m_timerEnabled = false;
var m_timerKicked = false;
var m_pict_timerId = 0;
var m_pict_timerEnabled = false;

// 表示関連
var heightMargin = 100;
var widthMargin = 100;
var m_boxHeight = 0;
var resizable = false;
var m_preScrollTop = -1;	//スクロールトップ(前回の位置)
var m_id = -1;
var m_slide_show_xml = null;  // スライドショー情報(xml)
var m_photo_filename_list = null;
var m_photo_box_index = 0;          // 次回占有時間に処理するPHOTOBOXの開始インデックス
var m_photo_creation_cnt = 0;      // PHOTOBOX一括生成数（最適化後）
var m_columns = 0;                  // 計測カラム数
var m_vskip = 0;                    // 行間

/**
 * フォトビューアを起動する
 * @param flg
 * @param id
 */
function pf_photoview_dispBox(flg, id)
{
    // 初期化
    m_timerId = 0;
    m_timerEnabled = false;
    m_timerKicked = false;
    m_pict_timerId = 0;

    m_preScrollTop = -1;	//スクロールトップ(前回の位置)
    m_id = -1;
    m_slide_show_xml = null;  // スライドショー情報(xml)
    m_photo_filename_list = null;
    m_photo_box_index = 0;        // 次回占有時間に処理するPHOTOBOXの開始インデックス
    m_photo_creation_cnt = 0;     // PHOTOBOX一括生成数（最適化後）
    m_boxHeight = 0;

    m_columns = 0;
    m_vskip = 200;                    // 行間

//    alert(flg + "," + id);
    m_id = id;

    // SELECTコントロール表示
    if (flg == 1) {
        pf_photoview_selectVisibility('hidden');
    } else {
        pf_photoview_selectVisibility('visible');
    }

    // ダイアログサイズ調整
    pf_photoview_onResize();
    pf_photoview_onResize4Shadow();

    // ダイアログ領域表示
    var obj = document.getElementById('id_region');
	if ( flg == 0 ) {
		obj.style.visibility = 'hidden';
	} else {
		obj.style.visibility = 'visible';
	}

    obj.style.zIndex = 100;

    // バックグラウンド表示
    obj = document.getElementById('id_back');
	if ( flg == 0 ) {
		obj.style.visibility = 'hidden';
	} else {
		obj.style.visibility = 'visible';
	}

	obj = document.getElementById('id_con');
    obj.style.zIndex = 200;

	if ( flg == 0 ) {
		obj.style.visibility = 'hidden';
	} else {
		obj.style.visibility = 'visible';
	}

    // メッセージバー表示
	obj = document.getElementById('id_bar');

//	obj.style.height = 20;
//	obj.style.width = "100%";

	if ( flg == 0 ) {
		obj.style.visibility = 'hidden';
	} else {
		obj.style.visibility = 'visible';
	}

	obj = document.getElementById('id_box');

    // 全子ノードの削除
    pf_photoview_deleteChilds(obj);
    
	if ( flg == 0 ){
        // イベントハンドラの削除
        if (resizable) {
            pf_photoview_removeEventListenerFunc('resize', pf_photoview_onResize, false);
        }
        if (ie6) {
            // IE6では、position: fixed; が正常動作しないため。
            pf_photoview_removeEventListenerFunc('resize', pf_photoview_onResize4Shadow, false);
            pf_photoview_removeEventListenerFunc('nscroll', pf_photoview_onScroll, false);
        }

        // タイマー禁止
        clearTimeout(m_timerId);
        m_timerEnabled = false;
        m_timerId = 0;
        clearTimeout(m_pict_timerId);
        m_pict_timerEnabled = false;
        m_pict_timerId = 0;
        // ダイアログをかくす
		obj.style.visibility = 'hidden';
		obj.innerHTML = "";
	} else {
        // タイマー許可
        m_timerEnabled = true;
        m_pict_timerEnabled = true;

        // イベントハンドラ登録
        if (resizable) {
            pf_photoview_addEventListenerFunc('resize', pf_photoview_onResize, false);
        }
        if (ie6) {
            // IE6では、position: fixed; が正常動作しないため。
            pf_photoview_addEventListenerFunc('resize', pf_photoview_onResize4Shadow, false);
            pf_photoview_addEventListenerFunc('scroll', pf_photoview_onScroll, false);
        }
        // ダイアログ表示
		obj.style.visibility = 'visible';

        // 写真一覧情報取得リクエスト
        var url = "/photo/allview/" + m_id;
        var myAjax = new Ajax.Request(
                url,
                {
                    method: 'post',
                    onComplete: pf_photoview_showResponse
                });
    }
}

/**
 * 写真一覧情報の取得
 * @param originalRequest
 */
function pf_photoview_showResponse(originalRequest)
{
    m_slide_show_json = originalRequest.responseText;
    m_photo_filename_list = eval(m_slide_show_json);

    if (m_photo_filename_list != null && m_photo_filename_list.length > 0 ) {
        m_pict_timerId = setTimeout( function(){pf_photoview_loadPictBox(m_photo_filename_list)}, C_OCCUPATION_TIME );
    }
}

/**
 * イベントハンドラ登録
 */
function pf_photoview_addEventListenerFunc(evname, func, flag)
{
    if (ie) {
        window.attachEvent('on' + evname, func);
    } else {
        window.addEventListener(evname, func, flag);
    }
}

/**
 * イベントハンドラ削除
 */
function pf_photoview_removeEventListenerFunc(evname, func, flag)
{
    if (ie) {
        window.detachEvent('on' + evname, func);
    } else {
        window.removeEventListener(evname, func, flag);
    }
}

/**
 * 各画像をロード
 */
function pf_photoview_loadPictBox(photos)
{
    clearTimeout(m_pict_timerId);
    m_pict_timerId = 0;

    if (photos == null || photos.length == 0) {
        return;
    }

    var pictCnt =  photos.length;
	var containarObj = document.getElementById('id_box');

	//cssは量があるので文字列で一括して与える
    var css = "padding: 0px; border-width: 0px; border-style: solid; border-color: #FF0000;width: " + C_PICT_HEIGHT + "px; height: " + (C_PICT_HEIGHT + C_PICT_TITLE_HEIGHT) + "px; overflow: hidden; float: left;";
    css = css + "margin-top: " + C_MARGIN + "px;";
    css = css + "margin-left: " + C_MARGIN + "px;";

    // 残処理数を算出
    var rest = pictCnt - m_photo_box_index;
    if (m_photo_creation_cnt == 0) {
        m_photo_creation_cnt = rest;
    }

    var first_left = -1;
    var first_top = -1;
    var current_column_idx = -1;
    //alert("rest = " + rest + ", m_photo_creation_cnt = " + m_photo_creation_cnt);

    // 描画
	for (var i = 0; i < Math.min(rest, m_photo_creation_cnt); i++) {
        var id = photos[m_photo_box_index + i].id;
        var title = photos[m_photo_box_index + i].title;

        var a = pf_photoview_createPictBox(m_photo_box_index + i, id, title, css);
        containarObj.appendChild(a);
        current_column_idx++;

        if (m_columns < 1) {
            if (first_left < 0) {
                // 最初のPHOTOBOXの位置を記憶
                first_left = a.offsetLeft;
                first_top = a.offsetTop;
//                alert("First_Left = " + first_left);
            } else {
                // 最初のPHOTOBOXと同じ位置かチェック
                if (first_left == a.offsetLeft) {
                    // 改行したので、カラム数を保持。
                    m_columns = current_column_idx;
                    m_vskip = a.offsetTop - first_top;
                    m_photo_creation_cnt = m_columns * 2;
//                    alert("m_columns = " + m_columns + ", m_photo_creation_cnt = " + m_photo_creation_cnt);
                }
            }
        }

        // タイトルをシュリンクする
        var titleid = C_DIVTAG_IDBASE_FOR_TITLE + (m_photo_box_index + i);
        var shrinked_title = title;

//        alert("titleid = " + titleid + ", title = " + pf_photoview_meta2escape(title));
        var titleObj = document.getElementById(titleid);
//        alert("offsetWidth = " + titleObj.offsetWidth);
        while (C_PICT_TITLE_LENGTH == 0 && titleObj.offsetWidth > C_PICT_WIDTH) {
            // 幅が広いので切り詰める
            if (shrinked_title.substring(shrinked_title.length - 1) == ";") {
                // 実体、数値参照かも
                var posamp = shrinked_title.lastIndexOf("&");
                if (shrinked_title.substring(posamp).match("&(#\\d+|[a-zA-Z]+);")) {
                    shrinked_title = shrinked_title.substring(0, posamp);
                } else {
                    shrinked_title = shrinked_title.substring(0, shrinked_title.length - 1);
                }
            } else {
                shrinked_title = shrinked_title.substring(0, shrinked_title.length - 1);
            }
            if (ie) {
//                alert("offsetWidth = " + titleObj.offsetWidth + ", next shrinked_title = " + pf_photoview_meta2escape(shrinked_title + "..."));
                titleObj.innerHTML = pf_photoview_meta2escape(shrinked_title + "...");  // FF
            } else {
                if (titleObj.firstChild) {
                    titleObj.innerHTML = pf_photoview_meta2escape(shrinked_title + "...");  // FF
                }
            }
        }
	}

    // 次回の開始位置
    m_photo_box_index += Math.min(rest, m_photo_creation_cnt);

    if (m_photo_creation_cnt == pictCnt) {
        m_columns = pictCnt;
    }
    
    if (m_pict_timerEnabled && m_photo_box_index < pictCnt) {
        pf_photoview_make_interMargin(); // 流し込み配置を続けると、Firefoxで処理が重くなるため、適宜流し込み解除する。
        // まだ処理が残っているので一旦10msタイマーを張ってUIスレッドを開放する
        m_pict_timerId = setTimeout( function(){pf_photoview_loadPictBox(photos)}, C_OCCUPATION_TIME );
    } else {
        // もう写真はないので最終処理へ
        pf_photoview_fixup();
    }

    if (m_timerEnabled) {
        if (m_timerKicked == false) {
            m_timerKicked = true;
            // まだ画像表示タイマーが設定されていない
            m_timerId = setTimeout( function(){pf_photoview_dispActiveImage(photos)}, 1000 );
            m_preScrollTop = (-1);
        }
    } else {
        // 全子ノードの削除
        pf_photoview_deleteChilds(containarObj);
    }
}

/**
 * あまり長い流し込み処理をすると、Firefoxが異常に重くなるので、
 * 途中で、適宜流し込みを解除する処理を入れる
 *
 *
 */
function pf_photoview_make_interMargin()
{
	var containarObj = document.getElementById('id_box');

    if (!ie) {
        var obj = document.createElement("div");
        if (obj) {
            pf_photoview_setStyle(obj, "clear: both;");
            containarObj.appendChild(obj);
        }
    }
}

/**
 * 最終処理
 *
 *
 */
function pf_photoview_fixup()
{
	var containarObj = document.getElementById('id_box');

    // 最後にfloatの解除と、IE以外は加えて5ピクセルのマージンを追加ためのdiv追加
    var obj = document.createElement("div");
    if (obj != null) {
        if (ie) {
            pf_photoview_setStyle(obj, "clear: both;");
        } else {
            pf_photoview_setStyle(obj, "clear: both; height:" + C_MARGIN + "px;");
        }
        containarObj.appendChild(obj);
    }
}

/**
 * すべての子ノードを削除する
 *
 */
function pf_photoview_deleteChilds(obj)
{
    if (obj) {
        for (var i = obj.childNodes.length - 1; i >= 0 ; --i) {
            obj.removeChild(obj.childNodes[i]);
        }
    }
}

/**
 * テキストを取得する
 *
 */
function pf_photoview_getTextContent(obj)
{
    var ret = "";
    if (obj.firstChild) {
        if (ie) {
            ret = obj.firstChild.text;  // IE
        } else {
            ret = obj.firstChild.textContent;  // FF
        }
    }
    return ret;
}

/**
 * エレメントを生成する.
 *
 */
function pf_photoview_createElement(tag, name)
{
    var obj;
    if (ie) {
       // IEはname属性値をcreateElement時に設定する。
       if (name) {
            obj = document.createElement("<" + tag + " name=\"" + name + "\">");
       } else {
            obj = document.createElement("<" + tag + ">");
       }
    } else {
        obj = document.createElement(tag);
        if (name) {
            obj.setAttribute("name", name);
        }
    }
    return obj;
}

/**
 * スタイルを設定する.
 *
 */
function pf_photoview_setStyle(obj, styles)
{
    if (ie) {
        obj.style.cssText = styles;
    } else {
        obj.setAttribute("style", styles);
    }
}

/**
 * 画像、画像タイトルなど1セットのオブジェクトを生成する。
 *
 */
function pf_photoview_createPictBox(i, id, title, css)
{
    var top = pf_photoview_createElement("div");
    if (top != null) {
        // その他属性値を設定する。
        if (ie) {
            top.style.cssText = css;
        } else {
            top.setAttribute("style", css);
        }
    }

    // 写真表示領域
    var obj = pf_photoview_createElement("a", C_DIVTAG_NAME_FOR_IMG);

    if (obj != null) {
        // その他属性値を設定する。
        obj.setAttribute('href', '/photo/choice/' + m_id + '/' + id + '/' );
        // その他属性値を設定する。
        css = "background-color: " + C_NOIMAGE_BKCOLOR + "; width: 90px; height: 90px; overflow: hidden;";
        pf_photoview_setStyle(obj, css);
        obj.id =  C_DIVTAG_IDBASE_FOR_IMG + i;
        top.appendChild(obj);

        // アンカー領域
        var a = pf_photoview_createElement("div");
        if (a != null) {
            css = "background-color: " + C_NOIMAGE_BKCOLOR + "; width: 90px; height: 90px;";
            pf_photoview_setStyle(a, css);
            if (ie) {
                a.className = C_NOIMAGE_CLASS;
            } else {
                a.setAttribute("class", C_NOIMAGE_CLASS);
            }
            a.innerHTML=pf_photoview_title_callback(pf_photoview_meta2escape(pf_photoview_trim_overflowtext(title)));
        }
        obj.appendChild(a);

        // テキスト領域
        var txt = pf_photoview_createElement("div");
        css = "overflow: hidden;";
        pf_photoview_setStyle(txt, css);
        var titleid = C_DIVTAG_IDBASE_FOR_TITLE + i;

        txt.innerHTML="<nobr id='" + titleid+ "'>" + pf_photoview_meta2escape(pf_photoview_trim_overflowtext(title)) + "</nobr>";
        top.appendChild(txt);
    }

    return top;
}

/**
 * メタ文字をエスケープする
 *
 */
function pf_photoview_meta2escape(str)
{
//    str = str.replace(/&amp;/g, "&");
    str = str.replace(/"/g, "&quot;");
    str = str.replace(/'/g, "&#039;");
    str = str.replace(/</g, "&lt;");
    str = str.replace(/>/g, "&gt;");
    return str;
}

/**
 * 指定サイズを越えた部分を「...」に変換する。
 *
 */
function pf_photoview_trim_overflowtext(str)
{
    var len = str.length;
    if (C_PICT_TITLE_LENGTH > 0 && len > C_PICT_TITLE_LENGTH) {
        str = str.substring(0, C_PICT_TITLE_LENGTH) + "...";
    }

    return str;
}

/**
 *
 *
 */
function pf_photoview_dispActiveImage(photos)
{
	var obj = document.getElementById('id_box');

	// 表示位置チェック
	var curPos = Math.floor(obj.scrollTop / 10);
	var prePos = Math.floor(m_preScrollTop / 10);
//	var curPos = obj.scrollTop;
//	var prePos = m_preScrollTop;

	if ( curPos != prePos )
	{
    	//前回から移動している場合は無条件にウェイト
		m_preScrollTop = obj.scrollTop;
    	m_timerId = setTimeout( function(){pf_photoview_dispActiveImage(photos)}, 1000 );
//		pf_photoview_logger_writeln("テスト用＞異なる位置:" + obj.scrollTop);
		return;
	}

	m_preScrollTop = obj.scrollTop;
//	pf_photoview_logger_writeln("テスト用＞同じ位置:" + obj.scrollTop);

    // おおよそアクセスする範囲を限定しておく
    var start_pict_id = Math.max(0, Math.floor((m_preScrollTop - 5) / m_vskip) * m_columns);
    var end_pict_id   = Math.min(photos.length, Math.ceil((m_preScrollTop + m_boxHeight - 5) / m_vskip) * m_columns);

    try {
        for ( var i = start_pict_id; i < end_pict_id; i++) {
            var pictId = C_DIVTAG_IDBASE_FOR_IMG + i;
    		var pictObj = document.getElementById(pictId);

            if (!pf_photoview_isInRegionObj(pictObj, obj)) {
                // 表示領域外なのでスキップ
                continue;
            }

            var clazz;
            if (ie) {
                clazz = new Array();
                // ie には getElementsByClassNameがない。すべてをトラバースする。
                var cla = pictObj.getElementsByTagName("*");
                for (var j = 0; j < cla.length; j++) {
                    var cladef = cla[j].className;
                    if (cladef) {
                        var classes = cladef.split(" ");
                        for (var k = 0; k < classes.length; k++) {
                            if (C_NOIMAGE_CLASS == classes[k]) {
                                clazz.push(cla);
                            }
                        }
                    }
                }
            } else {
                clazz = pictObj.getElementsByClassName(C_NOIMAGE_CLASS);
            }

//            pf_photoview_logger_writeln("チェック中＞ id=" + pictObj.getAttribute("id") + ", top=" + pictObj.style.offsetTop + ", left=" + pictObj.style.offsetLeft + ", bottom=" + pictObj.style.offsetBottom + ", right=" + pictObj.style.offsetRight);

            //未取得でない場合は処理しない
            if ( clazz.length == 0) {
//                pf_photoview_logger_writeln("取得済み＞ id=" + pictObj.getAttribute("id") + ", topcnt=" + topCnt + ", lastCnt=" + lastCnt + ", elements=" + elements.length);
                continue;
            }

            // 未取得なので、取得できるようにしてみる.
//            var url = photos[i].getAttribute("src");
            var url = photos[i].src;
//            pf_photoview_logger_writeln("リクエスト送信＞ id=" + pictObj.getAttribute("id") + ", url=" + url + ", topcnt=" + topCnt + ", lastCnt=" + lastCnt + ", elements=" + elements.length);

            if (url == undefined || url == null) {
                //何もしない
    //            alert("elements = i = " + i);
                ;
            } else {
//                var titletag = photos[i].getElementsByTagName('title')[0];
//                var title = pf_photoview_getTextContent(titletag);
                var title = photos[i].title;
                //リクエスト送信
                pictObj.innerHTML = "<img src='" + url + "' alt='" + pf_photoview_meta2escape(title) + "' title='" + pf_photoview_meta2escape(title) + "'>"
            }
        }
    } catch (e) {
        pf_photoview_logger_writeln("例外発生＞ " + e + ", id=" + pictObj.getAttribute("id") + ", topcnt=" + topCnt + ", lastCnt=" + lastCnt + ", elements=" + elements.length);
    }

    clearTimeout(m_timerId);
    m_timerId = 0;
    if (m_timerEnabled) {
    	m_timerId = setTimeout( function(){pf_photoview_dispActiveImage(photos)}, 1000 );
    }
}

/**
 *
 *
 */
function pf_photoview_isInRegionObj(child, parent) {

    var left = child.offsetLeft;
    var top = child.offsetTop;

    if (ie) {
        // ieの場合は常に親オブジェクとの相対になるので、目的のオブジェクトまで遡って積算する。
        var par = child.parentNode;
        while (par != parent) {
            left += par.offsetLeft;
            top += par.offsetTop;
            par = par.parentNode;
        }
    }

    var right = left + C_PICT_WIDTH - 1;
    var bottom = top + C_PICT_HEIGHT - 1;

    if ( pf_photoview_isInRegionPoint(left, top, parent) ||
        pf_photoview_isInRegionPoint(right, top, parent) ||
        pf_photoview_isInRegionPoint(right, bottom, parent) ||
        pf_photoview_isInRegionPoint(left, bottom, parent)) {
        return true;
    }
    return false;
}

/**
 *
 */
function pf_photoview_isInRegionPoint(x, y, parent) {
    if ( ((!opera && y >= parent.scrollTop) || (opera && y >= 0)) &&
            ((!opera && y < (parent.scrollTop + parent.offsetHeight)) || (opera && y < parent.offsetHeight)) &&
                (x >= parent.scrollLeft) &&
                (x < (parent.scrollLeft + parent.offsetWidth))) {
            return true;
    }

    return false;
}

/**
 * 表示位置・サイズ設定
 */
function pf_photoview_onResize() {
//    alert("pf_photoview_onResize");
//
    // ブラウザ非依存な内部領域サイズ？
    var clientHeight = 0;
	var clientWidth = 0;

	try{
		if (typeof(window.innerHeight) == 'undefined' ){
//            clientHeight = document.body.clientHeight;
            clientHeight = document.documentElement.clientHeight;
            clientWidth = document.body.clientWidth;
		} else {
            clientHeight = window.innerHeight;
            clientWidth = window.innerWidth;
		}
	} catch(e) {
//        clientHeight = document.body.clientHeight;
        clientHeight = document.documentElement.clientHeight;
        clientWidth = document.body.clientWidth;
	}

    // 表示領域・位置計算

	var conHeight = 0;
	var conWidth = 0;

    conHeight = clientHeight - heightMargin * 2;
    conWidth = clientWidth - widthMargin * 2;

    //
    var isTooNarrow = false;
    var bodyDivWidth = document.getElementById('bodyDiv').offsetWidth;
    if (conWidth < bodyDivWidth) {
        conWidth = bodyDivWidth;
        isTooNarrow = true;
    }

    // ダイアログ全体
	var obj = document.getElementById('id_con');
    obj.style.position = 'absolute';
    obj.style.height = conHeight + "px";
    obj.style.width = conWidth + "px";
    obj.style.top = heightMargin + "px";
    var narrowedWidthMargin = widthMargin;
    if (isTooNarrow) {
        narrowedWidthMargin = Math.max(0, (clientWidth - conWidth) / 2);
    }
    obj.style.left = narrowedWidthMargin + "px";

    // コントロールバー
	obj = document.getElementById('id_bar');
	obj.style.position = 'absolute';
    obj.style.top = C_MARGIN + "px";
    obj.style.left = C_MARGIN + "px";
    obj.style.width = conWidth - C_MARGIN * 2 + "px";
    obj.style.height = C_TITLE_BAR_HEIGHT + "px";

    // 写真表示領域
    m_boxHeight = conHeight - C_MARGIN * 4 - C_TITLE_BAR_HEIGHT;
	obj = document.getElementById('id_box');
	obj.style.position = 'absolute';
    obj.style.top = C_MARGIN * 2 + C_TITLE_BAR_HEIGHT + "px";
    obj.style.left = C_MARGIN + "px";
    obj.style.height = m_boxHeight + "px";
    obj.style.width = conWidth - C_MARGIN * 2 + "px";
}

/**
 * 表示位置・サイズ設定
 */
function pf_photoview_onResize4Shadow() {
    // 背景
    obj = document.getElementById('id_back');
    obj.style.top = "0px";
    obj.style.left = "0px";
    if (ie6) {
        // IE6では position: fixed; が正常に動作しない。
        obj.style.position = 'absolute';
        obj.style.width = document.body.scrollLeft + document.body.scrollWidth + "px";
        obj.style.height = document.body.scrollHeight + "px";
    } else {
        obj.style.position = 'fixed';
        obj.style.right = "0px";
        obj.style.bottom = "0px";
    }
}

/**
 * 表示位置・サイズ設定
 */
function pf_photoview_onScroll() {
//    alert("pf_photoview_onResize");
    // 背景
	obj = document.getElementById('id_back');
	obj.style.position = 'absolute';
    obj.style.top = "0px";
    obj.style.left = document.body.scrollLeft + "px";
    obj.style.width = document.body.scrollWidth + "px";
    obj.style.height = document.body.scrollHeight + 10 + "px";
}

/**
 * SELECTコントロールの表示制御(for IE6)
 */
function pf_photoview_selectVisibility(visible) {
    if (ie6) {
        var objs = document.getElementsByTagName("SELECT");
        for (var idx = 0; idx < objs.length; idx++) {
            var obj = objs.item(idx);
            obj.style.visibility = visible;
        }
    }
}

/**
 *
 */
function pf_photoview_logger_writeln(str) {
    pf_photoview_logger_write(str + '\x0d\x0a');
}

/**
 *
 */
function pf_photoview_logger_write(str) {
    var obj = document.getElementById('id_lbl');
    if (obj != null) {
        obj.value = str;
    }
}
