﻿function $_(id){
	if(typeof id === 'string') return document.getElementById(id);
	else return id
}

if( ! Array.prototype.contains ){
	Array.prototype.contains = function( value ){
		for(var i in this){
			if( this.hasOwnProperty(i) && this[i] === value){
				return true;
			}
		}
		return false;
	}
}

function setEvent(obj,ev,str){
	if(document.all) obj.setAttribute(ev,new Function(str))
	else obj.setAttribute(ev,str)
}

function add0(n){
	if(n<10) return '0'+n
	else return n
}

var talentdata
var schdata
var schcount = 1
var animdata = new Array()
var counters = new Array()
var animbank = 0

function chgbank(n){
	animbank = n
	if(!animdata[animbank]) animdata[animbank] = new Array()
}

function regist(func){
	animdata[animbank].push(func)
}

function do_one(){
	for(var i=0; i<animdata.length; i++){
		if(!counters[i]) counters[i]=0
		counters[i]++
		if(animdata[i].length>0){
			var func = animdata[i][0]
			if(func(counters[i])==false){
				animdata[i].shift()
				counters[i] = 0
			}
		}
	}
}

function setop(id,p){
	var target = $_(id)
	if(!target) return
	target.style.filter = 'alpha(opacity:' + p + ')'
	target.style.opacity = p/100
}

function fade_in(id,count){
	if(count>5) return false
	setop(id,count*20)
	$_(id).style.top = (45-count) + "px"
	return true
}

function fade_out(id,count){
	if(count>5) return false
	setop(id,100-count*20)
	$_(id).style.top = (40+count) + "px"
	return true
}

function fade_in2(id,count){
	if(count>3) return false
	setop(id,count*33)
	return true
}

function fade_out2(id,count){
	if(count>3) return false
	setop(id,99-count*33)
	return true
}

function wait_sec(s,count){
	if(count>s*10) return false
	return true
}

function change(){
	tbl = new Array()
	for(var i=0; i<5; i++){
		var idx = i+1
		var pos
		do{
			pos = Math.floor( Math.random() * talentdata['タレントリスト']['タレント'].length )
		}while(tbl.contains(pos))
		tbl.push(pos)
		var target = $_('area'+idx)
		var targetlink = $_('link'+idx)
		var obj = talentdata['タレントリスト']['タレント'][pos]
		targetlink.href = obj['リンク']
		setop(target,0)
		target.src = obj['サムネイル']
		target.alt = obj['名前']
	}
	chgbank(0)
	regist(function(count){ return fade_in('area1',count) })
	regist(function(count){ return fade_in('area2',count) })
	regist(function(count){ return fade_in('area3',count) })
	regist(function(count){ return fade_in('area4',count) })
	regist(function(count){ return fade_in('area5',count) })
	regist(function(count){ return wait_sec(5,count) })
	regist(function(count){ return fade_out('area1',count) })
	regist(function(count){ return fade_out('area2',count) })
	regist(function(count){ return fade_out('area3',count) })
	regist(function(count){ return fade_out('area4',count) })
	regist(function(count){ return fade_out('area5',count) })
	regist(function(count){ change(); return false })
}

function sch_change(){
	var data = schdata['panel'][schcount-1]
	$_('panellink').href = data['url']
	$_('panel').alt = data['name']
	$_('panel').src = 'panel/live' + add0(schcount) + '_off.gif'
	setEvent($_('panel'),'onmouseover','this.src="panel/live' + add0(schcount) + '_on.gif"')
	setEvent($_('panel'),'onmouseout','this.src="panel/live' + add0( schcount) + '_off.gif"')
	schcount++
	var max = schdata['panel'].length
	if(schcount>max) schcount = 1
	chgbank(1)
	regist(function(count){ return fade_in2('panel',count) })
	regist(function(count){ return wait_sec(6,count) })
	regist(function(count){ return fade_out2('panel',count) })
	regist(function(count){ sch_change(); return false })
}

window.onload = function(){
	var ttc = "<div id=\"top_talent_bg\" style=\"position: relative; z-index: 1; background-image: url('parts_img/top_talent_bg.jpg'); width: 627px; height: 179px\">\n<a href=\"http://www.asaikikaku.co.jp/profile/index.html\"><img id=\"btn1\" src=\"parts_img/btn_off1.png\" style=\"position: absolute; z-index: 2; left: 26px; top: 7px\" onmouseover=\"this.src='parts_img/btn_on1.png'\" onmouseout=\"this.src='parts_img/btn_off1.png'\"></a>\n<a href=\"http://www.asaikikaku.co.jp/profile/dansei.html\"><img id=\"btn2\" src=\"parts_img/btn_off2.png\" style=\"position: absolute; z-index: 2; left: 158px; top: 12px\" onmouseover=\"this.src='parts_img/btn_on2.png'\" onmouseout=\"this.src='parts_img/btn_off2.png'\"></a>\n<a href=\"http://www.asaikikaku.co.jp/profile/jyosei.html\"><img id=\"btn3\" src=\"parts_img/btn_off3.png\" style=\"position: absolute; z-index: 2; left: 249px; top: 12px\" onmouseover=\"this.src='parts_img/btn_on3.png'\" onmouseout=\"this.src='parts_img/btn_off3.png'\"></a>\n<a href=\"http://www.asaikikaku.co.jp/profile/bunkajin.html\"><img id=\"btn4\" src=\"parts_img/btn_off4.png\" style=\"position: absolute; z-index: 2; left: 339px; top: 12px\" onmouseover=\"this.src='parts_img/btn_on4.png'\" onmouseout=\"this.src='parts_img/btn_off4.png'\"></a>\n<a href=\"http://www.asaikikaku.co.jp/profile/wakate.html\"><img id=\"btn5\" src=\"parts_img/btn_off5.png\" style=\"position: absolute; z-index: 2; left: 430px; top: 12px\" onmouseover=\"this.src='parts_img/btn_on5.png'\" onmouseout=\"this.src='parts_img/btn_off5.png'\"></a>\n<a href=\"http://www.asaikikaku.co.jp/profile/kousei.html\"><img id=\"btn6\" src=\"parts_img/btn_off6.png\" style=\"position: absolute; z-index: 2; left: 520px; top: 12px\" onmouseover=\"this.src='parts_img/btn_on6.png'\" onmouseout=\"this.src='parts_img/btn_off6.png'\"></a>\n\n<a id=\"link1\" href=\"\"><img id=\"area1\" src=\"talentimg/blank.png\" style=\"position: absolute; z-index: 2; left: 37px; top: 40px\" onerror=\"src='talentimg/blank.png'\"></a>\n<a id=\"link2\" href=\"\"><img id=\"area2\" src=\"talentimg/blank.png\" style=\"position: absolute; z-index: 2; left: 148px; top: 40px\" onerror=\"src='talentimg/blank.png'\"></a>\n<a id=\"link3\" href=\"\"><img id=\"area3\" src=\"talentimg/blank.png\" style=\"position: absolute; z-index: 2; left: 262px; top: 40px\" onerror=\"src='talentimg/blank.png'\"></a>\n<a id=\"link4\" href=\"\"><img id=\"area4\" src=\"talentimg/blank.png\" style=\"position: absolute; z-index: 2; left: 371px; top: 40px\" onerror=\"src='talentimg/blank.png'\"></a>\n<a id=\"link5\" href=\"\"><img id=\"area5\" src=\"talentimg/blank.png\" style=\"position: absolute; z-index: 2; left: 483px; top: 40px\" onerror=\"src='talentimg/blank.png'\"></a>\n</div>\n"
	$_("top_talent_container").innerHTML = ttc
	var sc = "<div id=\"schedule_bg\" style=\"position: relative; z-index: 1; background-image: url('parts_img/live_schedule_bg.jpg'); width: 627px; height: 238px\">\n<a id=\"panellink\" href=\"\"><img id=\"panel\" src=\"blank.png\" style=\"position: absolute; z-index: 2; left: 27px; top: 65px\"></a>\n<a id=\"bannerlink1\" href=\"\"><img id=\"banner1\" src=\"parts_img/schedule_b1_off.gif\" style=\"position: absolute; z-index: 2; left: 328px; top: 38px\" onmouseover=\"this.src='parts_img/schedule_b1_on.gif'\" onmouseout=\"this.src='parts_img/schedule_b1_off.gif'\"></a>\n<a id=\"bannerlink2\" href=\"\"><img id=\"banner2\" src=\"parts_img/schedule_b2_off.gif\" style=\"position: absolute; z-index: 2; left: 328px; top: 134px\" onmouseover=\"this.src='parts_img/schedule_b2_on.gif'\" onmouseout=\"this.src='parts_img/schedule_b2_off.gif'\"></a>\n</div>\n"
	$_("schedule_container").innerHTML = sc
	var http = new JKL.ParseXML('talentlist.xml')
	talentdata = http.parse()
	http = new JKL.ParseXML.JSON('schedule.js')
	schdata = http.parse()
	$_('bannerlink1').href = schdata['banner'][0]['url']
	$_('bannerlink2').href = schdata['banner'][1]['url']
	change()
	sch_change()
	setInterval("do_one()",100)
}

