$(document).ready(function()
{
	$(".block-post-text table tr").hover(
		function(){
			$(this).addClass('ambient');
		},
		function(){
			$(this).removeClass('ambient');
		}
	);


	$(".block-post-text table tr:first").hover(
		function(){
			$(this).addClass('ambient-default');
		},
		function(){
			$(this).removeClass('ambient-default');
		}
	);
	
	$('.firstValueDeleted').one('click',function(){this.def = $(this).val();$(this).val('');});
	$('.firstValueDeleted').blur(function(){if($(this).val() == ''){$(this).val(this.def)}});
	$('.firstValueDeleted').click(function(){if($(this).val() == this.def){$(this).val('');}});

	$('#iFeedback1button').click(function(){
		$('#iFeedback1').parent().find('div.ed').remove();
		$.post($('#iFeedback1').attr('action'), $('#iFeedback1').serializeArray(), function(data){eval(data);});
	});

	$('#iFeedback0button').click(function(){
		$('#iFeedback0').parent().find('div.ed').remove();
		$.post($('#iFeedback0').attr('action'), $('#iFeedback0').serializeArray(), function(data){eval(data);});
	});

	$('#iFeedback2button').click(function(){
		$('#iFeedback2').parent().find('div.ed').remove();
		$.post($('#iFeedback2').attr('action'), $('#iFeedback2').serializeArray(), function(data){eval(data);});
	});

	$('#iCommentButton').click(function(){
		$('#iCommentForm').parent().find('div.ed').remove();
		$.post($('#iCommentForm').attr('action'), $('#iCommentForm').serializeArray(), function(data){eval(data);});
		return false;
	});


	$(".block1").hoverIntent(
		function(){
			$(".center-cell-div2 img:not(.frame1)").fadeOut(150);
			$(".center-cell-div2 .frame1").fadeIn(150);
		},
		function(){
			$(this).find(".annotation").fadeOut(150);
			$(".center-cell-div2 .visible").fadeIn(150);
		}
	);
	
	$(".block2").hoverIntent(
		function(){
			$(".center-cell-div2 img:not(.frame2)").fadeOut(150);
			$(".center-cell-div2 .frame2").fadeIn(150);
		},
		function(){
			$(this).find(".annotation").fadeOut(150);
			$(".center-cell-div2 .visible").fadeIn(150);
		}
	);
	
	$(".block3").hoverIntent(
		function(){
			$(".center-cell-div2 img:not(.frame3)").fadeOut(150);
			$(".center-cell-div2 .frame3").fadeIn(150);
		},
		function(){
			$(this).find(".annotation").fadeOut(150);
			$(".center-cell-div2 .visible").fadeIn(150);
		}
	);

	$(".block4").hoverIntent(
		function(){
			$(".center-cell-div2 img:not(.frame4)").fadeOut(150);
			$(".center-cell-div2 .frame4").fadeIn(150);
		},
		function(){
			$(this).find(".annotation").fadeOut(150);
			$(".center-cell-div2 .visible").fadeIn(150);
		}
	);

	$('#arhivSelect, #eventsSelect, #usersSelect, #onlyPriced').change(doSOBYTIJA);

	$('.image-height').css({height: $(".slider").height()+$(".slider-text").height()+10});
	$(".images a").hover(
	function(){
		$(this).prev('.zoom:first, .zoom-large:first').show(0);
	},
	function(){
		$(this).prev('.zoom:first, .zoom-large:first').hide(0);
	}
	);

	$(".comment-button").hover(
	function(){$(this).css({textDecoration: "underline"});},
	function(){$(this).css({textDecoration: "none"});}
	);

	$(".text").find('span').click(function() {
		if ($(this).hasClass('clicked')) {
			$(this).parent('div').parent('div').find('.first').slideUp(100);
			$(this).removeClass('clicked');
			$(this).addClass('dash');
		} else {
			$(this).parent('div').parent('div').find('.first').slideDown(100);
			$(this).addClass('clicked');
			$(this).removeClass('dash');
		}
	});

	$(".comment-button").click(function(){
		if($(this).find('span').css('display') != 'none')
		{
			$(this).find('span').hide(0);
			$(".feedback-comment").slideDown(300);
			$(".comment-button").addClass('margin-fix');
			setTimeout("$(document).scrollTop(99999)",1000);

		}
		return false;
	});

	$('#iCancel').click(function()
	{
		$(".comment-button").find('span').show(0);
		$(".feedback-comment").slideUp(300);
		$(".comment-button").removeClass('margin-fix');
		return false;
	});

	$('.comment-ans').click(function(){
		$('#ians').val($(this).attr('id').replace('iansid',''));
		$('.comment-button').click();
	});


	$(".submit-button").click(function(){
		$(".feedback-etc").slideDown(400);
		$(".request").addClass('request-fix');
		this.value = 'Send'
	});

	var FEEDBACKOPEN = 0;
	$('p.phone-annotation').find('span').click(function(){
		$(".feedback").fadeIn(200);
		FEEDBACKOPEN = 1;

	});

	$(".cross").click(function(){
		$(".feedback").fadeOut(200);
		FEEDBACKOPEN = 0;
	});

	$(".crossf").click(function(){
		$(".comment-button").find('span').show(0);
		$(".feedback-comment").slideUp(300);
		$(".comment-button").removeClass('margin-fix');
		return false;
	});

	$(".images a").click(function(){
		window.open($(this).attr('href').replace('#',''), 'Увеличить', 'width=600, height=600, resizable=1');
		return false;
	});

	$(".click-area").hoverIntent(
	function(){
		if(FEEDBACKOPEN == 1) return true;
		if ($(this).parent().is('.last'))
		{
			$(this).find('div').css({marginLeft: -$(this).find('img').width()-$(this).width()-20});
			$(this).find('div').fadeIn(200);
		} else {
			$(this).find('div').fadeIn(200);
		}
	},
	function(){
		$(this).find('div').fadeOut(200);
	}
	);

	$(".small-image-container").hoverIntent(
	function(){
		if(FEEDBACKOPEN == 1) return true;
		if ($(this).parent().parent().parent().parent().is('.last')) {
			$(this).find('div').css({marginLeft: -$('.small-images').width()-$(this).width()-30});
			$(this).find('div').fadeIn(200);
		} else {
			$(this).find('div').fadeIn(200);
		}
	},
	function(){
		$(this).find('div').fadeOut(200);
	}
	);

	$('.slider').scroll(function(){$('.slider-text').scrollLeft($(this).scrollLeft());});

	$(".point").hover(
	function(){
		$(this).addClass('marker-selection');
	},
	function(){
		$(this).removeClass('marker-selection');
	}
	);

	$(".text").hover(
	function(){
		$(this).find('span').addClass('marker-selection');
	},
	function(){
		$(this).find('span').removeClass('marker-selection');
	}
	);

	$(".unselect").click(function(){
		$('.selected').find('.fon2').removeClass('fon2');
		$('.selected').find('img').hide();
	});

	$(".push").click(function(){
		if ($(this).hasClass('selected')) { return false; }
		else
		{
			$(".push").removeClass('selected');
			$(".push").prev('td').find('img').hide();
			$(".push").next('td').find('img').hide();
			$(this).prev('td').find('img').show();
			$(this).next('td').find('img').show();
			$(this).addClass('selected');
		}
	});

	$(".hover-color").hover(
	function(){$(this).find('span').addClass('colored');},
	function(){$(this).find('span').removeClass('colored');}
	);

	comment();
	var resizeTimer = null;
	$(window).bind('resize', function()
	{
		if (resizeTimer) clearTimeout(resizeTimer);
		resizeTimer = setTimeout(comment, 100);
	});

});


function comment()
{
	if($('.comments').position() && $('.footer').position().top > ($('.comments').position().top + 460))
	$('.comments').css({'margin-top':($('.footer').position().top - $('.comments').position().top - 60)});
}

function doSOBYTIJA()
{
	var url = $('#sobytijaUrl').val();

	if($('#arhivSelect').find('option:selected').val() != 0)
	{
		url +='arhiv/';
	}

	if($('#eventsSelect').find('option:selected').val() != 0)
	{
		url +='rubrika'+$('#eventsSelect').find('option:selected').val()+'/';
	}

	if($('#usersSelect').find('option:selected').val() != 0)
	{
		url +='vystupajuwij'+$('#usersSelect').find('option:selected').val()+'/';
	}

	if($('#onlyPriced').attr('checked'))
	{
		url +='platnye1/';
	}

	document.location.replace(url);
}