/**
 * @author warmrobot
 */


/**
 * Функция показа и скрытия пояснительного текста для инпутов
 */
function b_input_hint_init() {
	var input = $("input",".b-input-hint");
	var open_form = $("#open_form");
	var initial_btn = $("input.s-initial");
	var form = $("form.b-form");
	var form_in_focus;
	$(input).focus(function(){
		$("label",$(this).closest(".b-input-hint")).hide();
		$(".b-theme-desc-form").show();
		initial_btn.css("visibility","hidden");
	});
	$(input).blur(function(){
		if (($(this).val() == "") && (!form_in_focus)) {
			$("label", $(this).closest(".b-input-hint")).show();
			$(".b-theme-desc-form").hide();
			initial_btn.css("visibility","visible");
		}
	});
	$(input).change(function(){
		if ($(this).val() != "") {
			$("label", $(this).closest(".b-input-hint")).hide();
			$(".b-theme-desc-form").show();
			initial_btn.css("visibility","hidden");
		}
	});
	$(input).mouseover(function(){
		if ($(this).val() != "") {
			$("label", $(this).closest(".b-input-hint")).hide();
			$(".b-theme-desc-form").show();
			initial_btn.css("visibility","hidden");
		}
	});
	$(open_form).click(function(){
		$("label",$(this).closest(".b-input-hint")).hide();
		$(".b-theme-desc-form").show();
		initial_btn.css("visibility","hidden");
	});
	form.mouseover(function(){
		form_in_focus  = true;
	});
	form.mouseout(function(){
		form_in_focus  = false;
	});
	$(input).trigger("change");
}


function comments_init(){
	/*
	 * Answer for the comment
	 */
	$(".s-msg-reply").click(function(){
		var parent = $(this).parents("div.msg").get(0);
		var parent_id = '#' + $(parent).attr("id");
		var action_value = $(this).attr("href");
		$("#form-comment-add").children("form").attr("action", action_value);
		$("#comment_PARENT_ID").attr("value", $("#ID_" + $(parent).attr("id")).attr("value"));
		$("#comment_LEVEL").attr("value", parseInt($("#LEVEL_" + $(parent).attr("id")).attr("value") + 1));
		$("#form-comment-add").insertAfter(parent_id);
		$("#form-comment-add").show();
		/*var textarea_width = $("#form-comment-add").width();
		if ($.browser.msie) {
			textarea_width -= 4
		};
		$("textarea", "#form-comment-add").width(textarea_width);*/
		return false;
	});
	
	
	/*
	 * Hide comment form
	 */
	$(".s-comment-form-hide").click(function(){
		$("#form-comment-add").hide();
		return false;
	});
}
