$(function (){
	if ($(document).height() > $("#shade_l").height()){
		var wHeight = $(document).height();
		$("#shade_l").css("min-height",wHeight);
		$("#shade_r").css("min-height",wHeight);
		$("#body").css("min-height",wHeight);
		$(window).bind("resize",function (){
			var wHeight = $(document).height();
			$("#shade_l").css("min-height",wHeight);
			$("#shade_r").css("min-height",wHeight);
			$("#body").css("min-height",wHeight);
		})
	}
	$("#left>ul>li>a").hover(
		function(){
			$(this).parent().addClass("hover");
		},
		function (){
			$(this).parent().removeClass("hover");
		}
	);
	$.sifr({
		path: host+'/js/fonts/',
		save: true
	});
	$(".print").click(function(){window.print();return false;});
	$('h1:not(.red)').sifr({ font: 'geinspira',color:"#FAFAFA" })
	$("h1.red").sifr({ font: 'geinspira' ,color:"#E5242A"});
	$("h1.gray").sifr({ font: 'geinspira' ,color:"#7F7F7F"});
	$("h1.black").sifr({ font: 'geinspira' ,color:"#272727"});
	
	$(".slide_container .title a").click(function (){
		if (this.className == 'plus') this.className = 'minus';
		else this.className = 'plus';
		$(this).parent().parent().find(".slide_content:first").slideToggle("slow");
	});
	$(".technick_data table")
		.css("border","0")
		.css("border-collapse","collapse")
		.css("border","1px solid #797979")
		.attr("border","0")
		
	$(".technick_data table")
		.find("tr:even td")
			.css("background","#C1C0C0")
			.css("border-top","1px solid #aaaaaa")
			.css("border-bottom","1px solid #aaaaaa")
			.css("border-left","1px solid #797979")
			.css("border-right","1px solid #797979");
	$(".technick_data table")
		.find("tr:odd td")
			.css("background","#B1B1B1")
			.css("border-top","1px solid #aaaaaa")
			.css("border-bottom","1px solid #aaaaaa")
			.css("border-left","1px solid #797979")
			.css("border-right","1px solid #797979")
	
	$(".technick_data table")
		.find("tr td:first")
			.css("background","#A5A5A5")
			.css("border-bottom","1px solid #797979");
	
	$(".technick_data table")
		.find("tr:first td")
				.css("background","#D9D8D8")
				.css("border","1px solid #797979");
	$(".technick_data table tr td[rowspan]").css("background","#A5A5A5").css("border","1px solid #797979");
	$(".technick_data table").find("tr:last td").css("border","1px solid #797979");
	
});
function preview(src,text){
	if (!src) return;
	$(document.body).append('<div id="popupMask"></div><div id="popupContainer"><table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%"><tr><td align="center"><div id="popupContent"><div id="popupHeader"><a href="" id="popupClose">Закрыть</a></div><div id="popupImgCont"><img src="'+host+'/images/ajax-loader.gif" width="32px" height="32px" id="popupImg"></div></div></td></tr></table></div>');
	
	$("#popupMask")
		.css("width",$(document).width())
		.css("height",$(document).height())
		.css("opacity",0.4)
		.fadeIn("slow");
	$("#popupContainer")
		.css("left",getBodyScrollLeft())
		.css("top",getBodyScrollTop())
		.fadeIn("slow");
	$("#popupClose").click(hidePreview);
	
	img = new Image();
	img.alt = text
	img.onload = imgPreviewOnLoad;
	img.src = src;
	
	$(window).bind("resize",resizeWnd)
}
function resizeWnd(){
	$("#popupMask")
		.css("width",$(document).width())
		.css("height",$(document).height())
}
function imgPreviewOnLoad(){
	imgWidth  = this.width;
	imgHeight = this.height;
	src		  = this.src;
	alt 	  = this.alt;
	wndWidth   = document.body.clientWidth;
	wndHeight  = document.body.clientHeight;
	if (imgWidth > wndWidth){
		imgHeight = parseInt(imgWidth * (wndWidth / imgWidth));
		imgWidth  = parseInt(wndWidth);
	}
	
	if (imgHeight > wndHeight){
		
		imgWidth  = parseInt(imgWidth * (wndHeight / imgHeight));
		imgHeight = wndHeight;
	}
	$("#popupFooter").html(alt)
	
	
	contWidth   = $("#popupContent").width() - 32 + imgWidth;
	contHeight  = $("#popupContent").height() - 32 + imgHeight;
	$("#popupContent")
		.animate({"width":contWidth},1500,function (){
			$(this).animate({"height":contHeight},1500,function(){
				$("#popupImg")
					.hide()
					.attr("src",src)
					.attr("alt",alt)
					.attr("title",alt)
					.width(imgWidth)
					.height(imgHeight)
					.fadeIn(1000/*,function(){
						$("#popupFooter")
							.slideDown("slow");
					}*/);
				
				$("#popupMask")
					.css("width",$(document).width())
					.css("height",$(document).height())
			});
		});
}
function hidePreview(){
	$("#popupContainer").fadeOut("slow",function(){
		$(this).remove();
		$("#popupMask").fadeOut("slow",function(){$(this).remove()});
	})
	return false;
}
function getBodyScrollTop()
{
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function getBodyScrollLeft()
{
  return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}