
var cubePeterBlogpartsCharaDivWidth = "FULL";

var cubePeterBlogpartsBackgroundInited = false;

function cubePeterBlogparts_ChangeCharaDivWidth(size){
	if(cubePeterBlogpartsCharaDivWidth != size) {
		cubePeterBlogpartsCharaDivWidth = size;
		cubePeterBlogpartsSetSize();
		cubePeterBlogpartsSetPosition();
	}
}


function cubePeterBlogparts_startMousePositionTracking(){
	ael(window.document,"mousemove",cubePeterBlogparts_mouseMove, false);
	
	cubePeterBlogparts_ChangeCharaDivWidth(200);
}

function cubePeterBlogparts_stopMousePositionTracking(){
	rel(window.document,"mousemove",cubePeterBlogparts_mouseMove, false);
	cubePeterBlogparts_ShowBackDiv();
}

function cubePeterBlogparts_mouseMove(e){
	var tbody = document['CSS1Compat' == document.compatMode ? 'documentElement' : 'body'];
	var tx,ty,tw,th;
	if(e) {
		tx = e.clientX;
		ty = e.clientY;
	} else {
		tx = event.x + document.body.scrollLeft;
		ty = event.y + document.body.scrollTop;
	}
	
	if (navigator.userAgent.indexOf("MSIE") >= 0) {
		tw = tbody.clientWidth;
		th = tbody.clientHeight;
	} else {
		tw = window.innerWidth;
		th = window.innerHeight;
	}
	
	getMovieName("haijiexternal0").asMouseMove(tx, ty, tw, th);
}

function cubePeterBlogparts_ShowBackDiv(){
	cubePeterBlogpartsBackgroundInited = true;
	cubePeterBlogpartsResize();
	
	if(cubePeterBlogpartsCheckBrowser() == "MSIE") {
		document.getElementById("haijiexternal1").style.width = "100%";
		document.getElementById("haijiexternal1").style.height = "100%";
	}
	
	var w = 0;
	if(cubePeterBlogpartsCheckBrowser() == "MSIE") {
		var tbody = document['CSS1Compat' == document.compatMode ? 'documentElement' : 'body'];
		w = tbody.clientWidth;
	} else {
		w = window.innerWidth - 17;
	}
	
	setTimeout(function() { 
		cubePeterBlogparts_ChangeCharaDivWidth("FULL");
	}, 1);
	setTimeout(function() { 
		getMovieName("haijiexternal0").asSetDivSize(w);
		getMovieName("haijiexternal1").asRunYagi();
	}, 2);
	/*
	setTimeout(function() { cubePeterBlogparts_ChangeCharaDivWidth("FULL"); }, 5);
	setTimeout(function() { getMovieName("haijiexternal0").asSetDivSize(w); }, 5);
	setTimeout(function() { getMovieName("haijiexternal1").asRunYagi(); }, 5);
	*/
}

function cubePeterBlogparts_finishEating(){
	setTimeout(function() { getMovieName("haijiexternal0").asShowHeiji(); }, 5);
}

function cubePeterBlogparts_finishWalkingHeiji(){
	setTimeout(function() { getMovieName("haijiexternal1").asShowTitle(); }, 5);
}

function cubePeterBlogparts_skip(){
	cubePeterBlogparts_ChangeCharaDivWidth("FULL");
	setTimeout(function() { getMovieName("haijiexternal0").asSkip(); }, 5);
	setTimeout(function() { getMovieName("haijiexternal1").asSkip(); }, 10);
}

function cubePeterBlogparts_soundOn(){
	setTimeout(function() { getMovieName("haijiexternal1").asSoundOn(); }, 5);
}

function cubePeterBlogparts_soundOff(){
	setTimeout(function() { getMovieName("haijiexternal1").asSoundOff(); }, 5);
}

function cubePeterBlogparts_reset(){
	cubePeterBlogpartsBackgroundInited = false;
	cubePeterBlogpartsResize();
	
	if(cubePeterBlogpartsCheckBrowser() == "MSIE") {
		document.getElementById("haijiexternal1").style.width = "99%";
		document.getElementById("haijiexternal1").style.height = "99%";
	}
	
	setTimeout(function() { getMovieName("haijiexternal0").asReset(); }, 5);
	setTimeout(function() { cubePeterBlogparts_ChangeCharaDivWidth(200); }, 25);
}

function cubePeterBlogparts_checkBrowser(){
	return cubePeterBlogpartsCheckBrowser();
}

function cubePeterBlogparts_startYagiClone(n0x, n0y, n1x, n1y, n2x, n2y, n3x, n3y, n4x, n4y, n5x, n5y) {
	setTimeout(function() { getMovieName("haijiexternal0").asStartYagiClone(n0x, n0y, n1x, n1y, n2x, n2y, n3x, n3y, n4x, n4y, n5x, n5y); }, 5);
}

function cubePeterBlogpartsInitLayer(){
	var html0 = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='100%' height='100%' id='haijiexternal0' align='middle'><param name='allowScriptAccess' value='always' /><param name='movie' value='http://www2.nissan.co.jp/NOTE/E11/SWF/SPECIAL/CONTENTS/PETER_BLOG/chara.swf' /><param name='scale' value='noscale' /><param name='salign' value='lt' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><embed src='http://www2.nissan.co.jp/NOTE/E11/SWF/SPECIAL/CONTENTS/PETER_BLOG/chara.swf' quality='high' scale='noscale' salign='lt' wmode='transparent' width='100%' height='100%' name='haijiexternal0' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
	
	var lay0 = document.createElement('div');
	lay0.setAttribute('id', 'notePeterBlogpartsCharaDiv');
	lay0.style.position = 'absolute';
	lay0.style.zIndex = 200;
	document.body.appendChild(lay0);
	
	if(cubePeterBlogpartsCheckBrowser() == "MSIE") {
		setTimeout(function() { lay0.innerHTML = html0; }, 1);
	} else {
		lay0.innerHTML = html0;
	}
	
	if(cubePeterBlogpartsCheckBrowser() == "Safari"){
		window.resizeBy(1,0);
	} else {
		document.getElementsByTagName("html")[0].style.overflow = "scroll";
	}
	
	var html1 = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='100%' height='100%' id='haijiexternal1' align='middle'><param name='allowScriptAccess' value='always' /><param name='movie' value='http://www2.nissan.co.jp/NOTE/E11/SWF/SPECIAL/CONTENTS/PETER_BLOG/back.swf' /><param name='scale' value='noscale' /><param name='salign' value='lt' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><embed src='http://www2.nissan.co.jp/NOTE/E11/SWF/SPECIAL/CONTENTS/PETER_BLOG/back.swf' quality='high' scale='noscale' salign='lt' wmode='transparent' width='100%' height='100%' name='haijiexternal1' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
	
	var lay1 = document.createElement('div');
	lay1.setAttribute('id', 'notePeterBlogpartsBackgroundDiv');
	lay1.style.position = 'absolute';
	lay1.style.zIndex = 199;
	//lay1.style.background = "#FF0000";
	document.body.appendChild(lay1);
	
	if(cubePeterBlogpartsCheckBrowser() == "MSIE") {
		setTimeout(function() { lay1.innerHTML = html1; }, 1);
	} else {
		lay1.innerHTML = html1;
	}
	
	ael(window,"resize",cubePeterBlogpartsResize, false);
	ael(window,"scroll",cubePeterBlogpartsScroll, false);
	
	cubePeterBlogpartsResize();
	cubePeterBlogpartsScroll();
}

function cubePeterBlogpartsResize(){
	cubePeterBlogpartsSetSize();
	cubePeterBlogpartsSetPosition();
}

function cubePeterBlogpartsScroll(){
	cubePeterBlogpartsSetPosition();
}


function cubePeterBlogpartsSetPosition(){
	var tbody = document['CSS1Compat' == document.compatMode ? 'documentElement' : 'body'];
	var lay0 = document.getElementById("notePeterBlogpartsCharaDiv");
	var lay1 = document.getElementById("notePeterBlogpartsBackgroundDiv");
	if (navigator.userAgent.indexOf("MSIE") >= 0) {
		lay0.style.left = (tbody.clientWidth + tbody.scrollLeft - divW(lay0)) + "px";
		lay0.style.top =  (tbody.clientHeight + tbody.scrollTop - divH(lay0)) + "px";
		lay1.style.left = (0 + tbody.scrollLeft) + "px";
		lay1.style.top =  (0 + tbody.scrollTop) + "px";
	} else {
		lay0.style.left = (window.innerWidth + pageXOffset - divW(lay0) - 17) + "px";
		lay0.style.top =  (window.innerHeight + pageYOffset - divH(lay0) - 17) + "px";
		lay1.style.left = (0 + pageXOffset) + "px";
		lay1.style.top =  (0 + pageYOffset) + "px";
	}
	
}

function cubePeterBlogpartsSetSize(){
	var tbody = document['CSS1Compat' == document.compatMode ? 'documentElement' : 'body'];
	var lay0 = document.getElementById("notePeterBlogpartsCharaDiv");
	var lay1 = document.getElementById("notePeterBlogpartsBackgroundDiv");
	if (navigator.userAgent.indexOf("MSIE") >= 0) {
		if(cubePeterBlogpartsCharaDivWidth == "FULL") { lay0.style.width = tbody.clientWidth + "px"; }
		else                                          { lay0.style.width = cubePeterBlogpartsCharaDivWidth + "px"; }
		if(cubePeterBlogpartsBackgroundInited) {
			lay1.style.width  = tbody.clientWidth + "px";
			lay1.style.height = tbody.clientHeight + "px";
		} else {
			lay1.style.width  = "10px";
			lay1.style.height = "10px";
		}
	} else {
		if(cubePeterBlogpartsCharaDivWidth == "FULL") {	lay0.style.width = (window.innerWidth - 17) + "px"; }
		else                                          { lay0.style.width = (cubePeterBlogpartsCharaDivWidth - 17) + "px"; }
		if(cubePeterBlogpartsBackgroundInited) {
			lay1.style.width  = (window.innerWidth - 17) + "px";
			lay1.style.height = (window.innerHeight - 17) + "px";
		} else {
			lay1.style.width  = "10px";
			lay1.style.height = "10px";
		}
	}
	lay0.style.height = "340px";
}

function cubePeterBlogpartsCheckBrowser(){if(navigator.userAgent.indexOf("Safari") >= 0){return "Safari";}else if(navigator.userAgent.indexOf("MSIE") >= 0){return "MSIE";}else{return "Netscape";}}
function ael(o, e, f, b){if(o.addEventListener){o.addEventListener(e, f, b);}else if(o.attachEvent){o.attachEvent("on" + e, f);}}
function rel(o, e, f, b){if(o.removeEventListener){o.removeEventListener(e, f, b);}else if(o.detachEvent){o.detachEvent("on" + e, f);}}
function divW (d){return document.layers?d.clip.width:(d.offsetWidth||d.style.pixelWidth||0);}
function divH (d){return document.layers?d.clip.height:(d.offsetHeight||d.style.pixelHeight||0);}
function getMovieName(n){return document.all?window[n]:document[n];}

ael(window,"load",cubePeterBlogpartsInitLayer, false);