jQuery(document).ready(function() {
	jQuery("a[rel=gallery]").fancybox();
	jQuery("a[rel=gallery1]").fancybox();
	$('#detiCh').keydown(function() {
		setTimeout(function(){
		if ($('#detiCh').val()!="" && $('#detiCh').val()!="0" && $('#detiCh').val()!="-" && $('#detiCh').val()!="нет" && $('#detiCh').val()!="нету" && $('#detiCh').val()!="ноль" && $('#detiCh').val()!=" ") {$("#deti_tr").show();$("#deti_tr input").addClass("validEmpty");}
			else {$("#deti_tr").hide();$("#deti_tr input").removeClass("validEmpty");$("#deti_tr input").val("");}
		}, 10);
	});
	
	$(window).resize(function () {
		topImg();
	});
	
	function topImg() {
		i=$("body").css('width');
		if (parseInt(i)<1250) {
			i=(parseInt(i)-990)/2;
			$("#layout1").css('padding-left', i+'px');
			$("#layout2").css('padding-right', i+'px');
		} else {
			$("#layout1").css('padding-left', '130px');
			$("#layout2").css('padding-right', '130px');
		}
	}
	
	topImg();
	
	$('input[name=date1]').change(function() {
		var date1=$(this).val();
		var myDate = new Date();
		myDate.setYear(date1.substr(6,4));
		myDate.setDate(date1.substr(0,2));
		myDate.setMonth(date1.substr(3,2));
		myDate.setTime(myDate.getTime() + 7 * 24 * 60 * 60 * 1000);
		var day = myDate.getDate();
		var month = myDate.getMonth();
		$('input[name=date2]').dpSetSelected(day + '/' + month + '/' + myDate.getFullYear());
	});
	
	$('.go_down').click(function() {
		$('.go_down').parent().find("ul").hide();
		destination = $(this).offset().top;
		$("html").animate({ scrollTop: destination}, 1100 );
		$(this).parent().find("ul").slideToggle();
		
		return false;
	});
	$('.tooltip').click(function() {
		destination_top = $(this).offset().top;
		destination_left = $(this).offset().left;
		$('.b-popup-title').html('');
		$('.b-popup-body-inner').html('');
		tooltip_id = $(this).attr('href');
		$('.b-popup-note').css('top', destination_top);
		$('.b-popup-note').css('left', destination_left);
		$.get("/index.php?menu=ajax&title&tooltip="+tooltip_id, function(data){
			$('.b-popup-title').html(data);
			$.get("/index.php?menu=ajax&text&tooltip="+tooltip_id, function(data){
				$('.b-popup-body-inner').html(data);
				$('.b-popup-note').fadeIn();
			});
		});
		return false;
	});
	$('.b-popup-close, #layout1').click(function() {
		$('.b-popup-note').fadeOut();
	});
});
document.onkeydown = function(e){ 
	if (e == null) {
		keycode = event.keyCode; 
	} else {
		keycode = e.which; 
	} 
	if(keycode == 27) {
		$('.b-popup-note').fadeOut();
	} 
}
