﻿var swf_url;
var mp4_url;
document.isOpen = false;

function BG_show(player) {
	pageTracker._trackPageview('card/'+player);
	swf_url="http://www.humancentrix.com/about/swf/"+player+"/swf/content1.swf";
	mp4_url="http://www.humancentrix.com/top/m_"+player+"/content1.mp4";
	try {

		document.isOpen = true;
		var nd = document.createElement("div");
		nd.id="BG_overlay"
		document.body.appendChild(nd);
		
		$("#BG_overlay").click(BG_remove);
		$(window).resize(BG_position);
		$("#BG_overlay").show();
			

		BG_position();
		$("#popup").fadeIn("fast", onFadeIn);
		
	} catch(e) {
		alert( e );
	}
		

function BG_remove(){

	document.isOpen = false;
	var ifNode = document.getElementById("popupVideo");
	ifNode.innerHTML = ""
	
	
	var callBack = function(){
        $('#BG_overlay').remove();
		$('#BG_overlay').remove();
		$("#popup").css({left:"-1000px"})
		$("#popupVideo").html("");
		$("#flashAd").html(" ");
	}
	$("#popup").fadeOut("fast",callBack);
}




function onFadeIn(){
	$("#popup").css({display:"block"})

	//var vTitle = 'SVP名詞';

	var flashHTML = '';
	
	if (navigator.userAgent.indexOf('iPhone') > 0) {
		flashHTML += '<EMBED SRC="'+mp4_url+'" WIDTH="600" HEIGHT="330" AUTOPLAY="true" CONTROLLER="false">'
	} else if (navigator.userAgent.indexOf('iPad') > 0) {
		flashHTML += '<EMBED SRC="'+mp4_url+'" WIDTH="600" HEIGHT="330" AUTOPLAY="true" CONTROLLER="false">'
	} else{	
	flashHTML += '<object width="600" height="330">'
    flashHTML += '<param name="movie" value="'+swf_url+'"></param>'
    flashHTML += '<param name="allowFullScreen" value="true"></param>'
	flashHTML += '<param name="allowscriptaccess" value="always"></param>'
    flashHTML += '<embed src="'+swf_url+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="600" height="330"></embed>'
	flashHTML += '</object>'
	}
	
	//タイトル
	//$("#popupHeader").find("h2").html(vTitle);

	
	var pop = document.getElementById("popupVideo");
		pop.innerHTML = flashHTML;
	

	
}




function BG_position() {
    
	updatePopupPosition();
	updateOverlay();
}



function updatePopupPosition(){
	//$("#popup").css({display:"none"})
	var w = 620;
	var h = 390;
	var de = document.documentElement;

	var screenW = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var screenH = self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;

	var scrollY = getScrollPosY();

	if(document.isOpen){
		$("#popup").css({left: ((screenW - w)/2)+"px", top: ((screenH - h)/2+scrollY)+"px" });
             
	}else{
		$("#popup").css({top: ((screenH - h)/2+scrollY)+"px" });
                 
	}
}

function updateOverlay(){
	var pageH = getPageH();
	$("#BG_overlay").css("height",pageH +"px");
}


function getScrollPosY() {
    if (typeof window.pageYOffset != 'undefined') {
        return window.pageYOffset;
    }
    else if (typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0) {
        return document.documentElement.scrollTop;
    }
    else if (typeof document.body.scrollTop != 'undefined') {
        return document.body.scrollTop;
    }
    return 0;
}

function getPageH(){

  	if (window.innerHeight && window.scrollMaxY) {	
		return window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		return document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		return document.body.offsetHeight;
  	}
	return 1000;
}

}
