$(document).ready(function(){
						   
	if (navigator.userAgent.indexOf('MSIE 8')!='-1'){//патч IE8
		$("table.body").css({tableLayout:'auto'});
		
		///////////////// патч для IE8 основного меню (наведение)
		$("div.lmenu div").hover(function () {
			if (!$(this).hasClass("sub"))
				if (!$(this).hasClass("act")) $(this).addClass('hv');
		},function () {
			if (!$(this).hasClass("sub"))
				if (!$(this).hasClass("act")) $(this).removeClass('hv');
		});
		
		$("div.lmenu div.sub p").hover(function () {
			if (!$(this).hasClass("act")) $(this).addClass('hv');
		},function () {
			if (!$(this).hasClass("act")) $(this).removeClass('hv');
		});
	}
	
	///////////////////////// основное меню. накладываем ссылки на div
	$("div.lmenu div p a").each(function(){
		if ($(this).hasClass('toclients')){
			var ID = $(this).attr('id').replace('tc','');
			$(this).parent().click(function() {
				if ($(this).hasClass('act')){
					$(this).removeClass('act');
					$("#toul"+ID).css({'display':'none'});
				}else{
					$(this).addClass('act');
					$("#toul"+ID).css({'display':'block'});
				}
			});
		}else{
			var link = $(this).attr('href');
			if (!$(this).parent().parent().hasClass("sub") && !$(this).parent().parent().parent().hasClass("sub")){
				$(this).parent().parent().click(function(){ location.href = link; });
			} else {
				$(this).parent().click(function(){ location.href = link; });
			}
		}
	});
	
	$("#form2r input.file").css({ 'opacity':'0' });	 
	
	$("#form2r input:file").change(function () {
		$("#form2r input:text").val($(this).val());
		$("#send_form").submit(function() {
  			doLoad(getObj('send_form'),'/ajax/sendform/');
  			return false;
		});
		$("#send_form").submit();
	});
	
	
	if (navigator.userAgent.indexOf('MSIE')!='-1'){//патч IE
		$(".catalog_inn .title div.end.act p").css({ backgroundImage:'url(/DESIGN/SITE/img/cat_title_right_end_act.gif)' });
	}
	$(".catalog_inn .title div").click(function () {
		$(".catalog_inn .title div").removeClass('act').removeClass('sa');
		$(this).removeClass('act').addClass('act');		
		if (navigator.userAgent.indexOf('MSIE')!='-1'){//патч IE
			$(".catalog_inn .title div.end p").css({ backgroundImage:'url(/DESIGN/SITE/img/cat_title_right_end.gif)' });
			if ($(this).hasClass('end')) { $(".catalog_inn .title div.end p").css({ backgroundImage:'url(/DESIGN/SITE/img/cat_title_right_end_act.gif)' }); }
		}
		var ID = $(this).attr('id').replace('mark','');
		if (ID>1) { 
			if ($("#mark"+(ID-1)).attr('id'))
				$("#mark"+(ID-1)).addClass('sa'); 
			else
				$("#mark"+(ID-2)).addClass('sa'); 
		}
		$(".catalog_inn .inner").css({display:'none'});
		$(".catalog_inn .catlist").css({display:'none'});
		$("#pack"+ID).css({display:'block'});
	});
	
	$(".catlist img").click(function () { 
		$("#gallery").css({ /*display: 'block', width: '100%', */height: $(".body").height()+'px' });
//		alert(((document.body.offsetHeight-$("#gallery div").height())/2));
//		$("#gallery div").css({ marginTop: ((document.body.offsetHeight-$("#gallery div").height())/2)+'px', marginLeft: (($(".body").width()-$("#gallery div").width())/2)+'px' });
		if (navigator.userAgent.indexOf('MSIE')=='-1') DD_roundies.addRule('#gallery div', '5px 5px 5px 5px', true);
	});
	
	$("#auth2r form u").click(function() {
				$.ajax({
				    url: '/ajax/fforget/',
					success: function(data) { $("#link2r").replaceWith(data); $("#forget").replaceWith(data); }
				});
	});
	
	$(".vacans li u").click(function() {
		$(".vacans li").removeClass('act');
		$(this).parent().addClass('act');
		$('body').scrollTop($(this).parent().offset().top);
	});
	
	$(".vacans li strong.title").click(function() {
		$(this).parent().removeClass('act');
	});
	
});


function closeWindow(block){
	var oursblock = document.getElementById(block);
	if (oursblock){
		oursblock.style.display = 'none';
	}
}


function loadImage(zone,img,imgWidth,imgHeight) {
	
	var cwidth = ClientWidth();
	var cheight = ClientHeight();

	var widthPrecent = 0;
	if (imgWidth>cwidth) {
		var rzc=(imgWidth-cwidth)+50;
		var prc=imgWidth/100;
		widthPrecent=Math.ceil(rzc/prc);
	}

	var heightPrecent = 0;
	if (imgHeight>cheight) {
		var rzc=(imgHeight-cheight)+50;
		var prc=imgHeight/100;
		heightPrecent=Math.ceil(rzc/prc);
	}

	if (widthPrecent>0 || heightPrecent>0) {
		var prec = 0;
		if (widthPrecent>heightPrecent) {
			var prec = widthPrecent;
		} else {
			var prec = heightPrecent;
		}
		
		var imgWidth = Math.ceil(imgWidth-((imgWidth/100)*prec));
		var imgHeight = Math.ceil(imgHeight-((imgHeight/100)*prec));
	}	

	var resLeft = Math.ceil(((cwidth-imgWidth)/2)+ScrollLeft());
	var resTop = Math.ceil(((cheight-imgHeight)/2)+ScrollTop());

	var box = document.getElementById(zone);
	box.style.display='block';
	box.innerHTML='';
	
	box.onclick = function() { 
	}

	var div = document.createElement("div");
	div.style.marginTop=resTop+'px';
	div.style.marginLeft=resLeft+'px';	
	
	var a = document.createElement("a");
	a.href = '#';
	a.title = 'CLOSE';
	a.style.marginLeft = (imgWidth-30)+'px';
	a.onclick = function() { 
		box.style.display='none';
		box.innerHTML='';
	}
	
	var image=document.createElement("img");	
	image.src=img;
	image.width=imgWidth;
	image.height=imgHeight;
	image.style.display='none';

	checkimage(image);
	
	div.appendChild(a);
	div.appendChild(image);
	
	box.appendChild(div);
}

function checkimage(image) 
{
	if(image.complete)
		image.style.display = 'block';
	else 
		setTimeout(function(){checkimage(image)},100);
}

function ClientWidth() {
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function ClientHeight() {
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}	

function ScrollLeft() {
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.scrollLeft:document.body.scrollLeft;
}

function ScrollTop() {
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.scrollTop:document.body.scrollTop;
}	


