$(function(){
	
	// Оглавление
	(function(){
		
		$("#service-button").hover(function(){
	        $(this).animate({opacity: "0.7"}, 'fast');
	    },function(){
	        $(this).animate({opacity: "1"}, 'fast');
		});
		
	    $("#service-button").click(function(){
	        $(".service-bg").animate({opacity: "show"}, 500);
	        $(".service-window").slideDown('slow');
	    });
		
	    $(".button-chgsort-asc").click(function(){
			var snum = $('#service_num').val();
			snum=parseInt(snum);
			for(i=1; i<=snum; i++){
				var srvtop = (snum - i)*40;
				var sname = 'num'+i;
				$("."+sname).animate({top: srvtop},200);
			}
			$('.button-chgsort-desc-a').removeClass("button-chgsort-desc-a").addClass("button-chgsort-desc");
			$(this).removeClass("button-chgsort-asc").addClass("button-chgsort-asc-a");
	    });
		
	    $(".button-chgsort-desc").click(function(){
			var snum = $('#service_num').val();
			snum=parseInt(snum);
			for(i=snum; i>0; i--){
				var srvtop = (snum - i)*40;
				var j = (snum - i) + 1;
				var sname = 'num'+j;
				$("."+sname).animate({top: srvtop},200);
			}
			$('.button-chgsort-asc-a').removeClass("button-chgsort-asc-a").addClass("button-chgsort-asc");
			$(this).removeClass("button-chgsort-desc").addClass("button-chgsort-desc-a");
	    });
		
	    $(".service-bg").click(function(){
	        $(this).animate({opacity: "hide"}, 500);
	        $(".service-window").slideUp('slow');
	    });
		
	    $("#service-close").click(function(){
	        $(".service-bg").animate({opacity: "hide"}, 500);
	        $(".service-window").slideUp('slow');
	    });
		
	})();
	
	// Вопросы и ответы
	(function(){
		
		$(".faq-title").hover(function(){
	        $(this).find("div").animate({opacity: "show"}, 200);
	    },function(){
	        $(this).find("div").animate({opacity: "hide"}, 200);
		});
		
		$(".faq-title").click(function(){
	        $(this).next("div").slideToggle("fast")/*.siblings(".faq-post:visible").slideToggle("fast")*/;
	        $(this).children('div').toggleClass('faq-title-arrow-a');
		});
		
	})();
	
	// Комментарии
	(function(){
		
		$(".comments-clpall-a").click(function(){
			$(".commentlist:visible").fadeOut('fast');
			$(".commentlist:hidden").fadeIn('fast');
		});
		
		$('.comment-author').hover(function(){
	        $(this).find('.comment-title-arrow').stop(1,1).animate({opacity: 'show'}, 200);
			$(this).find('.comment-title-date').stop(1,1).animate({opacity: 'show'}, 200);
	    },function(){
	        $(this).find('.comment-title-arrow').animate({opacity: 'hide'}, 200);
			$(this).find('.comment-title-date').animate({opacity: 'hide'}, 200);
		});
		
		$(".comment-title-arrow").click(function(){
			if($.browser.msie) return false;
			$(this).parent().next(".coment-content").slideToggle('fast');
			$(this).parent().next(".coment-content").next(".reply").slideToggle('fast');
			$(this).parent().parent().next(".children").slideToggle('fast');
			$(this).toggleClass("comment-title-arrow-a");
		});
		
		$("input").focus(function(){
	  		$(this).next('label').addClass('label-a');
		});
		
		$("input").blur(function(){
	  		$(this).next('label').removeClass('label-a');
		});
		
	})();
	
	// Отправка комментария
	(function(){
		
		var submit = $('.sendCommentBtn'),
			form = submit.parents('form'),
			name = $('input#author'),
			text = $('textarea#comment'),
			nName = $('p#notice-name'),
			nText = $('p#notice-text');
		
		function prepare()
		{
			nName.hide();
			nText.hide();
			
			if (check()) sent();
		}
		
		function check()
		{
			var admin = submit.hasClass('admin'),
				valName = $.trim(name.val()),
				valText = $.trim(text.val());
			
			if (admin) return true;
			
			if (!valName || !valText)
			{
				if (!valName) nName.fadeIn(200);
				if (!valText) nText.fadeIn(200);
				
				return false;
			}
			
			return true;
		}
		
		function sent()
		{
			submit.replaceWith('Подождите, пожалуйста ...');
			
			form.attr('action','http://www.photonoob.ru/wp-comments-post.php');
			form.submit();
		}
		
		submit.click(prepare);
		
		submit.hover(function(){
	        submit.stop(1,1).animate({opacity: "0.7"}, 'fast');
	    },function(){
	        submit.stop(1,1).animate({opacity: "1"}, 'fast');
		});
		
	})();
	
	// Другие элементы: смайлики
	(function(){
		
		var smiles = $('img.wp-smiley'),
			o = 0.65;
		
		smiles.animate({opacity:o}, 0);
		
		smiles.mouseover(function(){
			$(this).stop(1,1).animate({opacity:1}, 100);
		})
		smiles.mouseout(function(){
			$(this).stop(1,1).animate({opacity:o}, 100);
		})
		
	})();
	
});














































