$(function(){
	$("a.navi_head").click(function(){
		a_name = this.hash.substr(1,this.hash.length-1);
		$("a[name]")
			.css("text-decoration","")
			.css("color","");
		$("a[name='"+a_name+"']")
			.css("text-decoration","none")
			.css("color","#C12026");
	});
	if (document.location.hash){
		a_name = document.location.hash.substr(1,document.location.hash.length-1);
		$("a[name='"+a_name+"']")
			.css("text-decoration","none")
			.css("color","#C12026");
	}
	$(window).resize(function(){
		//if ($.browser.msie && $.browser.version <= 6){
			if ($(document.body).width() <= 1024){
				$("#container").width("1024");
			}
			else{
				$("#container").width("100%");
			}
		//}
	})
})
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");
	if ($.browser.msie && $.browser.version <=6){
		$("#popupContainer")
			.css("left",getBodyScrollLeft())
			.css("top",getBodyScrollTop())
			.css("width",$(window).width())
			.css("height",$(window).height())
			.fadeIn("slow");
	}else{
		$("#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);
	
	return false;
}
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(1500/*,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);
}
