function chgBnrF(num){
nowBnr = num;
document.getElementById("bnrA").style.top = ((num-1)*42+16) + 'px';
document.getElementById("bnrU").firstChild.href = bnrLink[num];
document.getElementById("bnrU").firstChild.target = bnrTarget[num];

document.getElementById("bnrU").firstChild.firstChild.src = bnrImage[num];
}

firstAlphaFlg = true;

function chgBnr(num){
if(selectedBnrNum == nowBnr){
return;
}
per = 0;
if(!firstAlphaFlg){
clearInterval(myAlpha);
}
if(num == 0){
if(nowBnr < 5){
nowBnr++;
} else {
nowBnr = 1;
}
num = nowBnr;
} else {
nowBnr = num;
}
document.getElementById("bnrA").style.top = ((num-1)*42+16) + 'px';
document.getElementById("bnrU").firstChild.href = bnrLink[num];
document.getElementById("bnrA").firstChild.href = bnrLink[num];
document.getElementById("bnrU").firstChild.target = bnrTarget[num];

document.getElementById("bnrU").firstChild.firstChild.style.opacity = 0;
document.getElementById("bnrU").firstChild.firstChild.style.MozOpacity = 0;
document.getElementById("bnrU").firstChild.firstChild.style.filter = 'alpha(opacity = 0)';
document.getElementById("bnrU").firstChild.firstChild.src = bnrImage[num];

myAlpha = setInterval("alpha(" + num + ")",70);
firstAlphaFlg = false;
SetSubCookieTopNoExpires("ss","screen",num);
}

function alpha(num){
per = per + 25;
document.getElementById("bnrU").firstChild.firstChild.style.opacity = per/100;
document.getElementById("bnrU").firstChild.firstChild.style.MozOpacity = per/100;
document.getElementById("bnrU").firstChild.firstChild.style.filter = 'alpha(opacity = ' + per + ')';
if(per == 100){
clearInterval(myAlpha);
}
}

function moveBnrSet(){
if(xmasStatus == 1){
setTimeout("moveBnrSet2()",1800);//xmasだったら、ここでやっと最初のバナーを表示する
}
if(topbnStartStatus == 1){ //topbnが表示されるときのみJSP側でtopbnStartStatusに「1」が入る
myMove = setInterval("moveBnr()",5000);
}
}

function moveBnrSet2(){
chgBnrF(dispScreen);
document.getElementById("bnrU").firstChild.firstChild.style.opacity = 0;
document.getElementById("bnrU").firstChild.firstChild.style.MozOpacity = 0;
document.getElementById("bnrU").firstChild.firstChild.style.filter = 'alpha(opacity = 0)';
per = 0;
myAlpha = setInterval("alpha()",70);
document.getElementById("bnrL").style.display = "block";
document.getElementById("bnrA").style.display = "block";
}

function moveBnr(){
chgBnr(0);
}

//window.onload = moveBnrSet; → 下部のonloadで起動

function selectedBnr(num){
selectedBnrNum = num == 9 ? nowBnr : num; //「9」はデカいバナーにmouseover時のもの
chgBnr(num);
}

function selectedBnrOut(){
selectedBnrNum = 0;
}

function initializeExternalLink () {
	$$ ("a.external").each (function (link) {
		link.target = "_blank";
	});
}
function initializeFeatureTab() {
	var tab = new Fabtabs ("feature-tab");
	var id = GetSubCookieTop("ss","top-feature-tab") || (GetSubCookieTop ("mnxset","dummy") == "true" ? "news" : "first");
	tab.setActiveTab (id);
	tab.onAfterChange = function (id) {
		SetSubCookieTopNoExpires("ss","top-feature-tab",id)
	};
}

function initializeMarketTab() {
	var tab = new Fabtabs ("feature-tab");
	var id = "report"
	tab.setActiveTab(id);
	tab.onAfterChange = function (id) {
		SetSubCookieTopNoExpires("ss","top-feature-tab",id)
	};
}

function initializeToolSequence () {
	Sortable.create ("tool", { format: /((.+))/, handle: "handle", tag: "div", onUpdate: function () {
		SetSubCookieTop("mnxset","top-tool-sequence",Sortable.sequence ("tool"))
	}});
	var sequence = GetSubCookieTop("mnxset","top-tool-sequence");
	if (sequence) {
		Sortable.setSequence ("tool", sequence.split (","))
	}
}
function initializeToolDisplay () {
	var display = GetSubCookieTop("mnxset","top-tool-display");
	if (display) {
		display.split (",").each (function (id) {
			updateToolDisplay (id);
		});
	}
	var buttons = $$ ("div#tool div.tool h2 span");
	buttons.each (function (button) {
		Event.observe (button, "click", function (e) {
			updateToolDisplay (Event.element (e).parentNode.parentNode.id);
		}, false);
	});
}
function updateToolDisplay (id) {
	Element.toggleClassName (id, "collapsed");
	var array = [];
	$$ ("div#tool div.tool").each (function (tool) {
		if (Element.hasClassName (tool, "collapsed")) {
			array.push (tool.id);
		}
	});
	SetSubCookieTop("mnxset","top-tool-display",array.join (","))
}
function initializeStockTab () {
	var tab = new Fabtabs ("stock-tab");
	var id = GetSubCookieTop("mnxset","top-stock-tab");
	if (id) {
		tab.setActiveTab (id);
	};
	tab.onAfterChange = function (id) {
		SetSubCookieTop("mnxset","top-stock-tab",id)
	};
}
window.onload = function () {
	// __clearCookie ();
	initializeExternalLink ();
	
	initializeToolSequence ();
	initializeToolDisplay ();
	initializeStockTab ();
moveBnrSet();
};
function __clearCookie () {
	eraseCookie ("top-feature-tab");
	eraseCookie ("top-news-tab");
	eraseCookie ("top-tool-sequence");
	eraseCookie ("top-tool-display");
	eraseCookie ("top-stock-tab");
}
