$(function(){
	$(window).scroll(function(){ moveModulBox(); });
});

function openModulBox(url){
	if(!url) return;
	// #modulBackGround の設置
	$("body").prepend("<div id=\"modulBackGround\"><img src=\"img/bg_modulbox.gif\" alt=\"\" class=\"bg\" /><div id=\"modulBox\"><div id=\"ajaxContent\"></div><p id=\"btnModuleBoxClose\"><img src=\"img/btn_close.gif\" alt=\"Close\" width=\"91\" height=\"25\" /></p></div></div>");
	var contentsHeight;
	var windowHeight;
	var windowWidth;
	if(document.documentElement.scrollHeight > document.body.scrollHeight){
		contentsHeihgt = document.documentElement.scrollHeight;
	}else{
		contentsHeihgt = document.body.scrollHeight;
	}
	if(document.documentElement.clientHeight){
		windowHeight = document.documentElement.clientHeight;
		windowWidth  = document.documentElement.clientWidth;
	}else{
		windowHeight = document.body.clientHeight;
		windowWidth  = document.body.clientWidth;
	}
	var moduleLeft = windowWidth / 2 - 635 / 2 ;
	$("body #modulBackGround").css("height",contentsHeihgt+"px");
	$("body #modulBackGround img.bg").css("width",windowWidth+"px");
	$("body #modulBackGround img.bg").css("height",contentsHeihgt+"px");
	$("body #modulBackGround #modulBox").css("left",moduleLeft+"px");
	moveModulBox();
	$("#modulBackGround #modulBox p#btnModuleBoxClose img").click(function(){ deleteModulBox(); });
	
	// #コンテンツの読み込み
	var params = "";
	$.ajax({
		type: "post",
		url: url,
		data: params,
		dataType: "html",
		success: function(msg){ $("body #modulBackGround div#modulBox div#ajaxContent").html(msg); },
		error: function(XMLHttpRequest,textStatus,errorThrown){ alert("XMLHttpRequest: "+XMLHttpRequest+"\ntextStatus: "+textStatus+"\nerrorThrown: "+errorThrown); }
	});
}
function moveModulBox(){
	if($("body #modulBackGround").html() == null){
		return ;
	}
	var scrollTop;
	if(document.documentElement.scrollTop){
		scrollTop = document.documentElement.scrollTop;
	}else{
		scrollTop = document.body.scrollTop;
	}
	if(document.documentElement.clientHeight){
		windowHeight = document.documentElement.clientHeight;
	}else{
		windowHeight = document.body.clientHeight;
	}
	var moduleTop = scrollTop + windowHeight / 2 - 285 / 2 ;
	$("body #modulBackGround #modulBox").css("top",moduleTop+"px");
}
function deleteModulBox(){
	$("body #modulBackGround").remove();
}

