// --------------------------------------------------------------------------------------------------------------> Cufon
Cufon.set("fontFamily", "Trebuchet MS"); 
Cufon.replace(".menu_container a", {hover:true, textShadow:"1px 1px #405001"});
Cufon.replace(".lcont .category .cat", {hover:true});
Cufon.replace("a.butt", {hover:true,"fontSize":"13px"});
//Cufon.replace(".personal_area a", {hover:true,"fontSize":"14px"});
Cufon.replace(".personal_area h4", {hover:true,"fontSize":"16px", textShadow:"1px 1px #a85403"});
Cufon.replace(".add_ads_container a ", {hover:true,"fontSize":"18px"} );


Cufon.set("fontFamily", "Sladkoeshka"); 
Cufon.replace("h1", {"fontSize":"30px"});
Cufon.replace("h2", {"fontSize":"29px"});
Cufon.replace(".h2_basket", {"fontSize":"38px"});
Cufon.replace("h3", {"fontSize":"30px"});
Cufon.replace(".price", {"fontSize":"24px"} );

//Cufon.replace(".crumbs", {hover:true,"fontSize":"24px"});

// --------------------------------------------------------------------------------------------------------------> add2Fav
function add2Fav (x)
{
	if (document.all  && !window.opera) {
		if (typeof window.external == "object") {
			window.external.AddFavorite (document.location, document.title);
			return true;
		}
		else return false;
	}
	else{
		x.href=document.location;
		x.title=document.title;
		x.rel = "sidebar";
		return true;
	}
}

// --------------------------------------------------------------------------------------------------------------> FancyBox
$(document).ready(function() {
	$(".fancybox").fancybox({
		'overlayColor'		:'#000',
		'overlayOpacity'	:0.3,
		'padding'			:"3px",
		'titlePosition'		:"inside",
	});
});

// --------------------------------------------------------------------------------------------------------------> confirm url
$(document).ready(function() 
{
	$(".сonfirm_url").click(function() {
		var agree = confirm($(this).attr("rel"));
		if (agree){}
		else { return false;}
	});
});

// --------------------------------------------------------------------------------------------------------------> Выровнять блоки
$(document).ready(function() 
{
	var left = $(".lcont .inner2").height();
	var middle = $(".mcont .inner2").height();
	var right = $(".rcont .inner2").height();
	var max = 0;
	
	if (left > max) {max = left;}
	if (middle > max) {max = middle;}
	if (right > max) {max = right;}
	
	$(".lcont .inner2").css("min-height",max+"px");
	$(".mcont .inner2").css("min-height",max+"px");
	$(".rcont .inner2").css("min-height",max+"px");
	
	//alert("left = "+left+" | middle = "+middle+" | right = "+right+" => max = "+max);
});

// --------------------------------------------------------------------------------------------------------------> Focus -> Blur
$(document).ready(function() 
{
	$("#name").focus(function() {if ($(this).val() == "Ваше имя") {$(this).val("");}});		$("input[rel=name]").focus(function() {if ($(this).val() == "Ваше имя") {$(this).val("");}});
	$("#name").blur(function() {if ($(this).val() == "") {$(this).val("Ваше имя");}});		$("input[rel=name]").blur(function() {if ($(this).val() == "") {$(this).val("Ваше имя");}});
	
	$("#email").focus(function() {if ($(this).val() == "Ваш e-mail") {$(this).val("");}});	$("input[rel=email]").focus(function() {if ($(this).val() == "Ваш e-mail") {$(this).val("");}});
	$("#email").blur(function() {if ($(this).val() == "") {$(this).val("Ваш e-mail");}});	$("input[rel=email]").blur(function() {if ($(this).val() == "") {$(this).val("Ваш e-mail");}});
	
	$("#response_text").focus(function() {if ($(this).val() == "Текст отзыва") {$(this).val("");}});
	$("#response_text").blur(function() {if ($(this).val() == "") {$(this).val("Текст отзыва");}});
	
	$("#login").focus(function () {if ($(this).val() == "логин (e-mail)"){$(this).val(""); $("#password").val("");}});
	$("#password").focus(function () {if ($(this).val() == "******"){$(this).val(""); $("#login").val("");}});
	
	$("#login").blur(function() {if (($(this).val() == "") && ($("#password").val() == "")){$(this).val("логин (e-mail)"); $("#password").val("******");}});
	$("#password").blur(function() {if (($(this).val() == "") && ($("#login").val() == "")){$(this).val("******"); $("#login").val("логин (e-mail)");}});
	//----------
	$("#order_login").focus(function () {if ($(this).val() == "логин (e-mail)"){$(this).val(""); $("#order_password").val("");}});
	$("#order_password").focus(function () {if ($(this).val() == "******"){$(this).val(""); $("#order_login").val("");}});
	
	$("#order_login").blur(function() {if (($(this).val() == "") && ($("#order_password").val() == "")){$(this).val("логин (e-mail)"); $("#order_password").val("******");}});
	$("#order_password").blur(function() {if (($(this).val() == "") && ($("#order_login").val() == "")){$(this).val("******"); $("#order_login").val("логин (e-mail)");}});
	//----------
	$('#phone').keyup(function() {
		var lastChar = $(this).val().substr(-1);
		var strLength = $(this).val().length;
		
		if ((isNaN(lastChar)) && (lastChar != " ")) {$(this).val($(this).val().substr(0,strLength-1));}
		if (lastChar == " ") {$(this).val($(this).val().replace(/[ \t]{2,}/g, ' '));}
	});
	
	$("#comment").focus(function() {if ($(this).val() == "Текст комментария") {$(this).val("");}});		$("textarea[rel=comment]").focus(function() {if ($(this).val() == "Текст комментария") {$(this).val("");}});
	$("#comment").blur(function() {if ($(this).val() == "") {$(this).val("Текст комментария");}});		$("textarea[rel=comment]").blur(function() {if ($(this).val() == "") {$(this).val("Текст комментария");}});
	
	$("#message_text").focus(function() {if ($(this).val() == "Текст сообщения") {$(this).val("");}});
	$("#message_text").blur(function() {if ($(this).val() == "") {$(this).val("Текст сообщения");}});
	
	$(".phone_callme").focus(function() {if ($(this).val() == "Номер телефона") {$(this).val("");}});
	$(".phone_callme").blur(function() {if ($(this).val() == "") {$(this).val("Номер телефона");}});
});


// --------------------------------------------------------------------------------------------------------------> Send Response
$(document).ready(function() 
{
	$("#send_response").live("click",function(){
		var reg = /[0-9a-z_]+@[0-9a-z_^.]+\.[a-z]{2,3}/i;
		
		if (($("#name").val() == "Ваше имя") || ($("#name").val().length == 0)) {alert("Введите ваше имя"); return false;}
		if (($("#email").val() == "Ваш e-mail") || ($("#email").val().length == 0)) {alert("Введите ваш e-mail"); return false;}
		if (!reg.test($("#email").val())) { alert("Некорректный e-mail адрес"); return false;}
		if (($("#response_text").val() == "Текст отзыва") || ($("#name").val.length == 0)) {alert("Введите текст отзыва"); return false;}
		
		$('#result_container').html("<div class='loading'></div>");
		$.ajax({
			type: "POST",
			url: "/response/send",
			data: "name="+$("#name").val()+"&email="+$("#email").val()+"&text="+$("#response_text").val(),
			success: function(result) {
				$("#result_container").html(result);
				
				$("#name").val("Ваше имя");
				$("#email").val("Ваш e-mail");
				$("#response_text").val("Текст отзыва");
				
				setTimeout(function(){$('#result_container').html('<a href="javascript: void(0)" class="butt" id="send_response">Отправить</a>');}, 5000);
			}
		});
	});
});

// --------------------------------------------------------------------------------------------------------------> Response Item Send
$(document).ready(function() 
{
	$("#send_item_response").live("click",function(){
		var reg = /[0-9a-z_]+@[0-9a-z_^.]+\.[a-z]{2,3}/i;
		var parent_id = $(this).attr("rel");
		
		//alert(parent_id); return false;
		
		if (($("#name").val() == "Ваше имя") || ($("#name").val().length == 0)) {alert("Введите ваше имя"); return false;}
		if (($("#email").val() == "Ваш e-mail") || ($("#email").val().length == 0)) {alert("Введите ваш e-mail"); return false;}
		if (!reg.test($("#email").val())) { alert("Некорректный e-mail адрес"); return false;}
		if (($("#response_text").val() == "Текст отзыва") || ($("#name").val.length == 0)) {alert("Введите текст отзыва"); return false;}
		
		$('#result_container').html("<div class='loading'></div>");
		$.ajax({
			type: "POST",
			url: "/catalog/write-response",
			data: "name="+$("#name").val()+"&email="+$("#email").val()+"&text="+$("#response_text").val()+"&parent_id="+parent_id+"&send_anw="+$("#send_anw").attr("checked")+"&send_new="+$("#send_new").attr("checked"),
			success: function(result) {
				$("#result_container").html(result);
				
				$("#name").val("Ваше имя");
				$("#email").val("Ваш e-mail");
				$("#response_text").val("Текст отзыва");
				$("#send_new").attr("checked","");
				
				setTimeout(function(){$('#result_container').html('<a href="javascript: void(0)" class="butt" id="send_item_response">Отправить</a>');}, 5000);
			}
		});
	});
});

// --------------------------------------------------------------------------------------------------------------> Response Item Vote UP/DOWN
$(document).ready(function() 
{
	$(".item_responses .votes .up a").click(function() {
		var comment_id = $(this).attr("rel");
		var parent = $(this).parent();
		
		$.ajax({
			type: "GET",
			url: "/catalog/votes/?do=up&id="+comment_id,
			success: function(result){
				if (isNaN(result)) {alert(result);}
				else {$(parent).children(".vote_count").html(result);}
			}
		});
	});
	
	$(".item_responses .votes .down a").click(function() {
		var comment_id = $(this).attr("rel");
		var parent = $(this).parent();
		
		$.ajax({
			type: "GET",
			url: "/catalog/votes/?do=down&id="+comment_id,
			success: function(result){
				if (isNaN(result)) {alert(result);}
				else {$(parent).children(".vote_count").html(result);}
			}
		});
	});
});

// --------------------------------------------------------------------------------------------------------------> Response Item Send ANS
$(document).ready(function() 
{
	$(".item_responses .anw a").click(function () {
		$(".item_responses .anw_form").hide();
		$(".anw a").show();
		$(this).hide();
		$(this).parent().parent().children(".anw_form").show();
	});
	
	$(".item_responses .anw_form .cansel").click(function() {
		$(this).parents(".anw_form").hide();
		$(".anw a").show();
		$(this).parents(".anw_form").children("p").children("input[rel=name]").val("Ваше имя");
		$(this).parents(".anw_form").children("p").children("input[rel=email]").val("Ваш e-mail");
		$(this).parents(".anw_form").children("p").children("textarea").val("Текст отзыва");
	});
	
	$(".send_item_response_anw").click(function() {
		var comment_id = $(this).attr("rel");
		var item_id = $(this).parent().attr("rel");
		
		var name = $(this).parents(".anw_form").children("p").children("input[rel=name]");
		var email = $(this).parents(".anw_form").children("p").children("input[rel=email]");
		var text = $(this).parents(".anw_form").children("p").children("textarea");
		var send_anw = $(this).parents(".anw_form").children("p").children("input[name=send_anw]");
		var send_new = $(this).parents(".anw_form").children("p").children("input[name=send_new]");
		
		//alert("send_anw ="+send_anw.attr("checked")+" | send_new= "+send_new.attr("checked"));
		//return false;
		
		var reg = /[0-9a-z_]+@[0-9a-z_^.]+\.[a-z]{2,3}/i;
		
		if ((name.val() == "Ваше имя") || (name.val().length == 0)) {alert("Введите ваше имя"); return false;}
		if ((email.val() == "Ваш e-mail") || (email.val().length == 0)) {alert("Введите ваш e-mail"); return false;}
		if (!reg.test(email.val())) { alert("Некорректный e-mail адрес"); return false;}
		if ((text.val() == "Текст комментария") || (text.val().length == 0)) {alert("Введите текст комментария"); return false;}
		
		$.ajax({
			type: "POST",
			url: "/catalog/write-response",
			data: "name="+name.val()+"&email="+email.val()+"&text="+text.val()+"&parent_id="+item_id+"&parent_comment="+comment_id+"&send_anw="+send_anw.attr("checked")+"&send_new="+send_new.attr("checked"),
			success: function(result) {
				//alert(result);
				$(".anw[rel="+comment_id+"]").append(result);
				$(".comment_container .anw_form").hide();
				name.val("Введите ваше имя");
				email.val("Введите ваш e-mail");
				text.val("Введите текст комментария");
				send_new.attr("checked","");
				
				setTimeout(function() {
					$(".anw[rel="+comment_id+"] p").hide();
					$(".anw[rel="+comment_id+"] a").show();
				}, 5000);
			}
		});
		//$(this).parent().children(".calsel_anw").click();
	});
});

// --------------------------------------------------------------------------------------------------------------> Blog Send Comment
$(document).ready(function() 
{
	$("#send_comment").live("click", function(){
		var reg = /[0-9a-z_]+@[0-9a-z_^.]+\.[a-z]{2,3}/i;
		var parent_id = $(this).attr("rel");
		
		if (($("#name").val() == "Ваше имя") || ($("#name").val().length == 0)) {alert("Введите ваше имя"); return false;}
		if (($("#email").val() == "Ваш e-mail") || ($("#email").val().length == 0)) {alert("Введите ваш e-mail"); return false;}
		if (!reg.test($("#email").val())) { alert("Некорректный e-mail адрес"); return false;}
		if (($("#comment").val() == "Текст комментария") || ($("#name").val.length == 0)) {alert("Введите текст комментария"); return false;}
		
		$('#result_container').html("<div class='loading'></div>");
		$.ajax({
			type: "POST",
			url: "/blog/write-comment",
			data: "name="+$("#name").val()+"&email="+$("#email").val()+"&comment="+$("#comment").val()+"&parent_id="+parent_id+"&send_anw="+$("#send_anw").attr("checked")+"&send_new="+$("#send_new").attr("checked"),
			success: function(result) {
				$("#result_container").html(result);
				
				$("#name").val("Ваше имя");
				$("#email").val("Ваш e-mail");
				$("#comment").val("Текст комментария");
				$("#send_new").attr("checked","");
				
				callback_submit();
				
				function callback_submit(){
					setTimeout(function(){$('#result_container').html('<a href="javascript: void(0)" class="butt" id="send_comment" rel="'+parent_id+'">Отправить</a>');}, 5000);
					}
			}
		});
	});
});

// --------------------------------------------------------------------------------------------------------------> Blog Vote UP/DOWN
$(document).ready(function() 
{
	$(".blog_comments .votes .up a").click(function() {
		var comment_id = $(this).attr("rel");
		var parent = $(this).parent();
		
		$.ajax({
			type: "GET",
			url: "/blog/votes/?do=up&id="+comment_id,
			success: function(result){
				if (isNaN(result)) {alert(result);}
				else {$(parent).children(".vote_count").html(result);}
			}
		});
	});
	
	$(".blog_comments .votes .down a").click(function() {
		var comment_id = $(this).attr("rel");
		var parent = $(this).parent();
		
		$.ajax({
			type: "GET",
			url: "/blog/votes/?do=down&id="+comment_id,
			success: function(result){
				if (isNaN(result)) {alert(result);}
				else {$(parent).children(".vote_count").html(result);}
			}
		});
	});
});

// --------------------------------------------------------------------------------------------------------------> Blog Send ANS
$(document).ready(function() 
{
	$(".comment_container .anw a").click(function () {
		$(".comment_container .anw_form").hide();
		$(".anw a").show();
		$(this).hide();
		$(this).parent().parent().children(".anw_form").show();
	});
	
	$(".anw_form .cansel").click(function() {
		$(this).parents(".anw_form").hide();
		$(".anw a").show();
		$(this).parents(".anw_form").children("p").children("input[rel=name]").val("Ваше имя");
		$(this).parents(".anw_form").children("p").children("input[rel=email]").val("Ваш e-mail");
		$(this).parents(".anw_form").children("p").children("textarea").val("Текст комментария");
	});
	
	$(".send_blog_comment_anw").click(function() {
		var comment_id = $(this).attr("rel");
		var post_id = $(this).parent().attr("rel");
		
		var name = $(this).parents(".anw_form").children("p").children("input[rel=name]");
		var email = $(this).parents(".anw_form").children("p").children("input[rel=email]");
		var text = $(this).parents(".anw_form").children("p").children("textarea");
		var send_anw = $(this).parents(".anw_form").children("p").children("input[name=send_anw]");
		var send_new = $(this).parents(".anw_form").children("p").children("input[name=send_new]");
		
		//alert("send_anw ="+send_anw.attr("checked")+" | send_new= "+send_new.attr("checked"));
		//return false;
		
		var reg = /[0-9a-z_]+@[0-9a-z_^.]+\.[a-z]{2,3}/i;
		
		if ((name.val() == "Ваше имя") || (name.val().length == 0)) {alert("Введите ваше имя"); return false;}
		if ((email.val() == "Ваш e-mail") || (email.val().length == 0)) {alert("Введите ваш e-mail"); return false;}
		if (!reg.test(email.val())) { alert("Некорректный e-mail адрес"); return false;}
		if ((text.val() == "Текст комментария") || (text.val().length == 0)) {alert("Введите текст комментария"); return false;}
		
		$.ajax({
			type: "POST",
			url: "/blog/write-comment",
			data: "name="+name.val()+"&email="+email.val()+"&comment="+text.val()+"&parent_id="+post_id+"&parent_comment="+comment_id+"&send_anw="+send_anw.attr("checked")+"&send_new="+send_new.attr("checked"),
			success: function(result) {
				//alert(result);
				$(".anw[rel="+comment_id+"]").append(result);
				$(".comment_container .anw_form").hide();
				name.val("Введите ваше имя");
				email.val("Введите ваш e-mail");
				text.val("Введите текст комментария");
				send_new.attr("checked","");
				
				setTimeout(function() {
					$(".anw[rel="+comment_id+"] p").hide();
					$(".anw[rel="+comment_id+"] a").show();
				}, 5000);
			}
		});
		//$(this).parent().children(".calsel_anw").click();
	});
});

// --------------------------------------------------------------------------------------------------------------> Send EMail
$(document).ready(function() 
{
	$("#send_message").live("click", function(){
		var reg = /[0-9a-z_]+@[0-9a-z_^.]+\.[a-z]{2,3}/i;
		
		if (($("#name").val() == "Ваше имя") || ($("#name").val().length == 0)) {alert("Введите ваше имя"); return false;}
		if (($("#email").val() == "Ваш e-mail") || ($("#email").val().length == 0)) {alert("Введите ваш e-mail"); return false;}
		if (!reg.test($("#email").val())) { alert("Некорректный e-mail адрес"); return false;}
		if (($("#message_text").val() == "Текст сообщения") || ($("#message_text").val.length == 0)) {alert("Введите текст сообщения"); return false;}
		
		$('#result_container').html("<div class='loading'></div>");
		$.ajax({
			type: "POST",
			url: "/send-email",
			data: "name="+$("#name").val()+"&email="+$("#email").val()+"&text="+$("#message_text").val(),
			success: function(result) {
				$("#result_container").html(result);
				
				$("#name").val("Ваше имя");
				$("#email").val("Ваш e-mail");
				$("#message_text").val("Текст сообщения");
				
				setTimeout(function(){$('#result_container').html('<a href="javascript: void(0)" class="butt" id="send_message">Отправить</a>');}, 5000);
			}
		});
	});
});

// --------------------------------------------------------------------------------------------------------------> Send AD EMail
$(document).ready(function() 
{
	$("#send_ad_message").live("click", function(){
		var reg = /[0-9a-z_]+@[0-9a-z_^.]+\.[a-z]{2,3}/i;
		var ad_id = $(this).attr("rel");
		
		if (($("#name").val() == "Ваше имя") || ($("#name").val().length == 0)) {alert("Введите ваше имя"); return false;}
		if (($("#email").val() == "Ваш e-mail") || ($("#email").val().length == 0)) {alert("Введите ваш e-mail"); return false;}
		if (!reg.test($("#email").val())) { alert("Некорректный e-mail адрес"); return false;}
		if (($("#message_text").val() == "Текст сообщения") || ($("#message_text").val.length == 0)) {alert("Введите текст сообщения"); return false;}
		
		$('#result_container').html("<div class='loading'></div>");
		$.ajax({
			type: "POST",
			url: "/ads/send-email",
			data: "name="+$("#name").val()+"&email="+$("#email").val()+"&text="+$("#message_text").val()+"&ad="+ad_id,
			success: function(result) {
				$("#result_container").html(result);
				
				$("#name").val("Ваше имя");
				$("#email").val("Ваш e-mail");
				$("#message_text").val("Текст сообщения");
				
				setTimeout(function(){$('#result_container').html('<a href="javascript: void(0)" class="butt" id="send_message">Отправить</a>');}, 5000);
			}
		});
	});
});

// --------------------------------------------------------------------------------------------------------------> Send Callme
$(document).ready(function() 
{
	$("#send_callme").live("click", function(){
		if (($("#name").val() == "Ваше имя") || ($("#name").val().length == 0)) {alert("Введите ваше имя"); return false;}
		if (($("#phone").val() == "Номер телефона") || ($("#phone").val().length == 0)) {alert("Введите номер телефона"); return false;}
		if (($("#comment").val() == "Текст комментария") || ($("#comment").val.length == 0)) {alert("Введите текст комментария"); return false;}
		
		$('#result_container').html("<div class='loading'></div>");
		$.ajax({
			type: "POST",
			url: "/send-callme",
			data: "name="+$("#name").val()+"&phone="+$("#phone").val()+"&comment="+$("#comment").val(),
			success: function(result) {
				$("#result_container").html(result);
				
				$("#name").val("Ваше имя");
				$("#phone").val("Номер телефона");
				$("#comment").val("Текст комментария");
				
				setTimeout(function(){$('#result_container').html('<a href="javascript: void(0)" class="butt" id="send_callme">Отправить</a>');}, 5000);
			}
		});
	});
});

// --------------------------------------------------------------------------------------------------------------> MENU BUTTONS
$(document).ready(function() 
{
	
	$(".menu_container a").hover(
		function(){
			var button = $(this);
			$(button).animate({"margin-top":"-8px", "padding-bottom":"8px"},80);
			$(button).css("backgroundImage","url('/images/menu-butt-bg-hover.png')");
		},
		function() {
			var button = $(this);
			$(button).animate({"margin-top":"0px", "padding-bottom":"0px"},80,function(){$(button).css("backgroundImage","url('/images/menu-butt-bg.png')");});
		}
	);
});

// --------------------------------------------------------------------------------------------------------------> LEFT MENU - VIEW SUBMENU
$(document).ready(function() {
	
	$(".open_cat").click(
		function(){
			if ($(this).parent().children(".sub_category").css("display") == "block")
			{
				$(this).parent().children(".sub_category").slideUp(800);
				$(this).removeClass("active");
				$(".category li a.cat").removeClass("active");
				Cufon.refresh();
			}
			else
			{
				$(".category li a.cat").removeClass("active");
				$(this).parents("li").children("a.cat").addClass("active");
				Cufon.refresh();
				$(".sub_category").slideUp(800);
				$(".open_cat").removeClass("active");
				$(this).parent().children(".sub_category").slideDown(800);
				$(this).addClass("active");
			}
		}
	);
});

// --------------------------------------------------------------------------------------------------------------> ADD TO BASKET (ITEM LIST)
$(document).ready(function() {
	$(".item_container .to_basket").click(function(){
		var item_id = $(this).parents(".item_container").attr("rel");
		var color_id = $(this).attr("rel");
		var root = $(this).parent();
		
		$(this).fadeOut();
		$(root).children(".count").fadeOut();
		$(root).children(".loading").fadeIn();
		
		
		$.ajax({
			type: "GET",
			url: "/basket/add/?item_id="+item_id+"&color_id="+color_id,
			success: function(count){
				refresh_basket();
				$(".show_basket").click();
				setTimeout(function(){
					$(root).children(".loading").hide();
					$(root).children(".count").html(count);
					$(root).children(".in_basket").css("display","block");
					$(root).children(".count").css("display","block");
				}, 1000);
			}
		});
		
	});
});

// --------------------------------------------------------------------------------------------------------------> ADD TO BASKET (ITEM PAGE)
$(document).ready(function() {
	$(".item_container_simple .to_basket").click(function(){
		var item_id = $(this).parents(".item_container_simple").attr("rel");
		var color_id = $(this).attr("rel");
		
		//alert(ci);
		
		$(this).fadeOut(800);
		
		$.ajax({
			type: "GET",
			url: "/basket/add/?item_id="+item_id+"&color_id="+color_id,
			success: function(count){
				refresh_basket();
				$(".show_basket").click();
				
				setTimeout(function(){
					$(".in_basket").show();
				}, 2000);
			}
		});
	});
});

// --------------------------------------------------------------------------------------------------------------> REFRESH BASKET
function refresh_basket()
{
	$.ajax({
		type: "GET",
		url: "/basket/get-status",
		success: function(html){
			$(".basket_container").html(html);
		}
	});
}

// --------------------------------------------------------------------------------------------------------------> SHOW BASKET
$(document).ready(function() {
	$(".show_basket").click(function(){
		$.ajax({
			type: "GET",
			url: "/basket/get-html",
			success: function(html){
				$("#basket .html").html(html);
				$(".shadow").fadeIn("fast", function(){$("#basket").fadeIn();});
			}
		});
	});
});


// --------------------------------------------------------------------------------------------------------------> HIDE BASKET
$(document).ready(function() {
	$(".close_basket").click(function(){
		close_basket();
	});
	
	$(".continue").live("click", function(){
		close_basket();
	});
	
	$(document).click(function(e) { 
		if ($(e.target).parents().filter("#basket_body, .basket").length != 1) {
			close_basket();
		}
	});
});

function close_basket()
{
	$("#basket").fadeOut("fast", function(){$(".shadow").fadeOut();});
}

// --------------------------------------------------------------------------------------------------------------> BASKET DELETE ROW
$(document).ready(function() {
	$(".delete_row").live("click", function(){
		var root = $(this).parents("tr");
		var row = $(root).attr("rel");
		var item_id = $(this).attr("rel");
		
		$(root).fadeOut();
		
		$.ajax({
			type: "GET",
			url: "/basket/delete-row/"+row,
			success: function(html){
				refresh_basket();
				refresh_total_count();
				refresh_total_sum();
				
				$(".item_container:[rel="+item_id+"] .basket .count").html("0");
				$(".item_container:[rel="+item_id+"] .basket .count").css("display","none");
				$(".item_container:[rel="+item_id+"] .basket .in_basket").css("display","none");
				$(".item_container:[rel="+item_id+"] .basket .to_basket").css("display","block");
			}
		});
	});
});

// --------------------------------------------------------------------------------------------------------------> BASKET REFRESH TOTAL COUNT
function refresh_total_count()
{
	$.ajax({
			type: "GET",
			url: "/basket/get-total-count",
			success: function(html){
				$('.total_count b').html(html);
			}
		});
}

// --------------------------------------------------------------------------------------------------------------> BASKET REFRESH TOTAL SUM
function refresh_total_sum()
{
	$.ajax({
			type: "GET",
			url: "/basket/get-total-sum",
			success: function(html){
				$('.total_sum b').html(html);
				
				if (html < 250) {$(".order").fadeOut("fast", function(){$(".min_order_sum").fadeIn()});}
				else {$(".min_order_sum").fadeOut("fast",function(){$(".order").fadeIn()});}
			}
		});
}

// --------------------------------------------------------------------------------------------------------------> BASKET UPDATE COUNT
$(document).ready(function() 
{
	$('#basket .count').live("keyup", function(e) {
		if ((isNaN($(this).val())) || ($(this).val() == "")) {$(this).parent().children(".confirm_count").css("display","none");}
		else 
		{
			$(this).parent().children('.confirm_count').click();
			
			var item_id = $(this).attr("rel");
			
			$(".item_container:[rel="+item_id+"] .basket .count").html($(this).val());
		}
	});
});

// --------------------------------------------------------------------------------------------------------------> BASKET CONFIRM COUNT
$(document).ready(function() 
{
	$("#basket .confirm_count").live("click", function() {
		var root = $(this).parents("tr");
		var row = $(root).attr("rel");
		var count = $(this).parent().children(".count").val();
		
		$(this).hide();
		
		$.ajax({
			type: "GET",
			url: "/basket/update-count/?row="+row+"&count="+count,
			success: function(result){
				$(root).children(".sum").children("span").html(result);
				
				refresh_total_count();
				refresh_total_sum();
				refresh_basket();
			}
		});
	});
});


// --------------------------------------------------------------------------------------------------------------> FEFRESH CAPTCHA
$(document).ready(function() 
{
	$("#refresh_captcha").click(function(){
		var d = new Date();
		$("#captcha").attr("src","/tools/kcaptcha/index.php?"+d.getTime());
	});
	$("#captcha").click(function(){$("#refresh_captcha").click();});
});


// --------------------------------------------------------------------------------------------------------------> REGISTRATION
$(document).ready(function() 
{
	$("#reg_form").submit(function(){
		var reg = /[0-9a-z_]+@[0-9a-z_^.]+\.[a-z]{2,3}/i;
		
		if ($("#fname").val() == "") { alert("Введите имя"); return false;}
		if ($("#phone").val().length < 9) { alert("Введите номер телефона"); return false;}
		
		if ($("#reg_email").val() == "") {alert("Введите e-mail"); return false;}
		if (!reg.test($("#reg_email").val())) { alert("Некорректный e-mail адрес"); return false;}
		
		if ($("#reg_pass").val().length < 6) { alert("Введите пароль. Минимум 6 символов"); return false;}
		if ($("#reg_pass").val() != $("#re_reg_pass").val()) { alert("Пароль и подтверждение пароля не совпадают"); return false;}
		
		if ($("#re_captcha").val().length < 5) { alert("Введите текст на картинке"); return false;}
		
	});
	
	$("#reg_email").keyup(function(){
		var reg = /[0-9a-z_]+@[0-9a-z_^.]+\.[a-z]{2,3}/i;
		
		if (reg.test($("#reg_email").val())) 
		{
			//alert($("#reg_email").val());
			
			$.ajax({
				type: "POST",
				url: "/registration/check-email",
				data: "email="+$("#reg_email").val(),
				success: function(result){
					$('.check_email_container').html(result);
				}
			});
			
		} else {$('.check_email_container').html("");}
	});
});



// --------------------------------------------------------------------------------------------------------------> REMEMBER
$(document).ready(function() 
{
	$("#remember_step1").submit(function(){
		var reg = /[0-9a-z_]+@[0-9a-z_^.]+\.[a-z]{2,3}/i;
		
		if ($("#email").val() == "") {alert("Введите e-mail"); return false;}
		if (!reg.test($("#email").val())) { alert("Некорректный e-mail адрес"); return false;}
	});
	
	$("#remember_step3").submit(function(){
		if ($("#rem_pass").val().length < 1) { alert("Введите пароль. Минимум 6 символов"); return false;}
		if ($("#rem_pass").val() != $("#re_rem_pass").val()) { alert("Пароль и подтверждение пароля не совпадают"); return false;}
	});
});

// --------------------------------------------------------------------------------------------------------------> LOGIN

$(document).ready(function() 
{
	$("#login_form").submit(function(){
		var reg = /[0-9a-z_]+@[0-9a-z_^.]+\.[a-z]{2,3}/i;
		
		if (($("#login").val() == "логин (e-mail)") || ($("#login").val() == "")) {alert("Введите логин"); return false;}
		if (!reg.test($("#login").val())) { alert("Некорректный логин"); return false;}
		if (($("#password").val() == "******") || ($("#password").val() == "")) {alert("Введите пароль"); return false;}
	});
});

// --------------------------------------------------------------------------------------------------------------> LOGIN FROM ORDER

$(document).ready(function() 
{
	$("#order_login_form").submit(function(){
		var reg = /[0-9a-z_]+@[0-9a-z_^.]+\.[a-z]{2,3}/i;
		
		if (($("#order_login").val() == "логин (e-mail)") || ($("#order_login").val() == "")) {alert("Введите логин"); return false;}
		if (!reg.test($("#order_login").val())) { alert("Некорректный логин"); return false;}
		if (($("#order_password").val() == "******") || ($("#order_password").val() == "")) {alert("Введите пароль"); return false;}
	});
});

// --------------------------------------------------------------------------------------------------------------> CHANGE PHOTO COLOR
$(document).ready(function() 
{
	$(".item_container_simple .colors_container a").click(function() {
		var new_ci = $(this).attr("rel");
		var old_ci = $(".item_container_simple .colors_container a.curr").attr("rel");
		
		var item_id = $(this).parents(".item_container_simple").attr("rel");
		var color_id = new_ci.substr(3,new_ci.length-1);
		
		/*
		
		
		$(".item_container_simple .photo_container a."+old_ci).hide(0,
		function() {
			$(".item_container_simple .photo_container a."+new_ci).show();
		});
		*/
		
		$(".item_container_simple .colors_container a").removeClass("curr");
		$(this).addClass("curr");
		
		$(".photo_container a").removeClass("view");
		$(".photo_container a[rel="+color_id+"]").addClass("view");
		
		$.ajax({
			type: "GET",
			url: "/catalog/get-price/?id="+item_id+"&color_id="+color_id,
			success: function(result){
				$(".price_container").html(result);
			}
		});
		
		$.ajax({
			type: "GET",
			url: "/catalog/get-discount/?id="+item_id+"&color_id="+color_id,
			success: function(result){
				$(".discount_container").html(result);
			}
		});
		
		$.ajax({
			type: "GET",
			url: "/basket/check-basket-item/?item_id="+item_id+"&color_id="+color_id,
			success: function(result){
				
				if (result != "")
				{
					$(".item_container_simple .butt_container .in_basket").css("display","inline-block");
					$(".item_container_simple .butt_container .to_basket").css("display","none");
				}
				else
				{
					$(".item_container_simple .butt_container .in_basket").css("display","none");
					$(".item_container_simple .butt_container .to_basket").css("display","inline-block");
					$(".item_container_simple .butt_container .to_basket").attr("rel",color_id)
				}
			}
		});
	});
	
	//----------------------------------------------------------------------------------------------------------/ other colors
	
	$(".other_colors_butt").mouseover(function() {
			$(this).addClass("hover");
			$(this).parent().children(".other_colors_container").show();
		});
	
	$(".other_colors").mouseleave(function(e) {
		$(".other_colors_butt").removeClass("hover");
		$(".other_colors_container").parent().children(".other_colors_container").hide();
	});
});

// --------------------------------------------------------------------------------------------------------------> ORDER STEP 1
$(document).ready(function() 
{
	$('#order_step1').submit(function() {
		
		var reg = /[0-9a-z_]+@[0-9a-z_^.]+\.[a-z]{2,3}/i;
		
		if ($("#fname").val() == "") { alert("Введите имя"); return false;}
		if ($("#city").val() == "") { alert("Введите город"); return false;}
		if ($("#adr").val() == "") { alert("Введите адрес"); return false;}
		if ($("#phone").val().length < 10) { alert("Введите номер телефона"); return false;}
		
		if ($("#order_email").val() == "") {alert("Введите e-mail"); return false;}
		if (!reg.test($("#order_email").val())) { alert("Некорректный e-mail адрес"); return false;}
		
		if ($("#re_captcha").val().length < 5) { alert("Введите текст на картинке"); return false;}
		
		if ($('.check_email_container').html().length > 0) { alert("Е-mail зарегестрирован в системе. Пожалуйста выполните вход"); return false;}
		//alert("order_form submit"); return false;
	});
});


// --------------------------------------------------------------------------------------------------------------> ORDER STEP 2
$(document).ready(function() 
{
	$('#order_step2').submit(function() {
		if ($("#date").val() == "") {alert("Введите желаемую дату доставки"); return false;}
		if ($("#time_from").val() == "") { alert("Введите желаемое вермя доставки"); return false;}
		if ($("#time_to").val() == "") { alert("Введите желаемое вермя доставки"); return false;}
		
		if (isNaN($("input:radio[name=delivery_type]").filter(":checked").val())) {alert("Выберите способ доставки"); return false;}
		if (isNaN($("input:radio[name=payment_type]").filter(":checked").val())) {alert("Выберите способ оплаты"); return false;}
	});
});


// --------------------------------------------------------------------------------------------------------------> ADS ADD/EDIT - CHOISE CAT
$(document).ready(function() 
{
	
	$(".category").live("change", function(){
		var id = $(this).attr("id");
		var rel = $(this).attr("rel");
		var value = $("#"+id+" option:selected").val();
		var parent_id = $(this).parents("td").children('.parent_id');
		
		if (value != 0)
		{
			$.ajax({
				type: "GET",
				url: "/ads/get_categories/"+value,
				success: function(result){
					
					if (result == "none")
					{
						$(parent_id).val(value);
						$("#children_"+rel).html("");
						$("#children_"+rel).css("padding-top","0px");
					}
					else
					{
						$("#children_"+rel).css("padding-top","8px");
						$("#children_"+rel).html(result);
						$(parent_id).val("");
					}
					
					$("#search_parent_id").val(value);
				}
			});
		}
		else
		{
			$(parent_id).val("");
		}
	});
});

// --------------------------------------------------------------------------------------------------------------> ADS ADD/EDIT - PHOTO
$(document).ready(function() 
{
	var count_photos = 1;
	var max_photos = 5;
	var max_photo_size = 8;
	var fileSize;
	
	var ie = 0/*@cc_on+@_jscript_version*10@*/;
	
	$("#photos_container input[type='file']").live("change", function(){
		
		if (ie == 0)
		{
			fileSize = (this.files[0].size/1000000).toFixed(2);
			
			fullName = $(this).val();
			shortName = fullName.match(/[^\/\\]+$/);
			splitName = fullName.split(".");
			fileType = splitName[1];
			fileType = fileType.toLowerCase();
			
			if ((fileType != "jpg") && (fileType != "jpeg"))
			{
				alert("Поддерживаемые форматы: jpg, jpeg");
				$(this).val('');
				return false;
			}
		}
		
		if (fileSize > max_photo_size)
		{
			alert("Максимальный размер файла "+max_photo_size+" Мb");
			$(this).val('');
			return false;
		}
		if (count_photos < max_photos)
		{
			$("#photos_container").append("<div><input type='file' name='photos[]' /> &nbsp; <a href='javascript: void(0)' class='clear' style='display:none;'><img src='/images/icons/delete16.png' title='Удалить' /></a></div>");
			
			count_photos++;
		}
		$(this).parent().children("a").css("display","inline-block");
		
	});
	
	$(".clear").live("click", function(){
		$(this).parent().remove();;
		count_photos--;
		if (count_photos == 0)
		{
			$("#photos_container").append("<div><input type='file' name='photos[]' /> &nbsp; <a href='javascript: void(0)' class='clear' style='display:none;'><img src='/images/icons/delete16.png' title='Удалить' /></a></div>");
			count_photos = 1;
		}
	});
	
	$("#type").change(function() {
		if ($("#type option:selected").val() == "offer") {$(".for_type_offer").fadeIn();} else {$(".for_type_offer").fadeOut();}
		if ($("#type option:selected").val() == "search") {$(".condition_req").fadeOut();} else {$(".condition_req").fadeIn();}
		
		$("input[name=price]").click(function() {
			$("#price_value").attr("checked","checked");
		});
	});
	
// --------------------------------------------------------------------------------------------------------------> ADS ADD SUMTIT
	$("#add_ads").submit(function() {
		var reg = /[0-9a-z_]+@[0-9a-z_^.]+\.[a-z]{2,3}/i;
		
		if ($("#parent_id").val().length == 0) {alert("Выберите категорию"); return false;}
		if ($("#type").val().length == 0) {alert("Выберите тип"); return false;}
		if ($("#title").val().length == 0) {alert("Напишите заголовок"); return false;}
		if ($("#title").val().length < 10) {alert("Заголовок слишком короткий"); return false;}
		if ($("#ad_text").val().length == 0) {alert("Напишите текст объявления"); return false;}
		if ($("#ad_text").val().length < 10) {alert("Текст объявления слишком короткий"); return false;}
		
		if (($("#type option:selected").val() == "offer") && ($("input[name=price_type]:radio").filter(":checked").val() == "value"))
		{
			if ($("#price").val().length == 0) {alert("Укажите цену"); return false;}
			if (isNaN($("#price").val())) {alert("Некоррекстная цена"); return false;}
		}
		
		if ($("#type option:selected").val() == "offer")
		{
			if ($("#condition option:selected").val().length == 0) {alert("Укажите состояние"); return false;}
		}
		
		if ($("#region_id").val().length == 0) {alert("Укажите регион"); return false;}
		
		if ($("#user_logined").val() == "false")
		{
			var reg = /[0-9a-z_]+@[0-9a-z_^.]+\.[a-z]{2,3}/i;
			
			if ($("#reg_email").val() == "") {alert("Введите e-mail"); return false;}
			if (!reg.test($("#reg_email").val())) { alert("Некорректный e-mail адрес"); return false;}
			
			if ($(".check_email_container").html().length > 0) { alert("E-mail уже зарегистрирован в системе! Пожалуйста выполните вход."); return false;}
			
			if ($("#fname").val().length == 0) { alert("Введите имя"); return false;}
			if ($("#phone").val().length < 9) { alert("Введите номер телефона"); return false;}
			
			if ($("#reg_pass").val().length < 6) { alert("Введите пароль. Минимум 6 символов"); return false;}
			if ($("#reg_pass").val() != $("#re_reg_pass").val()) { alert("Пароль и подтверждение пароля не совпадают"); return false;}
		}
		
		if ($("#length").val().length == 0) {alert("Укажите срок публикации"); return false;}
		
		if ($("#app_ruler").attr("checked") != true) {alert("Вы должны согласиться с условиями размещения объявлений."); return false;}
		
		$(".submit_container").html("<div class='loading_left'></div>");
	});
	
// --------------------------------------------------------------------------------------------------------------> ADS EDIT choise another cat
	$(".category_container_place a").click(function() {
		$(".category_container_place").hide();
		$(".category_container_select").show();
	});
});


// --------------------------------------------------------------------------------------------------------------> Personal data
$(document).ready(function() 
{
	$("#save_data").submit(function() {
		if ($("#save_data input[name=fname]").val().length < 1) { alert("Введите имя"); return false;}
		if ($("#save_data input[name=phone]").val().length < 9) { alert("Введите номер телефона"); return false;}
	});
	
	$("#save_pass").submit(function() {
		if ($("#save_pass input[name=curr]").val().length < 1) { alert("Введите текущий пароль"); return false;}
		if ($("#save_pass input[name=new]").val().length < 1) { alert("Введите новый пароль"); return false;}
		if ($("#save_pass input[name=new]").val() != $("#save_pass input[name=re_new]").val()) { alert("Пароль и подтверждение пароля не совпадают"); return false;}
	});
});

// --------------------------------------------------------------------------------------------------------------> Filters
$(document).ready(function() 
{
	
	
	
	
	$(".filter_container .price_form").change(function() {
		var price_form_id = $(".filter_container .price_form option:selected").val();
		var parent_id = $("#parent_id").val();
		
		document.location.href = "/catalog/set-filter/price-form/?id="+price_form_id+"&parent_id="+parent_id;
	});
	
	$(".filter_container .price_to").change(function() {
		var price_to_id = $(".filter_container .price_to option:selected").val();
		var parent_id = $("#parent_id").val();
		
		document.location.href = "/catalog/set-filter/price-to/?id="+price_to_id+"&parent_id="+parent_id;
	});
	
	$(".filter_container .brand").change(function() {
		var brand_id = $(".filter_container .brand option:selected").val();
		var parent_id = $("#parent_id").val();
		
		document.location.href = "/catalog/set-filter/brand/?id="+brand_id+"&parent_id="+parent_id;
	});
});






















