maxWidth = 267;
picCount = 3;

animateDelay = 300;
hoverDelay = 150;

function initPics(resized)
{
	var head = $(".block-new a#link"+1).html();
	$(".head-news h1").text(head);
	
	var blockWidth = $(".img-line").width()-1;
	var spacer =  Math.floor(blockWidth*7/100/picCount);
	var partImgWidth = Math.floor((blockWidth - maxWidth - picCount*spacer)/(picCount-1));
	if (partImgWidth > maxWidth) 
	{
		partImgWidth = maxWidth;
		spacer = Math.floor((blockWidth - picCount*maxWidth)/picCount);
	}	
    
	$(".img-line div").css({width: partImgWidth+"px"});
	$(".img-line p.spacer").css({width: spacer+"px"});
	
	if (resized == 1)  $(lastBlock).css({width: maxWidth+"px"}, { queue:false, duration:animateDelay});
	else $(lastBlock).animate({width: maxWidth+"px"}, { queue:false, duration:animateDelay});
	
	$(lastBlock).find("ins").addClass("block");
}

function animateTo(targetN)
{
			target = $(".img-line div#img"+targetN);
			if($(lastBlock).attr('id') == $(target).attr('id')) return;

			var head = $(".block-new a#link"+targetN).html();
			$(".head-news h1").text(head);

			var blockWidth = $(".img-line").width()-1;
			var spacer =  Math.floor(blockWidth*7/100/picCount);
			var partImgWidth = Math.floor((blockWidth - maxWidth - picCount*spacer)/(picCount-1));
			if (partImgWidth > maxWidth) 
			{
				partImgWidth = maxWidth;
				spacer = Math.floor((blockWidth - picCount*maxWidth)/picCount);
			}	
			
			$(".img-line p.spacer").animate({queue:false, width: spacer+"px", duration:animateDelay/2});

			$(lastBlock).animate({width: partImgWidth+"px"}, { queue:false, duration:animateDelay });			
			$(target).animate({width: maxWidth+"px"}, { queue:false, duration:animateDelay});

			targetLink = $("#link" + targetN);
			targetMark = $("#mark" + targetN);
			$(".block-new a").removeClass("active");
			$(targetLink).addClass("active");
			$(".block-new > ins").removeClass("visible");
			$("#mark" + targetN).addClass("visible");

			
			lastBlock = target;		
}

var timeoutId;
var pannedId;

function plannedAnimate()
{
	timeoutId=0;
	animateTo(plannedId);
}

function planAnimateTo(targetN)
{
	plannedId = targetN;
	if (timeoutId!=0) window.clearTimeout(timeoutId);
	timeoutId = window.setTimeout(plannedAnimate, hoverDelay);
}

function clearPlannedAnimate()
{
	if (timeoutId!=0) window.clearTimeout(timeoutId);
	timeoutId = 0;
}

 $(document).ready(function(){
	$("#close-sub a.root").click(function() { 	 $("#open-sub").slideToggle("slow");  });
	$(".with-sub").click(function() { 	 $("#open-navig").slideToggle("slow");  });

  	lastBlock = $("#img1");
	initPics(0);
	bannerfix();

	$(window).resize(function(){initPics(1);});
	$(window).resize(function(){bannerfix();});

    $(".img-line div").hover(	
		function()
		{
			id = $(this).attr('id');
			var n = id.substr(3,1) * 1;
			planAnimateTo(n);
		}, clearPlannedAnimate
	);
	
	$(".block-new a").hover(	
		function()
		{
			id = $(this).attr('id');
			var n = id.substr(4,1) * 1;
			planAnimateTo(n);			
		}, clearPlannedAnimate
	)
  });
 
function view_sub(vis_layer)
{
   vis_layer_new = document.getElementById(vis_layer);
    vis_layer_new.style.visibility='visible';vis_layer_new.style.display='block';

}

function close_sub(invis_layer)
{
    invis_layer_new = document.getElementById(invis_layer);
   invis_layer_new.style.visibility='hidden';
   invis_layer_new.style.display='none';
}

function bannerfix()
{
	var logo_width = $("#logo").width();

	var new_width = logo_width;
	if (logo_width > 295) new_width = logo_width-(logo_width-295)/2;
	
	$("#bannerleft").width(new_width);
}
function anichange (N) {
name_layer = $('#msg'+N);
if ( $(name_layer).is(':hidden') ) {
$(name_layer).show();
} else {
$(name_layer).hide();
}
}


