/*

	page scroll etc...
	
	author :Live!Ads oka
	lastupdate :090717
	
================================================== */


var page = {};

page.current = 1;

page.addLoadEvent = function(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			func();
			oldonload();
		}
	}
};

//---

page.init = function(){
	var x = 1;
/*
	while(document.getElementById("Chapter_" + x)){
		x++;
	}
*/	
	
	var url = document.URL;
	var array = true;
	if(url.indexOf("?") > 0){
		var array = url.split("?");
		array = array[1].split("&");
		for(var i=0;i<array.length;i++){
			array[i] = array[i].split("=");
			var hash = array[i][0];
			var value = array[i][1];
			
			array = new Array();
			array[hash] = value;
		}
	}
	if(array == ""){
		page.turn(array["Page"]);
	}else{
		//page number make
		page.none();
	}
	var flashDelayCall = setInterval(function (){startFlash(1);clearInterval(flashDelayCall)},500);
};


//page number make
page.pageNumber = function(num){
	
	var pagediv = document.getElementById("PageNum");
	var src = "";
	var num_val = "";

	src += '<ul>';
	for(i=1;i<=num;i++){
		if(i < 10){
			num_val ="0" + i;
		}else{
			num_val = i;
		}
		
		if(i == this.current){
			src +='<li class="current"><a href="#" onclick="return page.turn('+i+',this);">' + num_val + '</a></li>';
		}else{
			src +='<li><a href="#" onclick="return page.turn('+i+',this);">' + num_val + '</a></li>';
		}
	}
	src += '</ul>';
	pagediv.innerHTML = src;
	
};


//page none
page.none = function(){
	var id = "Chapter_0";
	var i=1;
	while(document.getElementById(id + i)){
		document.getElementById(id + i).style.display = "none";
		document.getElementById(id + i).style.marginLeft = "0px";
		i++;
	}
	
	document.getElementById(id + page.current).style.display = "block";
	
	if(typeof document.body.style.maxHeight != "undefined"){
		document.getElementById(id + page.current).style.marginLeft = ((page.current - 1) * 980) + "px";
	}else{
		document.getElementById(id + page.current).style.marginLeft = ((page.current - 1) * 490) + "px";
	}
};
//page block
page.block = function(){
	var id = "Chapter_0";
	var i=1;
	while(document.getElementById(id + i)){
		document.getElementById(id + i).style.marginLeft = "0px";
		document.getElementById(id + i).style.display = "block";
		i++;
	}
};

//page turn
page.turn = function(num){
	SmoothScroll(num,0);
	return false;
};
page.turn_02 = function(num){
	if(num == this.current){
		return;
	}
	this.block();
	if(page.lock == 0){
		page.lock  = 1;


		var width = 980;
		var start = width * (page.current - 1); 
		var last = width * (num - 1);
		var move = Math.abs(last - start);
		var move_Value = new Array();
		width = move;
		
		if(num < page.current){
			var pal = "-";
		}else{
			var pal = "";
		}

		var i=0;
		while(move > 1){
			move = Math.floor(move * (0.95 - (i * 0.0035)));
			move_Value[i] = move;
			i++;
		}
		
		for(y=0;y<move_Value.length;y++){
			move_Value[y] = width - move_Value[y];
			move_Value[y] = eval(pal + move_Value[y]);
		}
		
		
		
		var div = document.getElementById("Main-Text");
		var pos = 0;
		var timer;
		var x = 0;
		
		resetFlash(num);
		timer = setInterval(function(){
			if(move_Value[x]){
				pos = move_Value[x];
				div.style.marginLeft = "-" + Math.abs(start + pos) + "px";
				x++;
			}else{
				clearInterval(timer);
				div.style.marginLeft = "-" + last + "px";
				page.lock = 0;
				page.current = num;
				page.none();
				startFlash(num);
			}
		},35);


		
	}
	
	
	return false;
	
	
	
	
	
};

page.lock = 0;
page.addLoadEvent(page.init);


function SmoothScroll(num,end_val,Obj){
	//移動位置
	if(Obj){
		var id = Obj.href.substring(Obj.href.indexOf("#")+1,Obj.href.length);
		var end = document.getElementById(id).offsetTop - 15;
		var IE='\v'=='v';
		if(IE && !document.querySelectorAll){
			end += 525;
		}
	}else{
		var end = end_val;
	}
	
	if(end != 0){
		scrollTo(0,end);
		return;
	}else{
		end = 0;
	}


	
	//現在位置
	var start=window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
	var flag="up";

	function scrollMe(start,end,flag) {
		var timer = setInterval(
			function(){
				if(flag=="up" && start >= end){
					start=start-Math.floor((start-end) * 0.12) -1;
					window.scrollTo(0,start)

				}
				else{
					clearInterval(timer);
					scrollTo(0,end);
					page.turn_02(num);
				}
			}
			,30
		);
		
	}
	scrollMe(start,end,flag);
}




function note(a){
	var dd = a.parentNode.parentNode.getElementsByTagName("dd")[0];
	var dt = a.parentNode.parentNode.getElementsByTagName("dt")[0];
	
	var height = dd.getElementsByTagName("p")[0].offsetHeight;
	var move = Math.abs(height);
	var move_Value = new Array();
	var x=0;
	var i=0;
	var timer;
	while(move > 1){
		move = Math.floor(move * 0.85);
		move_Value[i] = move;
		i++;
	}


	if(dd.style.height != height + "px"){//open
		for(y=0;y<move_Value.length;y++){
			move_Value[y] = height - move_Value[y];
		}
		clearInterval(timer);
		timer = setInterval(function(){
			if(move_Value[x]){
				pos = move_Value[x];
				dd.style.height = pos + "px";
				dt.style.top = "-" + pos + "px";
				x++;
			}else{
				clearInterval(timer);
				dd.style.height = height + "px";
				dt.style.top = "-" + height + "px";
			}
		},30);
		
	}else{//close
		clearInterval(timer);
		timer = setInterval(function(){
			if(move_Value[x]){
				pos = move_Value[x];
				dd.style.height = pos + "px";
				dt.style.top = "-" + pos + "px";
				x++;
			}else{
				clearInterval(timer);
				dd.style.height = "1px";
				dt.style.top = "0px";
			}
		},30);
		
	}
	
	
	return false;
}



var Solar = {};
Solar.Close = function(a){
	var dd = a.parentNode.parentNode.parentNode.parentNode.getElementsByTagName("dd")[0];
	var img = a.parentNode.parentNode.parentNode.parentNode.getElementsByTagName("dt")[0].getElementsByTagName("img")[0];
	var height = dd.getElementsByTagName("div")[0].offsetHeight;
	var move = Math.abs(height);
	var move_Value = new Array();
	var x=0;
	var i=0;
	var timer;
	while(move > 1){
		move = Math.floor(move * 0.85);
		move_Value[i] = move;
		i++;
	}
	clearInterval(timer);
	timer = setInterval(function(){
		if(move_Value[x]){
			pos = move_Value[x];
			dd.style.height = pos + "px";
			x++;
		}else{
			clearInterval(timer);
			dd.style.height = "1px";
			img.src = "img/solar_system_dt.gif";
		}
	},30);
	
	return false;
};
Solar.Open = function(a){
	
	
	var dd = a.parentNode.parentNode.getElementsByTagName("dd")[0];
	
	var height = dd.getElementsByTagName("div")[0].offsetHeight;
	var move = Math.abs(height);
	var move_Value = new Array();
	var x=0;
	var i=0;
	var timer;
	while(move > 1){
		move = Math.floor(move * 0.85);
		move_Value[i] = move;
		i++;
	}
	
	var img = a.getElementsByTagName("img")[0];
	if(img.src.indexOf("02.gif") < 0){//open
		for(y=0;y<move_Value.length;y++){
			move_Value[y] = height - move_Value[y];
		}
		clearInterval(timer);
		timer = setInterval(function(){
			if(move_Value[x]){
				pos = move_Value[x];
				dd.style.height = pos + "px";
				x++;
			}else{
				clearInterval(timer);
				dd.style.height = height + "px";
			}
		},30);
		
		img.src = "img/solar_system_dt_02.gif";
		
	}else{//close
		clearInterval(timer);
		timer = setInterval(function(){
			if(move_Value[x]){
				pos = move_Value[x];
				dd.style.height = pos + "px";
				x++;
			}else{
				clearInterval(timer);
				dd.style.height = "1px";
			}
		},30);
		img.src = "img/solar_system_dt.gif";
	}

	return false;
}




var flash = {};
flash.version = "9.0.0";

flash.navi = function(){
	var num = 5;
	var alt = ["INTRODUCTION","SHARP'S SOLAR SOLUTIONS","MEETING THE WORLD'S NEEDS","BUSINESS'S SOLAR GAINS","SOLAR'S NEXT GIANT STEP"]
	var src = "";
	src += '<ul class="navi">';
	for(i=1;i<=5;i++){
		if(i<=num){
			if(this.navi_current == i){
				src +='<li><img src="img/navi_0' + i + '_on.gif" alt="' + alt[i-1] + '" width="240" height="60" /></li>';
			}else{
				if (swfobject.hasFlashPlayerVersion(this.version)) {
					src +='<li><object height="60" width="240" type="application/x-shockwave-flash" data="img/navi0' + i + '.swf" id="Navi_0' + i + '"><param name="movie" value="img/navi0' + i + '.swf" /><param name="quality" value="best"/><param name="wmode" value="transparent"/><param name="name" value="Navi_0' + i + '"/>';
					src +='</object></li>';
				}else{
					src +='<li><a id="Navi_0' + i + '" href="#Chapter_0' + i + '" onclick="return page.turn(' + i + ',this);"><img src="img/navi_0' + i + '.gif" class="hover" alt="' + alt[i-1] + '" width="240" height="60" /></a></li>';				
				}
			}	
		}else{
			src +='<li><img src="img/navi_0' + i + '_non.gif" alt="' + alt[i-1] + '" width="240" height="60" /></li>';
		}
	}
	src += '</ul>';
	document.write(src);
	this.navi_current++;
};
flash.navi_current = 1;


flash.main = function(num){
	var src = "";
	src += '<h2>';
	
	if (swfobject.hasFlashPlayerVersion(this.version)) {
	//	src += '<object height="400" width="980" type="application/x-shockwave-flash" data="img/h2_0' + num + '.swf"><param name="movie" value="img/h2_0' + num + '.swf" /><param name="id" value="main-ie_external-0' + num + '"/><param name="quality" value="best"/><param name="wmode" value="transparent"/><param name="bgcolor" value="#ffffff"/><param name="name" value="main-ie_external-0' + num + '"/></object>';
		src += '<object height="400" width="980" type="application/x-shockwave-flash" data="img/h2_0' + num + '.swf" id="main-ie_external-0' + num + '"><param name="movie" value="img/h2_0' + num + '.swf" /><param name="allowScriptAccess" value="always"/><param name="quality" value="best"/><param name="wmode" value="transparent"/><param name="bgcolor" value="#ffffff"/></object>';
	}else{
		src +='<img src="img/h2_0' + num + '.jpg" alt="" width="980" height="400" />';				
	}
	
	//src +='<img src="img/h2_0' + num + '.jpg" alt="" width="980" height="400" />';				
	src += '</h2>';
	document.write(src);
};
flash.next = function(num){
	var src = "";
	src += '<object height="60" width="240" type="application/x-shockwave-flash" data="img/navi0' + num + '.swf"><param name="movie" value="img/navi0' + num + '.swf" /><param name="quality" value="best"/><param name="allowScriptAccess" value="always"/><param name="wmode" value="transparent"/></object>';
	document.write(src);
};




/*

2009/07/22追加　by tanaka@pixelimage

・173行目にも追加 ＞　startFlash(num)
・394行目のSWF貼り付けコードも修正。IDまわりを、対応するように書き換え

チャプターを表示し終わった瞬間に、コールされ、
SWFファイルに、スタートをコールする。


*/

function swfTarget(str) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[str];
	} else {
		return document[str];
	}
}
function startFlash(num){
	swfTarget('main-ie_external-0'+num).openFunc();
}

function resetFlash(num){
	if (navigator.appName.indexOf("Microsoft") != -1) {
	swfTarget('main-ie_external-0'+num).closeFunc();
	}
}

