var oIntval;
var cfstatus = true;

function showCF(flag) {
	var cfbox = document.getElementById('cfbox');
	var cfswitch = document.getElementById('cfswitch');
	var cfplayer = document.getElementById('NSPlay');

	if(cfstatus) {
		cfbox.style.display = 'inline-block';
		oIntval = setInterval(openCF, 10);
		cfswitch.className = 'cfswitch2';
	}
	else {
		cfplayer.filters.alpha.opacity = 0;
		cfplayer.style.display = 'none';
		oIntval = setInterval(closeCF, 10);
		cfswitch.className = 'cfswitch1';
	}
	cfstatus = !cfstatus;
}

function showPlayer(){
	var cfplayer = document.getElementById('NSPlay');
	if(cfplayer.filters.alpha.opacity >= 100){
		clearInterval(oIntval);
		cfplayer.play(); 
	}
	else {
	    cfplayer.filters.alpha.opacity += 2;
	}
}

function openCF() {
	var cf = document.getElementById('cfbox');
	var cfplayer = document.getElementById('NSPlay');
	var w = cf.offsetWidth;
	var x = Math.ceil((330 - w) / 6);
	//x = (w <= 300) ? 30 : 5;
	w += x;
	if(w >= 330) {
		cf.style.width = '330px';
		clearInterval(oIntval);
		cfplayer.style.display = 'block';
		cfplayer.filters.alpha.opacity = 0;
		oIntval = setInterval(showPlayer, 10);
	}
	else {
		cf.style.width = w + 'px';
	}
}

function closeCF() {
	var cf = document.getElementById('cfbox');
	var cfplayer = document.getElementById('NSPlay');
	var w = cf.offsetWidth;
	var x = Math.ceil(w / 2);
	w -= x;
	if(w <= 10) {
		cf.style.width = '1px';
		cf.style.display = 'none';
		cfplayer.pause(); 
		clearInterval(oIntval);
	}
	else {
		cf.style.width = w + 'px';
	}
}

var submenu;

function SubMenu(idx) {
	var arrsm = new Array(2,3);
	var arrx = new Array(261,391);
	var arrl = new Array(4,6);
	for(var i = 0; i < arrsm.length; i++) {
		var mm = document.getElementById('mm_' + arrsm[i]);
		submenu = document.getElementById('submenu_' + arrsm[i]);
		if(idx == arrsm[i]) {
			mm.className = 'mmao';
			submenu.style.left = arrx[i];
			submenu.filters.alpha.opacity = 0;
			submenu.style.height = '0px';
			submenu.style.display = 'block';
			window.setTimeout('BlockShow("submenu_' + arrsm[i] + '",' + arrl[i] * 30 + ')', 2);
		}
		else {
			mm.className = '';
			submenu.style.display = 'none';
			//submenu.filters.alpha.opacity = 100;
			//window.setTimeout('BlockHidden("submenu_' + arrsm[i] + '")', 5);
		}
	}
}

function BlockShow(eid, max) {
	var e = document.getElementById(eid);
	var h = e.offsetHeight;
	h += 10;
	if(h >= max){
		e.style.height = max + 'px';
	    e.filters.alpha.opacity = 100;
	}
	else {
	    e.filters.alpha.opacity += 10;
	    e.style.height = h + 'px';
		window.setTimeout('BlockShow("' + eid + '",' + max + ')', 2)
	}
}


function BlockHidden(eid) {
	var e = document.getElementById(eid);
	var h = e.offsetHeight;
	h -= 10;
	if(h <= 0){
		e.style.height = '0px';
	    e.filters.alpha.opacity = 0;
	}
	else {
	    e.filters.alpha.opacity -= 10;
	    e.style.height = h + 'px';
		window.setTimeout('BlockHidden("' + eid + '")', 5)
	}
}


function BBlock(idx) {
	if(!document.getElementById('bb1')){return;};
	var arrLeft = new Array(0, 12, 262, 512, 762);
	for(var i = 1; i <= 4; i++) {
		var bb = document.getElementById('bb' + i);
		if(idx == i) {
			bb.style.display = 'block';
			bb.style.top = '598px';
			bb.style.height = '0px';
			//var bl = (i - 1) * 253 + 6;
			bb.style.left = arrLeft[i] + 'px';
		    //bb.filters.alpha.opacity = 0;
			showBB(bb.id);
		}
		else {
			bb.style.display = 'none';
		}
	}
}

function showBB(bid) {
	var bb = document.getElementById(bid);
	var h = bb.offsetHeight;
	var t = bb.offsetTop;
	h += 10;
	t -= 10;
	//document.getElementById('txt').innerText = t;
	if(t <= 488){
		bb.style.height = '110px';
		bb.style.top = '488px';
	    //bb.filters.alpha.opacity = 100;
	}
	else {
	    //bb.filters.alpha.opacity += 10;
	    bb.style.height = h + 'px';
		bb.style.top = t + 'px';
		window.setTimeout('showBB("' + bid + '")', 30)
	}
}

var prodintro_pos;
function ProdIntro2() {
	var e = document.getElementById('prod_intro');
	e.style.left = '0px';
}
function ProdIntro() {
	var e = document.getElementById('prod_intro');
	var l = e.offsetLeft;
	var a = e.filters.alpha.opacity;
	a += 4;
	l -= 1;
	//document.getElementById('txt').innerText = l;
	if(l <= 0){
	    e.filters.alpha.opacity = 100;
		e.style.left = '0px';
		prodintro_pos = 0;
		//document.getElementById('txt').innerText = l;
		if(document.getElementById('arrpir')) {document.getElementById('arrpir').style.display = 'block';}
	}
	else {
	    e.filters.alpha.opacity = a;
		e.style.left = l + 'px';
		window.setTimeout(ProdIntro, 30)
	}
}

function moveProdIntro(d) {
	var e = document.getElementById('prod_intro');
	var l = e.offsetLeft;
	//document.getElementById('txt').innerText = e.offsetLeft;
	var stepmove = 30;
	var maxmove;
	if(d == 2) {
		l -= stepmove;
		maxmove = prodintro_pos - 600;
		if(l <= maxmove){
			e.style.left = maxmove + 'px';
			prodintro_pos = maxmove;
			
			//document.getElementById('txt').innerText = 'width:' + e.offsetWidth + ' offsetleft:' + e.offsetLeft + ' prodintro_pos:' + prodintro_pos;

			document.getElementById('arrpi1').style.display = 'block';
			if(Math.abs(maxmove - 600) >= e.offsetWidth) {
				document.getElementById('arrpir').style.display = 'none';
			}
		}
		else {
			e.style.left = l + 'px';
			window.setTimeout('moveProdIntro(' + d + ')', 5)
		}
	}
	else {
		l += stepmove;
		maxmove = prodintro_pos + 600;
		if(l >= maxmove){
			e.style.left = maxmove + 'px';
			prodintro_pos = maxmove;
			document.getElementById('arrpir').style.display = 'block';
			if(l >= 0) {
				document.getElementById('arrpi1').style.display = 'none';
				prodintro_pos = 0;
			}
		}
		else {
			e.style.left = l + 'px';
			window.setTimeout('moveProdIntro(' + d + ')', 5)
		}
	}


	//document.getElementById('txt').innerText = prodintro_pos;

}

function chgAlpha(eid) {
	var e = document.getElementById(eid);
	if(e.filters.alpha.opacity <= 20) {
		e.filters.alpha.opacity = 20;
	}
	else {
		e.filters.alpha.opacity -= 1;
		window.setTimeout('chgAlpha("' + eid + '")', 20);
	}
}

/*
function showSubMenu() {
	var arrsm = new Array(2,3);
	var arrx = new Array(261,391);
	var evt = window.event.srcElement.id;
	var evtp = window.event.srcElement.parentNode.id;
	for(var i = 0; i < arrsm.length; i++) {
		var mm = document.getElementById('mm_' + arrsm[i]);
		var submenu = document.getElementById('submenu_' + arrsm[i]);
		if(mm.id.toString() == evt.toString() || submenu.id.toString() == evt.toString() || submenu.id == evtp.toString()) {
			mm.className = 'mmao';
			submenu.style.left = arrx[i];
			submenu.style.display = 'block';
		}
		else {
			mm.className = '';
			submenu.style.display = 'none';
		}
	}
}
*/

//document.body.onload = function() {
//	document.getElementById('topbar').attachEvent('onmouseover', SubMenu(99));
//}

function setCookies(name,value) {
　　 var Days = 30; //緩 cookie 繍瓜隠贋 30 爺
　　 var exp　　 = new Date();　　　　 //new Date("December 31, 9998");
　　 exp.setTime(exp.getTime() + Days*24*60*60*1000);
　　 document.cookie = name + "="+ escape(value) +";";
　　 //document.cookie = name + "="+ escape(value) +";expire*="+ **p.toGMTString();
}

function getCookies(name) {
　　 var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
　　 if(arr != null) return unescape(arr[2]); return null;
}

function chgLang() {
	var lang = getCookies('wlang');
	var langs = (lang == 1) ? 2 : 1;
	setCookies('wlang', langs);
	window.location.reload();
}