// animating index images
function animate_i_imgs(photo, num_imgs, period, fade_out)
{
	var i = photo;
	var new_img = $("#images .list dt").eq(i);
	var old_img = $("#images .list .a");
	var title_elm = $("#images .title");
	$("#images .list dt").removeClass("next_a");
	new_img.addClass("next_a");
	old_img.stop();
	old_img.fadeOut(fade_out, function()
		{
			new_img.removeClass("next_a").addClass("a");
			old_img.css({opacity: 1}).show().removeClass("a");
			i = $("#images .list dt").index($("#images .list .a"));
			var title = $("#images .list .a img").attr("alt");
			//title_elm.show();
			title_elm.text(title);
			title_elm.animate({left: 50, opacity: 1}, period, function()
				{
					title_elm.css({left: 20, opacity: 0});
				}
			);
			//title_elm.animate({left: 60}, period);
		}
	);
	++photo;
	if (photo > num_imgs - 1)
	{
		photo = 0;
	}
	return photo;
}
// setting block height equal to given one (ie6< check)
function correct_blck_height(blck, h_model, flg_iechk)
{
	if ((flg_iechk == true && $.browser.msie && $.browser.version <= 6) || flg_iechk == false)
	{
		blck.height(h_model);
	}
	return;
}
// setting elm bottom to bottom - only for ie6
function correct_bottom_pos(elm, parent, bottom)
{
	if ($.browser.msie && $.browser.version <= 6)
	{
		var h = parent.height();
		var bb = (!isNaN(parseInt(parent.css("paddingBottom")))) ? parseInt(parent.css("paddingBottom")) : 0;
		var bt = (!isNaN(parseInt(parent.css("paddingTop")))) ? parseInt(parent.css("paddingTop")) : 0;
		elm.css({top: h + bb + bt + bottom});
	}
	return;
}
// setting footer to bottom - only for ie6
function correct_footer_pos()
{
	if ($.browser.msie && $.browser.version <= 6)
	{
		var doc_h = $(body).height();
		var f_h = $("#footer").height();
		$("#footer").css({top: doc_h - f_h});
	}
	return;
}
// setting block height (ie6< check) and max-height for others
function set_blck_height(blck, h_model)
{
	if ($.browser.msie && $.browser.version <= 6)
	{
		blck.height(h_model);
		correct_footer_pos();
	}
	else
	{
		blck.css({maxHeight: h_model});
	}
	return;
}
$(document).ready(function(){
	$(".iepng").ifixpng();
	$().piroBox({
		my_speed: 300, // animation speed
		bg_alpha: 0.5, // background opacity
		slideShow : 'true', // true == slideshow on, false == slideshow off
		slideSpeed : 3, // slideshow
		close_all : '.piro_close, .piro_overlay' // add class .piro_overlay(with comma)if you want overlay click close piroBox
	});
	// setting params for #images block images change
	var period = 4000;
	var fade_out = 1500;
	var num_imgs = $("#images .list dt").length;
	// animate images in #images block
	$(window).load(function()
		{
			if (num_imgs > 1)
			{
				var i = 1;
				var title = $("#images .list .a img").attr("alt");
				$("#images .title").text(title);
				$(document).everyTime(period+fade_out, "images", function()
					{
						$("#images .title").css({opacity: 0});
						i = animate_i_imgs(i, num_imgs, period, fade_out);
					}
				);
			}
		}
	);
	//left menu hover
	$("#m_left>dd").hover(
		function()
		{
			$(this).addClass("h");
			$("span", $(this)).animate({paddingLeft: 10}, 90, function()
				{
					$(this).animate({paddingLeft: 50}, 90);
				}
			);
		},
		function()
		{
			var parent = $(this);
			parent.removeClass("h");
			$("span", $(this)).animate({paddingLeft: 40}, 90, function()
				{
					$(".arr", parent).animate({width: 42}, 80, function()
						{
							$(this).animate({width: 27}, 70);
						}
					);
				}
			);
		}
	);
	// other stuff init
	// correct .arr height ie6 only
	$("#m_left>dd").each(function()
		{
			correct_blck_height($(".arr", $(this)), $(this).height(), true);
		}
	);
	// correct_bottom_pos($(".today .c_bl"), $(".today"), -10);
	correct_footer_pos();
	$(window).bind("resize", function()
		{
			correct_footer_pos();
		}
	);
});
