step = 0.0015;
delay = 20;
koef = 40;

current_param = 'left';
current_limit = '100';
current_unit = '%';

is_block_movie = false;
current = 1;

function fn(x){
	if( x < 0.75 ){
		y = koef*Math.sqrt( ( 1-Math.pow( (x*2-1), 2 ) ) ) + 1;
	} else {
		y = koef*( Math.cos( Math.PI*0.84*( x*2 - 1 ) )/2 + 0.5-Math.pow(x,6)*0.03 );		
	}
	return y;
}

function startMovie( obj, direction, param, limit, unit ){
	current_param = param == null ? 'left' : param;
	current_limit = limit == null ? '100' : limit;
	current_unit = unit == null ? '%' : unit;
	if( !is_block_movie ){
		if( direction == 'next' && current < 4 ){
			is_block_movie = true;
			moveObj( obj, current, current+1 );
		} else if( direction == 'prev' && current > 1 ){
			is_block_movie = true;
			moveObj( obj, current, current-1 );
		}
	}
}

function moveObj( obj, from, to, now ){

	if( now == null ){
		now = 0;
	}
	if( now < 1 ){
		now += Math.min( fn(now)*step, 1 - now );
		document.all[obj].style.left = Math.round( -(from-1+(to-from)*now)*1000 )/10+'%';
		moveTimeout = setTimeout( 'moveObj( \''+obj+'\', '+from+', '+to+', '+now+' );', delay );
	} else {
		current += (to-from)*1;
		is_block_movie = false;
		clearTimeout( moveTimeout );
	}
}

moveTimeout = false;
linkTimeout = false;

function startLinks( direction ){
	direction == 1 ? moveLinks( 0 ) : moveLinksBack( 0 );
}
function moveLinks( from, now ){
	if( now == null ){
		now = 0;
	}
	if( now < 1 ){
		now += Math.min( fn(now)*0.008, 1 - now );
		document.all.scroll_links.style.top = '-' + Math.round( now*306 )+'px';
		document.all.top_links.style.height = 306 - Math.round( now*146 )+'px';
		linkTimeout = setTimeout( 'moveLinks( '+from+', '+now+' );', 65 );
	}else{
		clearTimeout( linkTimeout );
	}
}
function moveLinksBack( from, now ){
	if( now == null ){
		now = 0;
	}
	if( now < 1 ){
		now += Math.min( fn(now)*0.008, 1 - now );
		document.all.scroll_links.style.top = '-' + Math.round( (1-now)*306 )+'px';
		document.all.top_links.style.height = 306 - Math.round( (1-now)*146 )+'px';
		linkTimeout = setTimeout( 'moveLinksBack( '+from+', '+now+' );', 65 );
	}else{
		clearTimeout( linkTimeout );
	}
}


function msg_scroll(){
/*
	if( !scroll_down && !is_msg_show ){
		document.all.msg_down.style.display = 'block';
		is_msg_show = true;
		msg_scroll_start(0,0);
	}
*/	
}

msg_timeout = null;
function msg_scroll_start(f,t){
	// Зажигание
	if( f == 0 ){
		if( t<1 ){
			document.all.msg_down.style.filter = 'Alpha(Opacity=' + Math.round( t*100 ) + ')';
			msg_timeout = setTimeout( 'msg_scroll_start(0,' + (t+0.05) + ');', 10 );
		}else{
			msg_timeout = setTimeout( 'msg_scroll_start(1,0);', 750 );
		}
	// Пауза
	} else if( f == 1 ){
		if( t<2 ){
			y = (Math.cos(2*Math.PI*t)+1)/2;
			document.all.msg_down.style.filter = 'Alpha(Opacity=' + Math.round( y*100 ) + ')';
			msg_timeout = setTimeout( 'msg_scroll_start(1,' + (t+0.05) + ');', 8 );
		}else{
			msg_timeout = setTimeout( 'msg_scroll_start(2,1);', 2500 );
		}
	// Угасание
	} else if( f == 2 ){
		if( t>0 ){
			document.all.msg_down.style.filter = 'Alpha(Opacity=' + Math.round( t*100 ) + ')';
			msg_timeout = setTimeout( 'msg_scroll_start(2,' + (t-0.02) + ');', 8 );
		}else{
			document.all.msg_down.style.display = 'none';	
		}
	}
}



is_msg_show = false;
scroll_down = false;
scroll_timeout = false;

// Просмотр сайта начат
function start(){

	window.onresize = window.onscroll = function check_marker_pos(){
		// Максимально низкая видимая точка
		if( document.body.clientHeight + document.body.scrollTop > 800 ){
			scroll_down = true;
		}
	};	
	check_marker_pos();
	
	scroll_timeout = setTimeout( 'msg_scroll();', 7500 );	
	
}



function scripted( obj ){
	obj.scripted = 'scripted';
	obj.style.margin = '16px 0';
	obj.parentElement.insertAdjacentHTML('BeforeBegin', 
		'<div style="position:absolute; width:'+obj.clientWidth+'; height:'+obj.clientHeight+'; ">\
			<img src="/img/win_lt.gif" style="position:absolute; top:0px; left:-16px;">\
			<img src="/img/win_rt.gif" style="position:absolute; top:0px; left:'+obj.clientWidth+'px;">\
			<img src="/img/win_lb.gif" style="position:absolute; top:'+(obj.clientHeight+16)+'px; left:-16px;">\
			<img src="/img/win_rb.gif" style="position:absolute; top:'+(obj.clientHeight+16)+'px; left:'+obj.clientWidth+'px;">\
			<div style="position:absolute; width:16px; height:'+obj.clientHeight+'px; top:16px; left:-16px; background:url(/img/win_l.gif);">\
				<img src="/img/win_8.gif" class="top">\
				<img src="/img/win_7.gif" class="bottom">\
			</div>\
			<div style="position:absolute; width:20px; height:'+obj.clientHeight+'px; top:16px; left:'+obj.clientWidth+'px; background:url(/img/win_r.gif);">\
				<img src="/img/win_3.gif" class="top">\
				<img src="/img/win_4.gif" class="bottom">\
			</div>\
			<div style="position:absolute; width:'+obj.clientWidth+'px; height:16px; top:0; left:0; background:url(/img/win_t.gif);">\
				<img src="/img/win_1.gif" class="left">\
				<img src="/img/win_2.gif" class="right">\
			</div>\
			<div style="position:absolute; width:'+obj.clientWidth+'px; height:20px; top:'+(obj.clientHeight+16)+'px; left:0; background:url(/img/win_b.gif);">\
				<img src="/img/win_5.gif" class="right">\
				<img src="/img/win_6.gif" class="left">\
			</div>\
		</div>' 
	
	); 

	obj.scripted = 'scripted';
	
}