function iblockTrigger(iblock, status, animation){
	iblock_id = iblock.id;
	iblock_head = $(".infoblock-head", iblock);
	iblock_body = $(".infoblock-body", iblock);

	if (status){
		$(iblock_head).css({"background-position":"0px -25px", "color":"gray"});
		if (animation) {
			$(iblock_body).slideUp("slow"); 
		} else {
			$(iblock_body).hide();
		}
		
		$.cookie(iblock_id, false, {path:"/", expires: 365});
	} else {
		$(iblock_head).css({"background-position":"0px 0px", "color":"#bc262c"});
		if (animation) {
			$(iblock_body).slideDown("slow"); 
		} else {
			$(iblock_body).show();
		}
		
		$.cookie(iblock_id, null, {path:"/", expires: 365});
	}
};

$(document).ready(function() {
	$("#pageloader").hide();

	$("#text-tab").click(function(e){
		$('#tags-tab').css("marginTop", "-9px");
		$('#text-tab').css("marginTop", "-8px");
		$('#tags-block').slideUp("slow");
		$('#text-block').slideDown("slow");
	});
	$("#tags-tab").click(function(e){
		$('#tags-tab').css("marginTop", "-8px");
		$('#text-tab').css("marginTop", "-9px");
		$('#tags-block').slideDown("slow");
		$('#text-block').slideUp("slow");
	});		
	
	$(".pagetabs").css("background-color", "silver");
	
	$(".pagetabs").mouseover(function(e){
		$(this).css("background-color", "red");
	});
	$(".pagetabs").mouseout(function(e){
		$(this).css("background-color", "silver");
	});
	
	$(".infoblock-head").click(function(e){
		$(".infoblock-body", this.parentNode).css({height: 'auto'});
		iblockTrigger(this.parentNode, ($(".infoblock-body", this.parentNode).is(":hidden")==false), true);
		
	});
	
	$(".infoblock-head").mouseover(function(e){
		$(this).css("text-decoration","underline");
	});	
	
	$(".infoblock-head").mouseout(function(e){
		$(this).css("text-decoration","none");
	});		
	
	$(".infoblock").each(function(e){
		iblockTrigger(this, ($.cookie(this.id)!==null), false);
	});
	
	
	//$("#lc-switcher").css("cursor", "col-resize");
	
	$("#lc-switcher").click(function(e){
		if ($("#leftcolumn-content").is(":hidden")==false){
			$(".infoblock-body").hide();
			if ($.browser.msie)
				if($(".infoblock-head").length>0){
					$(".infoblock-head").fadeOut("slow", function(e){
						$("#leftcolumn-content").hide("slow");
					});
				} else {
					$("#leftcolumn-content").hide("slow");
				}
			else
				$("#leftcolumn-content").hide("slow");
			
			$.cookie("leftcolumn-content", false, {path:"/", expires: 365});
		}else{
			if ($.browser.safari)
			{
				$(".infoblock").hide();
				$("#leftcolumn-content").show();
				$(".infoblock").show("slow");
				$(".infoblock").each(function(e){
					iblockTrigger(this, ($.cookie(this.id)!==null), true);
				});
			} else {
				$("#leftcolumn-content").show("slow", function(e){
					if ($.browser.msie) $(".infoblock-head").fadeIn("slow");
					$(".infoblock").each(function(e){
						iblockTrigger(this, ($.cookie(this.id)!==null), true);
					});
				});
			}
			$.cookie("leftcolumn-content", null, {path:"/", expires: 365});
		};
	});
	
	$.smoothAnchors(1000, "easeOutExpo", false);
});


//формы
$(document).ready(function(e){
	$(".form-box input, .form-box textarea").bind("focus", function(e){
		//изменяем цвет рамки поля для ввода, если в нем находится курсор
		$(this).addClass("infocus");
		
		//открываем связанные с полем элементы
		$(".SHOWBY_"+this.name).slideDown("slow");
	});

	$(".form-box input, .form-box textarea").bind("blur", function(e){$(this).removeClass("infocus");});
	
	$(".form-box input, .form-box textarea").bind("keyup", function(e){
		var thisInputBox = this;
		
		var pwdlength;
		pwdlength = 6;
		if ($(thisInputBox).is('.pwd4')) pwdlength = 4;		
		
		//если поле содержит пароль, проверяем его длину
		if ((thisInputBox.type=='password')&&(thisInputBox.value.length<pwdlength)) 
			$(thisInputBox).addClass("wrongvalue");
		else
			$(thisInputBox).removeClass("wrongvalue");
		
		
		//проверяем, должны ли другие поля соответствовать этому
		$(".EQVAL_TO_"+thisInputBox.name).each(function(){
			var eqvalInputBox = this;
			if (eqvalInputBox.value == thisInputBox.value)
				$(eqvalInputBox).removeClass("wrongvalue");
			else
				$(eqvalInputBox).addClass("wrongvalue");
		});

		//проверяем, должно ли значение этого поля соответствовать значению другого
		//получаем массив, содержащий список классов
		var classArray = thisInputBox.className.split(" ");
		//проходим по списку классов
		$(classArray).each(function(i){
			var classItem = classArray[i];
			var classItemPrefix = classItem.substring(0, 9);
			if (classItemPrefix == "EQVAL_TO_"){
				var eqvalInputBoxName = classItem.substring(9);
				//проходим по всем элементам и сравниваем значения
				var isEqVal = true;
				$(".form-box input[name='"+eqvalInputBoxName+"']").each(function(){
					var eqvalInputBox = this;
					if (eqvalInputBox.value !== thisInputBox.value) isEqVal = false;
				});
				if (!isEqVal)
					$(thisInputBox).addClass("wrongvalue");				
				else
					$(thisInputBox).removeClass("wrongvalue");
			}
		});
		
	});	

	//подсказки
	$(".form-box input, .form-box textarea").bind("focus", function(e){ 
		$(".tooltip", this.parentNode).fadeIn("slow");
	});
	$(".form-box input, .form-box textarea").bind("blur", function(e){ 
		$(".tooltip", this.parentNode).fadeOut("slow");
	});	
	
	var captcha_word_defauld;
	$(".captcha-field").bind("focus", function(e){ 
		if (captcha_word_defauld==undefined) captcha_word_defauld = this.value;
		if ((captcha_word_defauld!==undefined) && (this.value==captcha_word_defauld)) this.value='';
	});
	$(".captcha-field").bind("blur", function(e){ 
		if ((captcha_word_defauld!==undefined)&&(this.value=='')) this.value = captcha_word_defauld;
	});

	//эффект для кнопок ресет
	$(".form-box button[type='reset']").bind("click", function(e){
		$(this).fadeOut("fast");
		$(this).fadeIn("fast");
	});

	//аккордион на случай, если закладок будет несколько
	//считываем значения куки
	$(".form-box").each(function(){
		if (this.id !== undefined){
			activeFormBlockId = $.cookie(this.id);
			if (activeFormBlockId != undefined){
				$(".form-block", this.parentNode.parentNode).each(function(e){
					if (this.id !== activeFormBlockId)
						$(".form-body", this).hide();
				});
				$("#"+activeFormBlockId+" .form-body").slideDown("slow");				
			}
		}
	});
	//добавляем обработчики
	$(".form-block .form-head").bind("mouseover", function(e){
		$(this).addClass("hover");
	});
	$(".form-block .form-head").bind("mouseout", function(e){
		$(this).removeClass("hover");
	});
	$(".form-block .form-head").bind("click", function(e){
		activeFormBlock = this.parentNode;
		jq_activeFormBody = $(".form-body", activeFormBlock);
		
		if(jq_activeFormBody.is(":hidden")){
			$(".form-block", this.parentNode.parentNode).each(function(e){
				$(".form-body", this).slideUp("slow");
			});
			jq_activeFormBody.slideDown("slow");
		} else {
			$(this).fadeOut("fast").fadeIn("slow");
		}
		
		//устанавливаем куки
		$(this).parents(".form-box").each(function(){$.cookie(this.id, activeFormBlock.id, {path:"/", expires: 365});});
	});

	
	//фикс прорисовки чекбоксов, получивших фокус
	if ($.browser.msie){
		$("input:checkbox").bind("click", function(e){this.blur();});
	};
	
});

$(document).ready(function() {
	$(".withborder").each(function(e){
		$(this).addClass('withborder_easy');
		$(this).css({'border':'none'});
		$(this).dropShadow({left: 0, top: 0, opacity: 0.5, blur: 2, swap: false});
	});
});
/*
//сохраняем реферер
$(document).ready(function() {
	if (document.referrer != '') {
		alert('Thanks for visiting from ' + document.referrer); 
	}
});
*/