/*
	custom abit in Murayama's code by zono
	*add parameter of flashVars
	*add code to get parameters of anchor tag
	*disable mousedown event

	overLayFlash JS: Fullsize FLash Overlays 
	by Ken Murayama - http://www.muraken.biz

	
	本スクリプトの利用、あるいは利用できないことによ・ﾄ発生した損失や損害に対してむもvんならｄ・F-siteは一切責任を負いません。
	自由に改父ﾏA利用してもら・ﾄ構いません。
	但し転載する場合は、引用元を明記し、リンクを張・ﾄください。

*/
//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) ;
	return arrayPageScroll;
}



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);	
	return arrayPageSize;
}


//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
//
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

function showFlash(objLink){
	var file = objLink.href;
	var ver = objLink.ver;
	if(navigator.appName.indexOf("Microsoft") != -1){
		var br = "ie";
	}else{
		var br = "other";
	}
	var arrayPageSize = getPageSize();
	var heightValue = arrayPageSize[3];		//custom adding
	var arrayPageScroll = getPageScroll();	
	var scrollValue = arrayPageScroll[1];	//custom adding
	var objBody = document.body;
	var objOverlay = document.createElement("div");
	//custom adding flashVars
	var myTag= '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+ver+'" width="100%" height="100%" id="overLayFlash" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="movie" value="'+file+'" /><param name="quality" value="high" /><param name="salign" value="lt" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#ffffff" /><param name="FlashVars" value="br='+br+'&amp;df='+dataFolder+'&amp;pic='+picUrl+'&amp;wh='+heightValue+'&amp;scr='+scrollValue+'" /><embed src="'+file+'" quality="high" salign="lt" swLiveConnect=true wmode="transparent" bgcolor="#ffffff" FlashVars="br='+br+'&amp;df='+dataFolder+'&amp;pic='+picUrl+'&amp;wh='+heightValue+'&amp;scr='+scrollValue+'" width="100%" height="100%" name="overLayFlash" id="overLayFlash" align="middle" allowScriptAccess="always" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	
	objOverlay.setAttribute('id','overLay');
	//objOverlay.setAttribute('id','overlay');
	//objOverlay.onclick = function () {hideFlash(); return false;}		//custom disable
	objOverlay.style.display = 'block';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '200';
 	objOverlay.style.width = '100%';
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.innerHTML = myTag;
	objBody.insertBefore(objOverlay, objBody.firstChild);
	//window.document.overLayFlash.onclick = function () {hideFlash(); return false;}		//custom disable
	objOverlay.style.display = 'block';
}


function hideFlash(){
	var objBody = document.body;
	objBody.removeChild(objBody.firstChild);
}

/*
function refreshFlash(){
	window.location.reload();
}
*/

function initoverLayFlash(){

	if (!document.getElementsByTagName){ return; }
	
	var anchors = document.getElementsByTagName("a");

	// loop through all anchor tags
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];

		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "overLayFlash")){
			anchor.onclick = function (e) {
				//custom ブラウザでイベント取得を切り分け
				var targ;   
				if (!e) var e = window.event;	//IE用
				if (e.target) targ = e.target;	//IE外
				else if (e.srcElement) targ = e.srcElement;

    			var revs = new String(targ.getAttribute("rev")).split(";");		//custom add
				dataFolder = revs[0];	//custom add
				picUrl = revs[1];		//custom add

				showFlash(this); 
				return false;
			}
		}
		
	}
	
}


//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//

function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}
}

/* //ExternalInterfaceがIEで不調 ////////////////////
//custom adding func
function thisMovie(movieName) 
{
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];	//IE
    } else {
        return document[movieName];	//Other
    }
}

function getHtmlInfo() 
{
    var page = getPageSize();
    var strPageSize = page[2] + "_" + page[3];
    thisMovie("overLayFlash").sendPageSize(strPageSize);
    thisMovie("overLayFlash").sendPageScroll(arrayPageScroll[1]);
}
///////////////////////////////////////////////// */


//custom adding var
var dataFolder;
var picUrl;


addLoadEvent(initoverLayFlash);	