/*@cc_on _d=document;eval('var document=_d')@*/
/**
*
*	LightBox風ポップアップライブラリ
*	※要 simple.js
*
*
*/

var Img;
var ImageHeight = 0;
var ImageWidth = 0;
var url;

	/*********************************************************************************************
	[使い方]
		ポップアップさせたいものに　onlclick="popup('URL', 'HEIGHT'. 'WIDTH') return false;"
		URL   : 表示させたいもののURL(画像可)
		HEIGHT: ポップアップの高さ(画像の場合は未指定でも可)
		WIDTH : ポップアップ幅(画像の場合は未指定でも可)
	**********************************************************************************************/
	function popup( obj, width, height )
	{
		url = obj.href;

		if ( ( width == 0 ) || ( height == 0 ) ) {

			Img = new Image();
			Img.onload = popupExec;
			Img.src = obj.href;


			return ;
		}
		else {
			ImageHeight = height;
			ImageWidth = width;
		}

		popupExec();
	}

	/**
	*
	*	popupExec
	*	ポップアップ実行
	*
	*/
	function popupExec()
	{

		// alert("popupExec");

		if ( ImageWidth == 0 || ImageHeight == 0 ) {
			ImageWidth = Img.width;
			ImageHeight = Img.height;
		}

		//背景
		var background = createBg();
		
		//表示用エリア作成
		var content = createContent();

		//読み込み
		if(url.indexOf('.png') != -1 || url.indexOf('.jpg') != -1 || url.indexOf('.jpeg') != -1 || url.indexOf('.gif') != -1) {
			//画像
			content.innerHTML = '<img src="' + url + '" id="POPUP_image" width="' + ImageWidth + '" height="' + ImageHeight + '">';
		} else {
			//通常のHTML
			content.innerHTML = '<iframe src="' + url + '" frameborder="0" width="' + ImageWidth + '" height="' + ImageHeight + '" id="POPUP_frame"></iframe>';
		}

		var Offset_Y;
		var ClientHeight
		var DispPoint

		background.style.display = 'block';
		Offset_Y = getWinYOffset();
		ClientHeight = getWindowHeight();

		if ( ClientHeight < ImageHeight ) {
			// はみ出す
			DispPoint = Offset_Y - ( ( ImageHeight - ClientHeight ) / 2 );
		}
		else {
			// はみ出さない
			DispPoint = Offset_Y + (ClientHeight / 2) - ( ImageHeight / 2 );
		}

		content.style.top = DispPoint + "px";
		// DispPoint = "Top:" + DispPoint + ";";

		//背景表示
		$opacity(background.id, 0, 70, 200);

		//内容表示
		var timeout = setTimeout(function(){
			clearTimeout(timeout);
			content.style.display = 'block';
			$opacity(content.id, 0, 100, 200);
			}, 200 );
	}


	/**
	*
	*	getWindowHeight
	*	ウィンドウの高さ取得
	*
	*/
	function getWindowHeight(){
		if(window.innerHeight) return window.innerHeight; // Mozilla, Opera, NN4
			if(document.documentElement && document.documentElement.clientHeight){ // 以下 IE
				return document.documentElement.clientHeight;
			}
			else if(document.body && document.body.clientHeight){
				return document.body.clientHeight;
			}
		return 0;
	}


	/**
	*
	*	getWinYOffset
	*	ウィンドウ位置取得
	*
	*/
	function getWinYOffset(){
		if(window.scrollY) return window.scrollY; // Mozilla
		if(window.pageYOffset) return window.pageYOffset; // Opera, NN4
		if(document.documentElement && document.documentElement.scrollTop){ // 以下 IE
			return document.documentElement.scrollTop;
		}
		else if(document.body && document.body.scrollTop){
			return document.body.scrollTop;
		}
		return 0;
	}


	/**
	*
	*	appendPopUp
	*	特定のリンクにポップアップを適用する
	*
	*/
	function appendPopUp()
	{
		var link = document.getElementsByTagName('a');
		for(var i=0 ; i<link.length ; i++)
		{
			if(link[i].className == '_popup') {
				link[i].href = "javascript:;";
				link[i].target="_self";
			}
		}
	}
	
	/**
	*
	*	背景作成
	*
	*/
	function createBg()
	{
		if(document.getElementById('POPUP_background')) {
			return document.getElementById('POPUP_background');
		}
		
		var screen   = document.createElement("div");
		var objBody  = document.getElementsByTagName("body").item(0);   
	
		objBody.appendChild(screen);
		screen.id = "POPUP_background";
	
		screen.style.display = 'none';
		$opacity(screen.id, 100, 0, 0);
		screen.style.height = objBody.scrollHeight + "px";
		screen.style.width  = "100%";
		screen.style.backgroundColor = "#000000";
		screen.style.position = "absolute";
		screen.style.top = "0px";
		screen.style.left = "0px";
		screen.style.zIndex = '9999';
		
		//非表示設定
		screen.onclick = closeContent;

		return screen;
	}
		
	/**
	*
	*	表示エリア作成
	*
	*/
	function createContent()
	{
		if(document.getElementById('POPUP_content')) {
			return document.getElementById('POPUP_content');
		}
		
		var content = document.createElement("div");
		var objBody  = document.getElementsByTagName("body").item(0);
		
		objBody.appendChild(content);
		content.style.display = 'none';
		content.id = "POPUP_content";
		$opacity(content.id, 100, 0, 0);
		content.style.position = "absolute";
		// content.style.top = 0; //getWindowHeight() + 200 + "px";
		content.style.left = "0px";
		content.style.textAlign = "center";
		content.style.verticalAlign = "middle";
		content.style.width  = "100%";
		content.style.zIndex = '10000';
		
		//非表示設定
		content.onclick = closeContent;
		return content;
	}
	
	
	/**
	*
	*	表示を止める
	*
	*/
	function closeContent()
	{
		$opacity("POPUP_content", 100, 0, 200);
		$opacity("POPUP_background", 70, 0, 200);
	
		var timeout = setTimeout(function(){
				clearTimeout(timeout);
				document.getElementById('POPUP_background').style.display = 'none';
				document.getElementById('POPUP_content').style.display = 'none';}, 420);
	
	
	}
	


window.onload = function(){
					createBg();
					createContent();
					}