// JavaScript Document

$.fn.center=function(){
	var w=$(window);
	this.css("position","absolute");
	this.css("top",(w.height()-this.height())/2+w.scrollTop() + "px");
	this.css("left",(w.width()-this.width())/2+w.scrollLeft() + "px");
	return this;
}
function create_message1(){
	$('body').each(function(){
		var w=$(window);
		$(this).prepend('<div class="this-mute" style="width: '+w.width()+'px; height: '+w.height()+'px;"></div>');
		$('.this-mute').css({opacity: 0.5});
		$(this).prepend('<div class="this-sup-message1" style="position:absolute;z-index:10000;width:1px;height:1px;border:1px solid #999999;background:#ffffff;text-align:center;"></div>');
		$('.this-sup-message1').each(function(){
			$(this).center();
			var offset = $(this).offset();
			$(this).animate({width: '300px', left: offset.left-150+'px'}, 300,
				function(){$(this).animate({height: '150px', top: offset.top-75+'px'}, 300,
					function(){
						$(this).html('<img src="/UserFiles/Image/_PRODUCTION_/function-not-available.gif" style="display: none; margin: 0px; padding: 0px; border: none;" usemap="#function-not-available"><map name="function-not-available"><area shape="rect" coords="280,0,300,20" href="javascript:close_message1()" title="закрыть"><area shape="rect" coords="90,115,210,135" href="/index.php?categories_id=5" title="телефоны офиса"></map>');
						$(this).find('img').animate({opacity: 'show'}, 'slow');
					}
				);}
			);
		});
	});
}
function close_message1(){
	$('.this-mute').remove();
	$('.this-sup-message1').remove();
}

// ******** ******** ******** ******** ******** ******** ******** ******** //

// ID 2, 128, 43, 44, 21, 32, 23
function this_scroll_description(P){
	//$('.this-description-container').each(function(){
	$('.this-block240long-container').each(function(){
		var N=$(this).css('margin-top'),H=$(this).height(),D=0,I=210,K=150;
		if(P=='up'){
			if((parseFloat(N)-K)<((H-I)*-1))
				D=(H-I)*-1;
			else
				D=parseFloat(N)-K;
		}
		else if(P=='down'){
			if((parseFloat(N)+K)>0)
				D=0;
			else
				D=parseFloat(N)+K;
		}
		$(this).animate({marginTop: D+'px'},'slow');
	});
}

// ******** ******** ******** ******** ******** ******** ******** ******** //

// ID ONLY 2
function this_scroll_oknasystem(P){
	if(P=='auto'){
		autoId = setTimeout(function(){this_scroll_oknasystem('auto')},7000);
		P='up';
	}
	else{
		clearTimeout(autoId);
		autoId = setTimeout(function(){this_scroll_oknasystem('auto')},15000);
	}
	$('.this-block240-oknasystem-container').each(function(){
		var N=$(this).css('margin-top'),H=$(this).height(),D=0,I=250,K=250,L=-25;
		if(P=='up'){
			if((parseFloat(N)-K)<((H-I)*-1))
				D=0;
			else
				D=parseFloat(N)-K;
		}
		else if(P=='down'){
			if((parseFloat(N)+K)>0)
				D=(H-I)*-1;
			else
				D=parseFloat(N)+K;
		}
		$(this).animate({marginTop: D+'px'}, 'slow');
		if(D<0)
			L=(D/K*-1+1)*-25;
		$('.this-oknasystem-switch').css({background: 'url(/UserFiles/Image/_PRODUCTION_/scrollbar_system.gif) '+L+'px 0px'});
	});
}

// ******** ******** ******** ******** ******** ******** ******** ******** //

// ID 128, 44
function this_scroll_okna(P){
	if(P=='auto'){
		autoId=setTimeout(function(){this_scroll_okna('auto')},3000);
		P='up';
	}
	else{
		clearTimeout(autoId);
		autoId=setTimeout(function(){this_scroll_okna('auto')},15000);
	}
	$('.this-block240slide-container').each(function(){
		var N=$(this).css('margin-top'),H=$(this).height(),D=0,I=210,K=210/*,L=-25*/;
		if(P=='up'){
			if((parseFloat(N)-K)<((H-I)*-1))
				D=0;
			else
				D=parseFloat(N)-K;
		}
		else if(P=='down'){
			if((parseFloat(N)+K)>0)
				D=(H-I)*-1;
			else
				D=parseFloat(N)+K;
		}
		if(D==(H-I)*-1)
			$(this).animate({marginTop: D+'px'}, 'slow', function(){$(this).css({marginTop: '0px'})});
		else
			$(this).animate({marginTop: D+'px'}, 'slow');
	});
}

// ******** ******** ******** ******** ******** ******** ******** ******** //

// ID ONLY 32
function switch_btn(A){
	if(A=='btn1'){
		$('#btn1').removeClass('btn1');
		$('#btn1').addClass('btn1-in');
		$('#this-block').animate({marginLeft:'0px'},'slow');
	}
	else{
		$('#btn1').removeClass('btn1-in');
		$('#btn1').addClass('btn1');
	}
	if(A=='btn2'){
		$('#btn2').removeClass('btn2');
		$('#btn2').addClass('btn2-in');
		$('#this-block').animate({marginLeft:'-440px'},'slow');
	}
	else{
		$('#btn2').removeClass('btn2-in');
		$('#btn2').addClass('btn2');
	}
	if(A=='btn3'){
		$('#btn3').removeClass('btn3');
		$('#btn3').addClass('btn3-in');
		$('#this-block').animate({marginLeft:'-880px'},'slow');
	}
	else{
		$('#btn3').removeClass('btn3-in');
		$('#btn3').addClass('btn3');
	}
}
function switch_sert(A){
	$('.this-sert-open').addClass('this-sert');
	$('.this-sert-open').removeClass('this-sert-open');
	$('.sert'+A).removeClass('this-sert');
	$('.sert'+A).addClass('this-sert-open');
}

// ******** ******** ******** ******** ******** ******** ******** ******** //
