// JavaScript Document

var wH;
var wW = 883;

$(function(){
	wH = $("#outContainer").height();	
	
	$(".movieWrap img").click(function(){
		moviebox("#movie");
	});
	
	$(".bg").click(function(){
		
		$(this).next().slideUp(500, function(){
			$(this).parent().css({
				"display": "none"
			});
			$("#swfMovie").remove();
			$(this).append("<div id='swfMovie'>動画を再生するには最新のFlash Playerが必要です。</div>");
		});
		
		$(window).unbind("resize");
	});
	
	$("p#close img").click(function(){
		
		$(this).parent().parent().slideUp(500, function(){
			$(this).parent().css({
				"display": "none"
			});
			$("#swfMovie").remove();
			$(this).append("<div id='swfMovie'>動画を再生するには最新のFlash Playerが必要です。</div>");
		});
		
		$(window).unbind("resize");
	});
})

function moviebox(id){
	
	var flashvars = {};

	var attributes = {
		id: "swfMovie",
		name: "swfMovie"
	};
	
	var params = {
		allowScriptAccess: "always",
		allowFullScreen: "false",
		quality: "high",
		wmode: "transparent"
	};

	swfobject.embedSWF("swf/player.swf", "swfMovie", "585", "380", "10.0.22.87", "", flashvars, params, attributes, function(){
		$(id).css({"display": "block"});
		sizeSet(id);
		$(id).children(".popcontents").slideDown(500);
	});

	
	$(window).bind("resize", function(){
		sizeSet(id);
	});
}

function sizeSet(id){
	var h = $(window).height();
	var w = $(window).width();
	
	h = (h > wH) ? h : wH;
	w = (w > wW) ? w : wW;
	
	$(id).css({
		"width": w,
		"height": h
	});
	
	$(id).children(".bg").css({
		"width": w,
		"height": h
	});
	
	var cH = 380;
	var cW = 585;
	
	var mt = (($(window).height()-cH)/2 > 0) ? ($(window).height()-cH)/2: 0;
	var ml = (($(window).width()-cW)/2 > 0) ? ($(window).width()-cW)/2: 0;
	
	$(id).children(".popcontents").css({
		"top": mt,
		"left": ml
	});
}
