if ("Microsoft Internet Explorer" == navigator.appName) {location.href="index.html";}
var R = Math.floor(Math.random()*55)+200;
var R_new = Math.floor(Math.random()*255);
var G = Math.floor(Math.random()*55)+200;
var G_new = Math.floor(Math.random()*255);
var B = Math.floor(Math.random()*55)+200;
var B_new = Math.floor(Math.random()*255);
var h = hx = L = lx = ly = xmax = ymax = napr = predA = predB = xC = yC = 0;
window.onload = function(e) {
	document.body.style.background="RGB("+R+","+G+","+B+")";
	setInterval( ColorStep ,333);
	FWResize();
	PenduluMuve();
	window.onresize = FWResize;
}
// color
 function ColorStep() {
	R=ColorShft(R, R_new);
	G=ColorShft(G, G_new);
	B=ColorShft(B, B_new);
	document.body.style.background="RGB("+R+","+G+","+B+")";
}
 function ColorShft (Col, Col_new) {
	if (Col == Col_new) ColorNew(Col);
	else if	(Col > Col_new) Col--;
	else Col++;
	return Col
}
 function ColorNew (C) {
	switch (C) {
		case R: R_new = Math.floor(Math.random()*255); break;
		case G: G_new = Math.floor(Math.random()*255); break;
		case B: B_new = Math.floor(Math.random()*255); break;
	}
}
// pendulum
 function PendulumScroll() {
		h = ymax*2;
		lx = ly= 0;
		if ( xmax != h ) {
			if ( xmax > h ) { 
				lx = Math.floor((xmax-h)/2);
				if ( document.getElementById('pendulum').scrollLeft < lx ) { document.getElementById('pendulum').scrollLeft = lx; }
				else if ( document.getElementById('pendulum').scrollLeft > h+lx) { document.getElementById('pendulum').scrollLeft = xmax-lx-1; }
			}
			else {
				h = Math.floor(xmax/2);
				ly = Math.floor((ymax-h)/2);
				if ( document.getElementById('pendulum').scrollTop < ly ) { document.getElementById('pendulum').scrollTop = ly; }
				else if ( document.getElementById('pendulum').scrollTop > h+ly) { document.getElementById('pendulum').scrollTop = h+ly-1; }
			}
		}
	}
 function FWResize() {
		xmax = Math.floor(document.getElementById('pendulum').scrollWidth*3/7);
		ymax = Math.floor(document.getElementById('pendulum').scrollHeight*3/7);
		PendulumScroll();
		predA = xmax-(lx*3/2)-20;
		predB = (lx*3/2)+20;
		L=ymax-ly;
		var cen = Math.floor(document.getElementById('pendulum').offsetWidth/2);
		document.getElementById('line').setAttribute("x1", cen );
		document.getElementById('line').setAttribute("y1", ly );
		xC = Math.floor(document.getElementById('pendulum').scrollWidth/2);
		yC = Math.floor(document.getElementById('pendulum').scrollHeight/2);
	}
 function PenduluMuve() {
		PendulumScroll();
		var x = document.getElementById('pendulum').scrollLeft;
		var y = document.getElementById('pendulum').scrollTop;
		if ( x <= predB  ) { napr = 1; }
		else if ( x>=predA ) { napr = 0; }
		if (napr == 0) {
			if ( x <= ( predB + 10 ) ) {document.getElementById('pendulum').scrollLeft--;}
				else { document.getElementById('pendulum').scrollLeft -=3; }
			}
		else {
			if ( x>=(predA - 10)  ) {document.getElementById('pendulum').scrollLeft++;}
			else { document.getElementById('pendulum').scrollLeft +=3; }
		}
		var post_X2 = x - (xmax/2);
		var p_xx=(L*L)-(post_X2*post_X2);
		if ( p_xx >= 0 ) { 
			var sum = ymax -Math.floor(Math.sqrt(p_xx));
			document.getElementById('pendulum').scrollTop = sum;
		}
		else { document.getElementById('pendulum').scrollTop = ymax; }	
		document.getElementById('line').setAttribute("x2", (xC - x + 25) );
		document.getElementById('line').setAttribute("y2", (yC - y - 5) );
		setTimeout(PenduluMuve,20);
	}
