//ショートカット
(function()
{
	var
	// browser object references clockup
	_w = this,
	_d	= document,
	_n = navigator,
	_agent = _n.userAgent,
	_l = location,
	
	undefined;
	
	_id		= function(e){return document.getElementById(e);},
	_tags	= function(e,p){return (p)? p.getElementsByTagName(e) : document.getElementsByTagName(e);};
})();


//onload
$(document).ready(
	function()
	{
		//TopMenu Init
		TM.Init();
		//LangChange Init
		LC.init();
		
		//Photo Gallery
		_id("photoGallery")
		{
			$('#photoGallery a').lightBox();
		}
	}
);


/** Flash Gallery
------------------------------ **/

function fGallery(param)
{
	var FlashVars;
	
	if(param.xmlPath == undefined)
	{
		var appPath	= encodeURIComponent("/flash_gallery/app/dirfile_to_xml.php");
		var dirPath	= encodeURIComponent(param.dirPath);
		FlashVars	= "appPath=" + appPath + "&" + "dirPath=" + dirPath;
	}
	else
	{
		var xmlPath	= encodeURIComponent(param.xmlPath);
		FlashVars	= "xmlPath=" + xmlPath;
	}
	//Document Write
	document.write('<div style="margin-bottom:20px;">');
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="620" height="400" id="gallery" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="allowFullScreen" value="true" />');
	document.write('<param name="FlashVars" value="' + FlashVars + '" />');
	document.write('<param name="movie" value="/flash_gallery/gallery.swf" />');
	document.write('<param name="quality" value="best" />');
	document.write('<param name="scale" value="noscale" />');
	document.write('<param name="bgcolor" value="#000000" />');
	document.write('<embed src="/flash_gallery/gallery.swf" FlashVars="' + FlashVars + '" quality="best" scale="noscale" bgcolor="#000000" width="620" height="400" name="gallery" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
	document.write('</div>');
}


/** Movie
------------------------------ **/
function flvPlayer(file)	// file = xml file path
{
document.write('<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" align="middle" height="270">');
document.write('<param name="_cx" value="12700" />');
document.write('<param name="_cy" value="7143" />');
document.write('<param name="FlashVars" value="" />');
document.write('<param name="Movie" value="flvplayer.swf?skin=basic&amp;autoplay=false&amp;repeat=false&amp;file=' + file + '" />');
document.write('<param name="Src" value="flvplayer.swf?skin=basic&amp;autoplay=false&amp;repeat=false&amp;file=' + file + '" />');
document.write('<param name="WMode" value="Window" />');
document.write('<param name="Play" value="-1" />');
document.write('<param name="Loop" value="-1" />');
document.write('<param name="Quality" value="High" />');
document.write('<param name="SAlign" value="" />');
document.write('<param name="Menu" value="-1" />');
document.write('<param name="Base" value="" />');
document.write('<param name="AllowScriptAccess" value="always" />');
document.write('<param name="Scale" value="NoScale" />');
document.write('<param name="DeviceFont" value="0" />');
document.write('<param name="EmbedMovie" value="0" />');
document.write('<param name="BGColor" value="000000" />');
document.write('<param name="SWRemote" value="" />');
document.write('<param name="MovieData" value="" />');
document.write('<param name="SeamlessTabbing" value="1" />');
document.write('<param name="Profile" value="0" />');
document.write('<param name="ProfileAddress" value="" />');
document.write('<param name="ProfilePort" value="0" />');
document.write('<param name="AllowNetworking" value="all" />');
document.write('<param name="AllowFullScreen" value="true" />');
document.write('<embed src="flvplayer.swf?skin=basic&amp;autoplay=false&amp;repeat=false&amp;file=' + file + '" quality="high" bgcolor="#000000" name="flvplayer" scale="noscale" allowscriptaccess="always" allowfullscreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer_jp" align="middle" height="270" width="480">');
document.write('</object>');
}

/** PDF
------------------------------ **/


/** Google Viewer
------------------------------ **/
function gViewer(url)
{
//	url = "http://www.illf.jp/notes/pamp_illf2009.pdf";
//	url = "http%3A%2F%2Fwww.illf.jp%2Fnotes%2Fpamp_illf2009.pdf";
	
	if(url.match(/^http%3A%2F%2F/))
	{
		path = url;
	}
	else
	{
		path = encodeURIComponent(url);
	}
	
	document.write('<iframe src="http://docs.google.com/viewer?url=' + path + '&embedded=true" class="gDocs"></iframe>')
}


/** TopMenu
------------------------------ **/
var TM ={
	
	/** 変数
	------------------------------ **/
	TMID		: "#topMenu",
	mainTimer	: "",
	subTimer	: "",
	timerTime	: 300,
	//サブメニュー総数
	subMenuCount	: 0,
	
	/** 関数
	------------------------------ **/
	//Init
	Init : function()
	{
		var mCount = $(this.TMID + " dt").length;
		
		for(var $i = 0; $i < mCount; $i++)
		{
			var dt			= this.TMID + " dt:eq(" + $i + ")";		//DT
			var baseName	= $(dt).attr("class");					//BaseName
			var dd			= this.TMID + " dd." + baseName;		//DD
			//
			this.subMenuCount	= $(this.TMID + " ul.subMenu").length;
			//
			//設定
			if($(dd).html())
			{
				/** Main Menu **/
				//Position
				var posLeft = $(dt).position().left;
				$(dd).css("left" , posLeft);
				
				//Add Event - A
				$(dt + " a").hover(
					function()
					{
						TM.Open(this);
					},
					function()
					{
						TM.mainTimer = setTimeout("TM.Close()" , TM.timerTime);
					}
				);
				//Add Event - DD
				$(dd).hover(
					function()
					{
						clearTimeout(TM.mainTimer);
					},
					function()
					{
						TM.mainTimer = setTimeout("TM.Close()" , TM.timerTime);
					}
				);
				
				/** Sub Menu **/
				$(dd + " a").each(
					function()
					{
						//子持ちは表示
						if($(this).attr("class") == "hasSub")
						{
							$(this).hover(
								function(){ TM.SubOpen(this);	},
								function(){}
							);
						}
						//同列子非表示
						else
						{
							$(this).hover(
								function(){ TM.SubClose(this); },
								function(){}
							);
						}
					}
				);
			}
		}
	},
	
	//Open
	Open : function(tar)
	{
		clearTimeout(this.mainTimer);
		//クラス名取得
		var cl = $(tar).parent().attr("class");
		//クラスDD以外非表示
		$(this.TMID + " dd:not(." + cl + ")").fadeOut("fast");
		//クラスDD表示
		$(this.TMID + " dd." + cl).fadeIn("fast");
	},
	
	//Close
	Close : function()
	{
		//逆順でサブメニュー非表示
		for(var $i = this.subMenuCount; $i >= 0; $i--)
		{
			$(this.TMID + " .subMenu:eq(" + $i + ")").fadeOut();
		}
		//DD非表示
		$(this.TMID + " dd").fadeOut("fast");
	},
	
	//SubMenu
	SubOpen : function(tar)
	{
		var childMenu = $(tar).parent().children("ul.subMenu");
		//同列サブメニュー非表示
		$(tar).parent().siblings("li.hasSub").children("ul.subMenu").fadeOut("fast");
		//サブメニュー表示＆ネスト非表示
		childMenu.fadeIn("fast");
		childMenu.children("li.hasSub").children("ul.subMenu").hide();
	},
	SubClose : function(tar)
	{
		//同列サブメニュー非表示
		$(tar).parent().siblings("li.hasSub").children("ul.subMenu").fadeOut("fast");
	}
}


/** LangChange
------------------------------ **/
var LC = {
	
	/** 変数
	------------------------------ **/
	LCID			: "#langChange",
	langCount		: 0,
	singleHeight	: 20,
	totalHeight		: 0,
	
	/** 関数
	------------------------------ **/
	init : function()
	{
		this.langCount		= $(this.LCID + " li").length;
		
		if(this.langCount > 1)
		{
			this.totalHeight	= (this.singleHeight + 1) * this.langCount;
		
			$(this.LCID).hover(
				function()
				{
					LC.listOpen();
				},
				function()
				{
					LC.listClose();
				}
			);
		}
	},
	
	listOpen : function()
	{
		$(this.LCID).animate({"height" : this.totalHeight},"fast");
	},
	
	listClose : function()
	{
		$(this.LCID).animate({"height" : this.singleHeight},"fast");
	}
}

//メールメンテナンス
function contactMainte(lang)
{
	if(lang == "ja")
	{
		alert("問い合わせフォームは現在メンテナンス中です。\nお電話にて直接お問い合わせください。\nTEL:076-224-8582");
	}
	else
	{
		alert("Temporal maintenance of our inquiry form.\nPlease call us for contact.\nTEL:076-224-8582");
	}
}

//----------
// DEBUG
//----------
function DEBUG(content)
{
	//Contents
	if(document.getElementById("DEBUG"))
	{
		$("#DEBUG").prepend(content + "<br />");
	}
	//Add Field
	else
	{
		$("body").append('<div id="DEBUG"></div>');
		//Style Set
		$("#DEBUG").css(
		{
			overflow	: "auto",
			position	: "absolute",
			top			: "0",
			right		: "0",
			width		: "240px",
			height		: "160px",
			padding		: "10px",
			background	: "#fff",
			color		: "#000"
		});
		//Add Contents
		$("#DEBUG").prepend(content + "<br />");
	}
	//
	$("#DEBUG").scrollTop(0);
}
