
/*global $,document,window*/
//0 means disabled; 1 means enabled;
var interstitialStatus = 0;

//loading interstitial with jQuery
function loadInterstitial(){
	//loads interstitial only if it is disabled
	if(interstitialStatus===0){

		$("#backgroundInterstitial").css({
			"opacity": "1.0"
		});
		$("#backgroundInterstitial").show();
		$("#showInterstitial").show();
		$("html").css({
			"overflow": "hidden"
		});

		interstitialStatus = 1;
	}
}

//centering interstitial
function centerInterstitial(){
	//request data for centering

	var windowHeight = document.documentElement.clientHeight;
	//centering
	$("#showInterstitial").css({
		"top": 0,
		"left": 0,
		"width": "100%"

	});
	//only need force for IE6

	$("#backgroundInterstitial").css({
		"height": windowHeight
	});

}

//disabling interstitial with jQuery
function disableInterstitial(){
	//disables interstitial only if it is enabled
	if(interstitialStatus==1){
		$("html").css({
			"overflow": "auto"
		});

		$("#backgroundInterstitial").hide();
		$("#showInterstitial").hide();
		window.scrollTo(0,1); //these two window commands are for
		window.scrollTo(0,0); //Safari and Chrome to get the scroll bars visible again
		//revert back to normal parameters when ad is disabled
		$("#primarystructure").css({
			"display": "block"
		});
		$("#leader_board").css({
			"display": "block"
		});

		interstitialStatus = 0;
	}
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){

if(interstitialStatus==1){
//blank out content upon interstitial load so it
//doesnt  interfere with mouse pointer with flash ads
		$("#content").css({
			"primarystructure": "none"
		});
		$("#leader_board").css({
			"display": "none"
		});
		       }

});

function initInterstitialAd() {
	var CkieLst=document.cookie.split(';');
	var ii=0;
	var HadRB=0;
	var now=new Date();
	var cookies=(navigator.cookieEnabled) ? true : false;
	var query = window.location.search.substring(1);
	var vars = query.split('&');

	if (typeof navigator.cookieEnabled=="undefined" && !cookies) {
		document.cookie="test";
		cookies=(document.cookie=="test") ? true : false;
		document.cookie="";
	}
	if (!cookies) {return(true);}

	//Set Cookie Variable depending on section
	var i_section = "JPHM=";

	var localnow = (new Date()).getTime();
	var when = localnow;
	for (ii=0;ii<CkieLst.length;ii++) {
		if (CkieLst[ii].indexOf(i_section) != -1) {
			var offset=CkieLst[ii].indexOf(i_section);
			when = CkieLst[ii].substr(offset+7,14);
			HadRB=1;
		}
	} //Check if cookie has been set or greater than 8 hours
	if (HadRB < 1 || (localnow - when) > 43200000 ) {
		bbg_show_int = true;
	}
}

function displayInterstitialAd() {
var now=new Date();
var expires=new Date(now.getTime() - (1000 * 60 * 60 * now.getHours()) + (1000 * 60 * 60 * 24));
var localnow = (new Date()).getTime();
//Set Cookie Variable depending on section
	var i_section_c = "JPHM=1-";

	document.cookie=i_section_c + localnow + '; expires=' + expires.toGMTString() + '; domain=bloomberg.co.jp';

	centerInterstitial();
	loadInterstitial();
	$(function() {window.setTimeout("disableInterstitial()",10000);
});
}

function introJump() {
    document.write('<scr'+'ipt type="text/javascript"">var noad=1;</scr'+'ipt>');
}

function HideIntroAd()
{
    if ($("#intro_ad").find("img[src*='empty.gif']").length > 0) {
        document.write('<scr' + 'ipt type="text/javascript"">var noad=1;</scr' + 'ipt>');
    }
 }


