if(document.getElementById){
/*************************************************
Overlay viewer ver 1.1
y.iibuchi@gmail.com

このJavaScript ファイルを読み込むだけで、contents内のjpg, gifへの直接リンクを置き換え、
クリックした場合にOverlay処理して表示するようにする。

*************************************************/

var html = [
	'<div id="overlay" style="display:none;z-index:20;">',
	'<div id="overlay1" class="alpha">',
	'</div>',
	'<div id="overlay2" onclick="hideById(\'overlay\');">',
	'<div id="overlay_image" style="','position:absolute;padding:5px; background-color:white;','">',
	'<img src="/common/images/indicator_medium.gif"',
	' id="overlay_image2" style="','display:block;','" />',
	'<p class="center">',
	'<a href="',"javascript:void(hideById('overlay'));",'" class="button">close</a>',
	'</p></div>','</div>','</div>'
];

document.write(html.join(""));


function overlayOnload(){
	// ■ リンク先の拡張子がjpgの<a href="...">を置き換える
	var arr = document.getElementById("contents").getElementsByTagName("a");
	for(var i=0;i<arr.length;i++){
		if((arr[i].href.match(".jpg")) || (arr[i].href.match(".gif"))){
			arr[i].href="javascript:viewImages(\""+arr[i].href+"\")";
		}
	}
	// ■overlay1とoverlay2がページに存在する場合に、幅と高さを画面いっぱいに拡大する
	if((document.getElementById("overlay1") != null) && (document.getElementById("overlay2") != null)) {
		var x = 0; var y = 0;
		if(document.all){	// IE
			x = Math.max(document.body.scrollWidth,document.documentElement.scrollWidth);
			y = Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
		} else {	// Firefox, Safari, Opera
			x = Math.max(document.body.scrollWidth,document.documentElement.clientWidth);
			y = Math.max(document.body.scrollHeight,document.documentElement.clientHeight);
		}
		document.getElementById("overlay1").style.width = x+"px";
		document.getElementById("overlay1").style.height = y+"px";
		document.getElementById("overlay2").style.width = x+"px";
		document.getElementById("overlay2").style.height = y+"px";
	}
	setCenter();
}


if (window.attachEvent){
	window.attachEvent('onload', overlayOnload);
} else {
	window.addEventListener('load', overlayOnload, false);
}

function viewImages(url){
	var d1=document.getElementById("overlay_image");
	var d2=document.getElementById("overlay_image").getElementsByTagName("img")[0];
	d2.style.visibility="hidden";
	d2.src=url;
	showById("overlay");
	d2.onload=function(){setCenter();this.style.visibility="visible";}
}

function setCenter(){
	var d1=document.getElementById("overlay_image");
	var d2=document.getElementById("overlay_image").getElementsByTagName("img")[0];
	var t = document.documentElement.scrollTop || document.body.scrollTop;
	d1.style.left = (get_browser_width()/2)-(d2.width/2)+"px";
	d1.style.top = (get_browser_height()/2)+t-(d2.height/2)+"px";
	//http://logic.stepserver.jp/data/archives/511.html
	//----------------------------------------------- get_browser_width
	function get_browser_width() {
		if ( window.innerWidth ) { return window.innerWidth; }  
		else if ( document.documentElement && document.documentElement.clientWidth != 0 ) { return document.documentElement.clientWidth; }  
		else if ( document.body ) { return document.body.clientWidth; }  
		return 0;  
	}
	
	//----------------------------------------------- get_browser_height
	function get_browser_height() {
		if ( window.innerHeight ) { return window.innerHeight; }  
		else if ( document.documentElement && document.documentElement.clientHeight != 0 ) { return document.documentElement.clientHeight; }  
		else if ( document.body ) { return document.body.clientHeight; }  
		return 0;  
	}
}


}
