﻿// JavaScript Document
//Browzer movieName Make Up
function flashVersionCheck(){
	return versionNum;
};
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
};

//Flash Version Message
var oldVerMsg = '<div><h4>こちらのコンテンツではAdobe Flash Player の最新バージョンが必要です。</h4><p>Adobe Flash PlayerはAdobeサイトから無償でダウンロードできます。</p><p class="right"><a href="http://www.adobe.com/go/getflashplayer" target="_blank"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Adobe Flash Player を取得" width="112" height="33" /></a></p><p class="center"><a href="#" onclick="disablePopup()" title="閉じる">閉じる</a></p></div>';


//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(moviePath,movieTitle,telopPath){
	
	//BaseURI
	var baseURI = location.protocol+"//"+location.hostname+"/";
	
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.6"
		});
		
		$("#movie").html(oldVerMsg);
		
		var so = new SWFObject(baseURI+"rnavi/movie/flvLoader.swf", "flvLoader", "440", "350", "9", "#ffffff");
		so.addParam("flashvars","filePath="+moviePath+"&movTitle="+movieTitle+"&telopPath="+telopPath);
		so.addParam("allowScriptAccess", "sameDomain");
		so.addParam("loop", "true");
		so.addParam("quality", "best");
		so.addParam("menu", "false");
		
		$("#movie").css("visibility", "visible");
		so.write("movie");
		$("#backgroundPopup").fadeIn("slow",function(){
			$("#popupContact").show();
			popupStatus = 1;
			$("input, select, textarea").css("visibility", "hidden");
			centerPopup();
		});
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#popupContact").hide();
		$("#movie").css("visibility", "hidden");
		$("#movie").html("");
		$("#backgroundPopup").fadeOut("slow",function(){
			popupStatus = 0;
			$("input, select, textarea").css("visibility", "visible");
		});
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = $(window).width();
	var windowHeight = $(window).height();
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").height(windowHeight);
	
}

//CONTROLLING EVENTS IN jQuery
$("body").ready(function(){
	$("body").append('<div id="popupContact"><div id="movie"></div></div><div id="backgroundPopup"></div>');
	//LOADING POPUP
	//Click the button event!
	$("a.htmlBox-light").click(function(){
		var filePath = $(this).attr("rel");
		var fileTitle = $(this).attr("title");
		var telopPath = $(this).attr("rev");
		//centering with css
		centerPopup();
		//load popup
		loadPopup(filePath,fileTitle,telopPath);
		return false;
	});
	
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
	//resize event
	$(window).resize(function(){
		centerPopup();
	});
});

			
			
	
