window.onload = function() {
	var x = 0, y = 27, nahStepTimeOut, forest = document.getElementById('forest'); _ufo = document.getElementById('ufo'), z=1; 
	
	_ufo.scrollTop = Math.random()*60;
	
	var _ufoScroll = function () { 
		if (kor > 0.5) {   
			_ufo.scrollTop++;
			if ( _ufo.scrollTop >= 59 ) kor = 0;
		}
		else {	
			_ufo.scrollTop--;
			if ( _ufo.scrollTop <= 1 ) kor =1; 
		}
	}
	
	var forestStep = function () { forest.style.width = parseInt(forest.style.width)+1.5+'px';  }
	
	var active = function () {
			document.getElementById('stop').className = '';
			document.getElementById('ufo_body').style.backgroundPosition='-214px 160px';
			kor = Math.random();
			forestInterval=setInterval( forestStep ,30);
			_ufoInterval=setInterval( _ufoScroll ,50);
			return false
	}
	
	if (z==1) { z=0; active(); } 
	
	document.getElementById('start').onclick = function() {
		el = document.getElementById('start'); 
		if (el.className != 'active')
			{	m = parseInt (el.style.marginLeft); 
				el.className = 'active';
				active();
				if (nahStep) { x = 0; nahStep () };
				return false
			}
		else { return false }	
	}
	
	document.getElementById('stop').onclick = function() {
		el = document.getElementById('stop'); 
		if (el.className != 'active')
		{
			m = parseInt (el.style.marginLeft); 
			document.getElementById('start').className = '';
			document.getElementById('ufo_body').style.backgroundPosition='0px 160px';
			el.className = 'active';
			clearInterval(forestInterval);
			clearInterval(_ufoInterval);
			if (nahStep) { x = 0; nahStep () };
			return false
		}
	}
	
	var nahStep = function () { 
		if (nahStepTimeOut) clearTimeout (nahStepTimeOut); 
		l = (1 / (Math.pow (x, 1.25) / 20 + 0.5) - 0.05) * Math.sin (x/2); 
		el.style.marginLeft = (m + l * 25) + 'px'; x ++; 
		if (x < 82) { nahStepTimeOut = setTimeout (nahStep, 10) } 
		else { el.style.marginLeft = '0'; }
	}
}
