/**
*
*	LightBox風ポップアップライブラリ
*	※要 simple.js
*
*
*/


	/*********************************************************************************************
	[使い方]
		ポップアップさせたいものに　onlclick="popup('URL', 'HEIGHT'. 'WIDTH') return false;"
		URL   : 表示させたいもののURL(画像可)
		HEIGHT: ポップアップの高さ(画像の場合は未指定でも可)
		WIDTH : ポップアップ幅(画像の場合は未指定でも可)
	**********************************************************************************************/
	function popup(obj, width, height)
	{
		url = obj.href;
		
		if(!height){
			height = 480;
		}
		if(!width) {
			width = 640;
		}
		
		//背景
		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 scrolling="no" src="' + url + '" id="POPUP_image" width="' + width + '" height="' + height + '">';
		} else {
			//通常のHTML
			content.innerHTML = '<iframe scrolling="no" src="' + url + '" frameborder="0" width="' + width + '" height="' + height + '" id="POPUP_frame"></iframe>';
		}
		
		//表示&位置あわせ
		background.style.display = 'block';
		content.style.top = (document.documentElement.scrollTop || document.body.scrollTop) + ((document.documentElement.clientHeight || document.body.clientHeight) - height) / 2 + 'px';
		//背景表示
		$opacity(background.id, 0, 70, 200);

		//内容表示
		var timeout = setTimeout(function(){
			clearTimeout(timeout);
			content.style.display = 'block';
			$opacity(content.id, 0, 100, 200);
			}, 200);
		
	}
	
	
	
	
	/**
	*
	*	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 = (document.documentElement.scrollHeight || document.body.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 = (document.documentElement.scrollTop || document.body.scrollTop + 200) + 'px';
		content.style.left = "0px";
		content.style.textAlign = "center";
		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();
					}