
//function map(page){
//    win=window.open(page,"map","menubar=no,scrollbars=no,resizable=yes,width=800,height=600");
//}

/* バックグラウンドid */
var gsbackgroundid = 'wbackground_type001';
/* 表示イメージ */
var gsimgpath = '[image_path]';		//画像のパスに置き換える
var gsimgcomment = '[comment]';		//画像のコメント(alt)に置き換える
/* メッセージ表示用id */
var gsimginfomsgid = 'imginfomsg';
var iposition;						//座標
/*-----------------------------------------------------*-----***/
/*  fonload_type01                                             */
/*  画面ロード時にイベントを設定する                           */
/***-----*-----------------------------------------------------*/
	function fonload_type01(){
		//バックグラウンド(div)作成
		fstartup_backgroundtype01();

		//座標の取得
		window.document.onmousemove = function(e){
			iposition = fgetMousePosition(e);
		}
	}

/*-----------------------------------------------------*-----***/
/*  fonload_type02                                             */
/*  画面ロード時にイベントを設定する                           */
/***-----*-----------------------------------------------------*/
	function fonload_type02(){
		//windowをポップアップさせる
		fwindowpopup_type();
	}

/*-----------------------------------------------------*-----***/
/*  fimage_onclick                                             */
/*  画像を拡大して表示                                         */
/*  itype：表示タイプ                                          */
/***-----*-----------------------------------------------------*/
	function fimage_onclick(event,oobj,itype){
		if(ftrim(oobj) == '' || ftrim(oobj) == 'undefined'){
			if(event.srcElement){
				//IE.Safari.Opere.chrome
				var othis = document.getElementById(event.srcElement.id);
			}else{
				//firefox
				var othis = document.getElementById(event.currentTarget.id);
			}
		}else{
			var othis = oobj;
		}
		if(ftrim(itype) == '' || ftrim(itype) == 'undefined'){
			//表示タイプ未指定
			itype = 0;
		}

		//バックグラウンドのobject取得
		var obkgdobj = document.getElementById(gsbackgroundid);
		obkgdobj.style.className = '';		//非表示の解除
		obkgdobj.style.display = 'block';
		obkgdobj.style.position = 'absolute';
		obkgdobj.style.top = '0px';
		obkgdobj.style.left = '0px';
		obkgdobj.style.zIndex = 1;
		obkgdobj.style.backgroundColor = '#999999';
		//透明度の設定
		obkgdobj.style.filter = 'alpha(style=0, opacity=56)';
		obkgdobj.style.MozOpacity = 56 / 100;
		obkgdobj.style.opacity = 56 / 100;

		//現在のウインドウの表示領域取得
		var swwidth = document.body.offsetWidth;		//ウインドウのwidth
		var swheight = document.body.offsetHeight;		//ウインドウのheight
		obkgdobj.style.width = swwidth + 'px';
		obkgdobj.style.height = swheight + 'px';

		//書き込み先
		var selement = document.getElementsByTagName('body').item(0);
//		//スクロールバーを非表示にする
//		selement.style.overflow = 'hidden';

		//クリックした画像のパスを取得
		var sgetpath = othis.src;
		//クリックした画像のコメントを取得
		var sgetcomment = othis.alt;

		//html書き込み
		//URL
		//表示タイプ別処理
		if(Number(itype) == 1){
			surl = '../popup001.html';
		}else{
			surl = './popup001.html';
		}
		var httpObj = '';
		var oobjtextdoc = '';
		//Ajax通信(false：同期,true：非同期)
		var bresult = new Ajax.Request(surl,{
			method : 'get',
			asynchronous : false,
			parameters : '',
			onSuccess : function(httpObj){
				//var oobjtextdoc = httpObj.responseText;
			},
			onComplete: function(httpObj){
				//popup001.htmlの値取得
				var oobjtextdoc = httpObj.responseText;
				//取得した画像のパスを設定
				oobjtextdoc = oobjtextdoc.replace(gsimgpath,sgetpath);
				//取得した画像のコメントを設定
				oobjtextdoc = oobjtextdoc.replace(gsimgcomment,sgetcomment);
				//ポップアップhtmlを書き込む
				selement.innerHTML += oobjtextdoc;

				//画像を画面中央に配置
				var owitem = document.getElementById('popupwindow01');		//popup001：divのobject

				//表示タイプ別処理
				var opopupimg = document.getElementById('popupimage01');	//popup001：imageのobject

				var imgsize = getActualDimension(othis);
				var wkwidth = Number(imgsize.width) + 8;
				var wkheight = Number(imgsize.height) + 8;
				owitem.style.width = wkwidth + 'px';		//divのwidth設定
				owitem.style.height = wkheight + 'px';		//divのheight設定

				if(imgsize.width == othis.width){
					// for IE
					var opopupimg = document.getElementById('popupimage01');	//popup001：imageのobject
					var wktop = (Number(swheight) - Number(opopupimg.height)) / 2;
					var wkleft = (Number(swwidth) - Number(opopupimg.width)) / 2;
					wkwidth = Number(opopupimg.width) + 8;
					wkheight = Number(opopupimg.height) + 8;
					owitem.style.width = wkwidth + 'px';		//divのwidth設定
					owitem.style.height = wkheight + 'px';		//divのheight設定
				}else{
					var wktop = (Number(swheight) - Number(wkheight)) / 2;
					var wkleft = (Number(swwidth) - Number(wkwidth)) / 2;
				}

				//表示位置
				owitem.style.position = 'absolute';			//divの表示位置設定
//				owitem.style.top = wktop + 'px';
				owitem.style.top = '60px';
				owitem.style.left  = wkleft + 'px';
			},
			onFailure : function(httpObj){
//				//エラーメッセージを表示
//				var oobj = document.getElementById('makebox');
//				var svalue = '読み込みに失敗しました';
//				var stext = document.createTextNode(svalue);
//				oobj.appendChild(stext);
				//バックグラウンドのclass変更
				obkgdobj.className = 'contents-none';
				//現在のウインドウの表示領域取得
				obkgdobj.style.width = '';
				obkgdobj.style.height = '';
			},
			onException: function (request) {
//				//エラーメッセージを表示
//				var oobj = document.getElementById('makebox');
//				var svalue = '読み込み中にエラーが発生しました';
//				var stext = document.createTextNode(svalue);
//				oobj.appendChild(stext);
				//バックグラウンドのclass変更
				obkgdobj.className = 'contents-none';
				//現在のウインドウの表示領域取得
				obkgdobj.style.width = '';
				obkgdobj.style.height = '';
			}

		});
	}

/*-----------------------------------------------------*-----***/
/*  fviewMsginfo                                               */
/*  メッセージ表示設定                                         */
/***-----*-----------------------------------------------------*/
	function fviewMsginfo(){
		if(!document.getElementById(gsimginfomsgid)){
			//div作成
			var element = document.createElement('div');
			element.id = gsimginfomsgid;

			var objbody = document.getElementsByTagName('body').item(0);
			// body要素にdivエレメントを追加
			objbody.appendChild(element);
		}

		//表示位置調整
		var ix = Number(iposition.x) + 12;
		var iy = Number(iposition.y) + 12;

		//メッセージ表示用div
		var omsginfo = document.getElementById(gsimginfomsgid);

		if(document.getElementById('popupwindow01')){
			omsginfo.innerHTML = '<h6 style="margin: 5px;">画像をクリックすると元に戻ります。</h6>';
			omsginfo.className = '';
			omsginfo.style.display = 'block';
			omsginfo.style.position = 'absolute';
			omsginfo.style.top = iy + 'px';
			omsginfo.style.left = ix + 'px';
			omsginfo.style.zIndex = 3;
			omsginfo.style.backgroundColor = '#ffffff';
			//透明度の設定
			omsginfo.style.filter = 'alpha(style=0, opacity=56)';
			omsginfo.style.MozOpacity = 56 / 100;
			omsginfo.style.opacity = 56 / 100;
		}else{
			if(document.getElementById(gsimginfomsgid)){
				// メッセージ表示用div削除
				Element.remove(gsimginfomsgid)
				Event.unloadCache;
			}
		}
	}

/*-----------------------------------------------------*-----***/
/*  fgetMousePosition                                          */
/*  画面座標の取得                                             */
/***-----*-----------------------------------------------------*/
	function fgetMousePosition(e){
		var obj = new Object();

		if(e){
			obj.x = e.pageX;
			obj.y = e.pageY;
		}else{
			obj.x = event.x + document.body.scrollLeft;
			obj.y = event.y + document.body.scrollTop;
		}
		return obj;
	}

/*-----------------------------------------------------*-----***/
/*  fhiddenMsginfo                                             */
/*  メッセージを非表示に設定                                   */
/***-----*-----------------------------------------------------*/
	function fhiddenMsginfo(){
		if(document.getElementById(gsimginfomsgid)){
			// メッセージ表示用div削除
			Element.remove(gsimginfomsgid)
			Event.unloadCache;
		}
	}

/*-----------------------------------------------------*-----***/
/*  fstartup_backgroundtype01                                  */
/*  バックグラウンド用div作成                                  */
/***-----*-----------------------------------------------------*/
	function fstartup_backgroundtype01(){
		//div作成
		var element = document.createElement('div');
		element.id = gsbackgroundid;
		element.className = 'contents-none';

		var objbody = document.getElementsByTagName('body').item(0);
		// body要素にdivエレメントを追加
		objbody.appendChild(element);
	}

/*-----------------------------------------------------*-----***/
/*  fclose_popuparea                                           */
/*  popupエリアを閉じる                                        */
/***-----*-----------------------------------------------------*/
	function fclose_popuparea(sid){
		//バックグラウンドのobject取得
		var obkgdobj = document.getElementById(gsbackgroundid);
		obkgdobj.className = 'contents-none';
		//現在のウインドウの表示領域取得
		obkgdobj.style.width = '';
		obkgdobj.style.height = '';

		if(document.getElementById(gsimginfomsgid)){
			// メッセージ表示用div削除
			Element.remove(gsimginfomsgid)
			Event.unloadCache;
		}

		// div削除
		Element.remove(sid)
		Event.unloadCache;
	}

/*-----------------------------------------------------*-----***/
/*  fwindowpopup_type                                          */
/*  windowをポップアップさせる                                 */
/***-----*-----------------------------------------------------*/
	function fwindowpopup_type(){
		if(!document.getElementsByTagName){
			return false;
		}
		var links = document.getElementsByTagName("a");
		for(var i=0; i < links.length; i++){
			if(links[i].className.match("popup_type01")){
				links[i].onclick = function() {
					window.open(this.href);
					return false;
				}
			}
		}
	}

/*-----------------------------------------------------*-----***/
/*  getActualDimension                                         */
/*  画像本来の大きさを取得する                                 */
/***-----*-----------------------------------------------------*/
function getActualDimension(image) {
  var run, mem, w, h, key = "actual";

  // for Firefox, Safari, Google Chrome
  if ("naturalWidth" in image) {
    return { width:  image.naturalWidth,
             height: image.naturalHeight };
  }

  if ("src" in image) { // HTMLImageElement
    if (image[key] && image[key].src === image.src) {
      return image[key];
    }
    if (document.uniqueID) { // for IE
      run = image.runtimeStyle;
      mem = { w: run.width, h: run.height }; // keep runtimeStyle
      run.width  = "auto"; // override
      run.height = "auto";
      w = image.width;
      h = image.height;
      run.width  = mem.w; // restore
      run.height = mem.h;
    } else { // for Opera and Other
/*
      function fn() {
        w = image.width;
        h = image.height;
      }
      mem = { w: image.width, h: image.height }; // keep current style
      image.removeAttribute("width");
      image.addEventListener("DOMAttrModified", fn, false);
      image.removeAttribute("height");
      // call fn
      image.removeEventListener("DOMAttrModified", fn, false);
      image.width  = mem.w; // restore
      image.height = mem.h;
 */
      mem = { w: image.width, h: image.height }; // keep current style
      image.removeAttribute("width");
      image.removeAttribute("height");
      w = image.width;
      h = image.height;
      image.width  = mem.w; // restore
      image.height = mem.h;
    }
    return image[key] = { width: w, height: h, src: image.src }; // bond
  }
  // HTMLCanvasElement
  return { width: image.width, height: image.height };
}


//*------------------------------------------------------*
// 処理内容　　　：空白除去
// 引数        　：svalue : 値
//*------------------------------------------------------*
	function ftrim(svalue){
	    return String(svalue).replace(/^[ 　]*/gim, "").replace(/[ 　]*$/gim, "");
	}

