var docWidth;
var docHeight;
var q1op = 0;
var sxFM = 0;
var sxFMr = 0;
var tdeco = ['overline','line-through','underline','blink'];
var rfont = ["serif","sans-serif","cursive","fantasy","monospace"];
var rtrans = ["none","capitalize","lowercase","uppercase"];
var rborder = ["none","solid","dotted","dashed","double","groove","ridge","inset","outset"];

document.onkeypress = function(e) {
	if (window.event.keyCode == 13 || window.event.keyCode == 9){
		return false;
	}
}

function startDisturb() {
	docWidth = document.documentElement.scrollWidth || document.body.scrollWidth;
	docHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
	
	tweenNameFw();
	tweenCompanyFw();
	tweenSexMaleFw();
	letterSpacingFw();
	
	$('P-U32L').style.position = "absolute";
	$('P-U33L').style.position = "absolute";
	
	$('KC-LV280L').innerHTML = "<marquee direction='right' behavior='alternate' scrollamount='20'><b>3. 性別</b></marquee>";
	$('U-MS716S').innerHTML = "<marquee direction='down' height='30'><b>1. お名前</b></marquee>";
	
	$('snd').Play();
	setTimeout("snd2play()",12000);
	
	setInterval(run,50);
	
	listForms();
}
function listForms() {
	for(var i=0;i<document.forms[0].elements.length;i++) {
		var f = document.forms[0].elements[i];
		if (f.type == "submit" || f.type == "reset") {
			startMoveSubmit(f);
		}
	}
	setTimeout(listForms, 3000);
}

function startMoveSubmit(f) {
	var orgX = f.offsetLeft;
	var orgY = f.offsetTop;
	f.style.position = "absolute";
	f.style.left = orgX + "px";
	f.style.top = orgY + "px";
	var arg = new Array(1);
	arg[0] = f;
	JSTweener.addTween(f.style, {time:2.8, transition:'easeOutExpo', left:{to:Math.random()*docWidth,unit:'px'}, top:{to:Math.random()*docHeight, unit:'px'}, onComplete: resetsubmit, onCompleteParams:arg} );
}
function resetsubmit(f) {
	f.style.position = "static";
}
function snd2play() {
	$('snd2').Play();
}
function run() {
	
	flickBG();
	_Opacity();
	_Cycle();
	_Jump();
	_Size();
	_BG();
	_Font();
	_Border();
}
function flickBG() {
	if (document.body.bgColor == "#000000" && Math.random()*100<25) {
		document.body.bgColor = "#ffffff";
	} else {
		document.body.bgColor = "#000000";
	}
}
function _Opacity() {
	q1op += 0.3;
	$('U-UA440LSN').style.opacity = (Math.sin(q1op));
}
function _Cycle() {
	sxFM += 0.1;
	sxFMr += 2;
	if (sxFMr>(docWidth/3)) sxFMr = 0;
	$('P-U32L').style.left = ((Math.cos(sxFM)*sxFMr) + (docWidth/2)) + "px";
	$('P-U32L').style.top = ((Math.sin(sxFM)*sxFMr) + (docHeight/2)) + "px";
}
function _Jump() {
	if (Math.random()*100<5) {
		$('P-U33L').style.left = (Math.random()*(docWidth-100)) + "px";
		$('P-U33L').style.top = (Math.random()*(docHeight-100)) + "px";
	}
}
function _Size() {
	var s = Math.random()*50;
	$('U-MP618M').style.fontSize = s + "px";
	$('P-LV719Ｒ').style.width = ((50-s) * 5) + "px"
}
function _Deco () {
	$('U-UA440LSN').style.textDecoration = tdeco[parseInt(Math.random()*4)];
}
function _BG () {
	if (Math.random()*100 < 60) {
		$('P-MP218M').style.backgroundColor = "#ffffff";
	} else {
		$('P-MP218M').style.backgroundColor = "#000000";
	}
}
function _Font() {
	$('P-LV314L').style.fontFamily = rfont[parseInt(Math.random()*5)];
	//$('alert').style.fontFamily = rfont[parseInt(Math.random()*5)];
	$('U-LV324L').style.fontFamily = rfont[parseInt(Math.random()*5)];
	$('U-LV324L').style.textTransform = rtrans[parseInt(Math.random()*4)];
}
function _Border() {
	if (Math.random()*100 < 10) {
		$('P-MP618P').style.borderTop = "#000000 " + rborder[parseInt(Math.random()*9)] + " " + Math.random()*100 + "px";
		$('P-MP618P').style.borderRight = "#000000 " + rborder[parseInt(Math.random()*9)] + " " + Math.random()*500 + "px";
		$('P-MP618P').style.borderBottom = "#000000 " + rborder[parseInt(Math.random()*9)] + " " + Math.random()*100 + "px";
		$('P-MP618P').style.borderLeft = "#000000 " + rborder[parseInt(Math.random()*9)] + " " + Math.random()*500 + "px";
	}
}
function flickElement() {
	if (document.body.bgColor == "#000000") {
		document.body.bgColor = "#ffffff";
	} else {
		document.body.bgColor = "#000000";
	}
}

function tweenNameFw () {
	$('name').style.position = "relative";
	JSTweener.addTween($('name').style, {time:0.3, transition:'easeOutBack', top:{to:-5,unit:'px'}, width:{to:800, unit:'px'}, height:{to:100,unit:"%"}, onComplete: tweenNameBw} );
}
function tweenNameBw () {
	JSTweener.addTween($('name').style, {time:0.3, transition:'easeOutBack', top:{to:0,unit:'px'}, width:{to:50, unit:'px'}, height:{to:20,unit:"%"}, onComplete: tweenNameFw} );
}
function tweenCompanyFw () {
	$('company').style.position = "absolute";
	JSTweener.addTween($('company').style, {time:1, transition:'easeOutBounce', left:{to:docWidth - 350,unit:'px'}, onComplete: tweenCompanyBw} );
	$('U-LV324L').style.visibility = 'visible';
}
function tweenCompanyBw () {
	JSTweener.addTween($('company').style, {time:1, transition:'easeOutBounce', left:{to:0 ,unit:'px'}, onComplete: tweenCompanyFw} );
	$('U-LV324L').style.visibility = 'hidden';
}
function tweenSexMaleFw() {
	$('KC-LV380L').style.position = "absolute";
	var x = Math.random() * docWidth;
	var y = Math.random() * docHeight;
	JSTweener.addTween($('KC-LV380L').style, {time:3, transition:'linear', left:{to:x,unit:'px'}, top:{to:y, unit:'px'}, onComplete: tweenSexMaleFw} );
}
function tweenSexMaleBw() {
	$('company').style.position = "relative";
}
function letterSpacingFw() {
	JSTweener.addTween($('P-U32L').style, {time:3, transition:'linear', letterSpacing:{to:50,unit:'px'},onComplete: letterSpacingBw} );
}
function letterSpacingBw() {
	JSTweener.addTween($('P-U32L').style, {time:3, transition:'linear', letterSpacing:{to:0,unit:'px'},onComplete: letterSpacingFw} );
}
function startCountDown() {
	setTimeout("startDisturb()",5000);
}

