/**
 * ILLUST イラスト ページスクリプト
 **/
var illust_Img = new Array();
var illust_timeout = new Array();
var illust_menu = null;
var opa_n = null;

function illustLoad(){
	illust_menu = my$("illust_menu");
	var param = {
		type : "get",
		dataType : "html",
		contentType : "text/html;charset=utf-8"
	};
	$("#maintext").ajaxStart(function(){
		//読み込み前準備処理
		$("#maintitle").html("ILLUST");
	}).load("./illust/text.html",null,function(data,stat){
		//読み込み成功処理
		this.innerHTML = data;
		var a = my$("illust-list").getElementsByTagName("img"),
		    l = a.length,
		    tmp;
		for(var i = 0;i < l;i++){
			a[i].onload = function(){$(this).fadeIn("slow");};
			a[i].style.display="none";
			a[i].onclick = illustClick;
			a[i].setAttribute("num",i);
		}
		mainShow();
	});
}

function illustClick(){
	illust_Img = new Array();
	var a = my$("illust-list").getElementsByTagName("img");
	var l = a.length;
	var tmp;
	for(var i = 0;i < l;i++){
		tmp = a[i].getAttribute("src").split("sum");
		if(document.all){
			illust_Img.push(tmp[0]+"illust/"+tmp[2]);
		}else{
			illust_Img.push("./"+tmp[0].substr(1)+"illust/"+tmp[2]);
		}
	}
	illustFunc(this.getAttribute("num"));
}

function illustFunc(num){
	if(illust_Img)
		illust_a = illust_Img;
	if(!(num == null))
		illust_n = num;
	var abc;
	
	var l = illust_timeout.length;
	for(var i = 0;i < l;i++){
		clearTimeout(illust_timeout[i]);
	}
	illust_timeout = new Array();
	
	abc = my$("illust_pic");
	abc.style.visibility = "hidden";
	abc.src = illust_a[illust_n];
	abc.parentNode.style.display = "block";
	abc.onload=function(){
		var path = "./illust/comment/com" + illust_a[illust_n].split('img/illust/')[1].split('.jpg')[0] + ".comment";
		var param = {
			type : "get",
			dataType : "html",
			contentType : "text/html;charset=utf-8"
		};
		illustResize();
		$("#illust_contents").load(path,null,function(data,stat){
			//読み込み成功処理
			this.innerHTML = "<pre>"+data+"</pre>";
			my$("illust_menu_sub").style.top  = (this.offsetTop + this.scrollHeight + 80) + "px";
			my$("illust_shadow").style.height = (this.offsetTop + this.scrollHeight + 80) + "px";
		});
		//読み込み処理
	}
}

function illustResize(){
	var abc;
	var con = my$("illust_contents");
	if(abc = my$("illust_pic")){
		a = document.body.clientHeight - abc.clientHeight - illust_menu.clientHeight;
		if(a > 0){
			a = parseInt(a/2,10);
			abc.style.top = illust_menu.clientHeight + a + "px";
		}else{
			abc.style.top = illust_menu.clientHeight+"px";
		}
		b = document.body.clientWidth - abc.clientWidth;
		if(b > 0){
			b = parseInt(b/2,10);
			abc.style.left = b + "px";
		}else{
			abc.style.left = "0px";
		}
		con.style.top  = parseInt(abc.style.top.split("px")[0],10)  + abc.clientHeight + 10 + "px";
		con.style.left = parseInt(abc.style.left.split("px")[0],10) + 30 + "px";
	}
	opa_n = abc;
	illustFed();
}

function illustFed(){
	var t = 0;
	var tt= 50;
	var nu= 10;
	for(var i = 1;i <= nu;i++){
		t = tt*i+tt;
		illust_timeout.push(setTimeout("opacity_change('"+i*0.1+"')",t));
	}
}

function pic_next(){
	var len = illust_a.length;
	var n   = illust_n;
	if(n < (len - 1 ))
		n++;
	else
		n = 0;
	illustFunc(n);
}
function pic_before(){
	var len = illust_a.length;
	var n   = illust_n;
	if(n <= 0)
		n = len - 1;
	else
		n--;
	illustFunc(n);
}
function pic_close(){
	my$("illust_tool").style.display = "none";
	illust_n = null;
}

function opacity_change(p){
	if(opa_n){
		opa_n.style.visibility = "visible";
		if(document.all){
			opa_n.style.filter="Alpha(opacity="+(100*p)+")";
		}else{
			opa_n.style.opacity = p;
		}
	}
}