// add wrapping iframe - ie only
function add_iframe(elm)
{
	if ($.browser.msie && $.browser.version <= 6 && $(".pre_ie_iframe", elm).length == 0)
	{
		var elm_w = elm.width();
		var elm_h = elm.height();
		var elm_z = (elm.css("z-index") != 0)? elm.css("z-index") - 1: 0;
		elm.wrapInner('<div class="pre_ie_iframe"></div>');
		$(".pre_ie_iframe", elm).css({height: elm_h, left: 0, position: "absolute", top: 0, width: elm_w, zIndex: elm_z + 1});
		$("<iframe></iframe>").attr({className: "ie_iframe"}).css({border: 0, height: elm_h, left: 0, opacity: 0, position: "absolute", top: 0, width: elm_w, zIndex: elm_z}).appendTo(elm);
		$(elm).on("resize", function()
			{
				var elm_w = elm.width();
				var elm_h = elm.height();
				$(".pre_ie_iframe", elm).css({height: elm_h, width: elm_w});
				$(".ie_iframe", elm).css({height: elm_h, width: elm_w});
			}
		);
	}
	return;
}
// animating index images
function animate_i_imgs(num_imgs, period, fade_out)
{
	var blck = $("#index .promo");
	var i = $(".m_tabs li", blck).index($(".m_tabs .a", blck));
	++i;
	if (i > num_imgs - 1)
	{
		i = 0;
	}
	var nav_elm = $(".m_tabs li", blck).eq(i);
	var new_img = $(".image .list li", blck).eq(i);
	var old_img = $(".image .list .a", blck);
	if (nav_elm.length == 1 && new_img.length == 1)
	{
		$(".image .list .next_a", blck).removeClass("next_a");
		new_img.addClass("next_a");
		$(".m_tabs .a", blck).removeClass("a");
		nav_elm.addClass("a");
		old_img.fadeOut(fade_out, function()
			{
				$(".image .list .next_a", blck).removeClass("next_a").addClass("a");
				old_img.removeClass("a").show();
			}
		);
	}
	return;
}
// casting blanket
function cast_blanket(popup, time)
{
	var document_h = $(document).height();
	var document_w = $(window).width();
	$("<div></div>").attr({id: "blanket"}).css({height: document_h, left: 0, opacity: 0.5, position: "absolute", top: 0, width: document_w, zIndex: 1005}).appendTo($("body"));
	if ($.browser.msie)
	{
		$("<iframe></iframe>").attr({id: "blanket_iframe"}).css({border: 0, height: document_h, left: 0, opacity: 0, position: "absolute", top: 0, width: document_w, zIndex: 1004}).appendTo($("body"));
	}
	position_popup(popup);
	$(window).on("resize", function()
		{
			change_blanket();
			position_popup(popup);
		}
	);
	if (time != 0)
	{
		popup.fadeIn(time);
	}
	else
	{
		popup.show();
	}
	$("#blanket").on("click", function()
		{
			remove_blanket(popup, 0);
			if (popup.attr("id") == 'ww_whattodo')
			{
	   submit_frm('done');
			}
		}
	);
	return;
}
// changing dimensions of blanket
function change_blanket()
{
	var document_h = $(document).height();
	var document_w = $(window).width();
	$("#blanket").css({height: document_h, width: document_w});
	$("#blanket_iframe").css({height: document_h, width: document_w});
}
// castaway blanket
function remove_blanket(popup, time)
{
	if (time != 0)
	{
		popup.fadeOut(time);
  setTimeout(function() { $("#blanket").css({opacity: 0}); }, time);
  setTimeout(function() { $("#blanket_iframe").remove(); }, time);
  setTimeout(function() { $("#blanket").remove(); }, time);
	}
	else
	{
	popup.hide();
	$("#blanket").css({opacity: 0});
	$("#blanket_iframe").remove();
	$("#blanket").remove();
	}
	return;
}
// emulate position fixed for ie6
function emule_fixed_ie6(elm, corr_top)
{
	if ($.browser.msie && $.browser.version <= 6)
	{
		var elm_t = (!isNaN(parseInt(elm.css("top")))) ? parseInt(elm.css("top")) : 0;
		var elm_l = (!isNaN(parseInt(elm.css("left")))) ? parseInt(elm.css("left")) : 0;
		elm_t = elm_t + corr_top;
		doc_h = $(document).height() - $(window).height();
		$(window).on("scroll", function()
			{
				elm.css({top: $(window).scrollTop() + elm_t});
				if ($(window).scrollTop() > doc_h)
				{
					$(window).scrollTop(doc_h);
				}
			}
		);
	}
	return;
}
// input hints
function init_input_hint()
{
	$(":input").each(function()
		{
			var elm = $(this);
			var text = elm.attr("title");
			elm.on("focus", function()
			{
				$(this).parents(".error").removeClass("error");
				if (elm.hasClass("hlp_input"))
				{
					$(this).addClass("hlp_toggle");
					$(this).removeClass("hlp_input");
					if ($(this).val() == text)
					{
						$(this).val('');
					}
				}
				else if (elm.hasClass("hlp_pass"))
				{
					$(".hlp_pass_txt", $(this).parents(".input")).hide();
					$(this).addClass("hlp_pass_toggle");
					$(this).removeClass("hlp_pass");
				}
			}
			);
			elm.on("blur", function()
			{
				if ($(this).val() == '' && elm.hasClass("hlp_toggle"))
				{
					$(this).val(text);
					$(this).addClass("hlp_input");
				}
				else if ($(this).val() == '' && elm.hasClass("hlp_pass_toggle"))
				{
					$(".hlp_pass_txt", $(this).parents(".input")).show();
					$(this).addClass("hlp_pass");
					$(this).parents(".input").addClass("noth");
				}
			}
			);
		}
	);
	return;
}
// init ny popup
function init_nyterms(cookie_name)
{
	var expire = 30;
	var flg_seen = read_cookie(cookie_name);
	if (flg_seen != 'seen')
	{
		cast_blanket($("#ww_nyterms"), 0);
		$("#frm_nyterms_y").on("click", function()
			{
				if ($(this).is(":checked"))
				{
					$("#ww_nyterms .lnk_y").removeClass("lnk_notaccept");
				}
				else
				{
					$("#ww_nyterms .lnk_y").addClass("lnk_notaccept");
				}
			}
		);
		$("#ww_nyterms .lnk_n").on("click", function(e)
			{
				e.preventDefault();
				remove_blanket($("#ww_nyterms"), 0);
			}
		);
		$("#ww_nyterms .lnk_y").on("click", function(e)
			{
				e.preventDefault();
				if ($("#frm_nyterms_y").is(":checked"))
				{
					create_cookie(cookie_name, 'seen', expire);
					$("form[name=cart_form] :submit").trigger("click");
					remove_blanket($("#ww_nyterms"), 0);
				}
			}
		);
	}
	else
	{
		$("form[name=cart_form] :submit").trigger("click");
	}
}
// off float
function init_offfloat()
{
	// account create good - right column floating
	var elm = $(".fixed_float");
	if (elm.length == 1)
	{
		var off_fixed_float = elm.offset();
		var off_footer = $("#footer_table").offset();
		var off_frame = $("#frame").offset();
		var flg_done = false;
		if (off_frame != null)
	 {
		$(document).on("scroll", function()
			{
				var elm_w = elm.width();
				var elm_h = elm.height();
				var doc_h = $(document).height();
				var win_h = $(window).height();
				var footer_h = $("#foot_blck").height() + 20;
				var gap = off_frame.left - $("#frame").offset().left;
				//var toppx = (!elm.hasClass("menu")) ? 0 : 12;
				if ($(this).scrollTop() >= off_fixed_float.top)
				{
					if (!flg_done)
					{
						elm.width(elm_w);
						elm.css({position: "fixed", left: off_fixed_float.left - $(this).scrollLeft(), top: 12});
						flg_done = true;
	    }
	    elm.css({left: off_fixed_float.left - $(this).scrollLeft() - gap});
					if (doc_h - $(this).scrollTop() - footer_h < elm_h)
					{
						elm.css({top: doc_h - $(this).scrollTop() - footer_h - elm_h});
					}
					else
					{
						elm.css({top: 12});
					}
				}
				else if (flg_done)
				{
					if (flg_done)
					{
						elm.css({position: "relative", left: "auto", top: "auto"});
						flg_done = false;
					}
				}
			}
		);
	 }
		$(window).on("resize", function()
			{
				var gap = off_frame.left - $("#frame").offset().left;
				if (elm.css("position") == "fixed")
				{
					elm.css({left: off_fixed_float.left - $(this).scrollLeft() - gap});
				}
			}
		);
	}
	return;
}
// init postcards price
function init_postcards_price()
{
	if ($("#postcards_prices").length == 1 && $(".good form select[name=qty]").length == 1)
	{
		var p = $(".good form");
	 var qty = $(".good form select[name=qty]").val();
		var use_blank_item = ($("input[name=use_blank_item]", p).length == 1) ? $("input[name=use_blank_item]", p).val() : 'undefined';
		$.post("/cart/get_tov_price", {id: $("input[name=product]", p).val(), override_item: $("input[name=override_item]", p).val(), use_blank_item: use_blank_item, qty: qty}, function(res)
		{
	  var price = parseFloat(res); // это цена
	  // для дополнительного селекта
			if ($(".good .size_sel select").length == 1)
			{
				var pr_add = 0;
				if ($(".good .size_sel select :selected").length == 1)
				{
					pr_add = ($(".good .size_sel select :selected").attr("price_diff")) ? parseFloat($(".good .size_sel select :selected").attr("price_diff")) : 0;
				}
		  $("#postcards_prices .old .price").text(parseFloat($("#tovar_original_price").val()) + pr_add);
		  $("#postcards_prices .new .price").text(price + pr_add);
		  $("#tovar_price_container").text((price + pr_add) * qty);
			}
			else
			{
		  $("#postcards_prices .new .price").text(price);
		  $("#tovar_price_container").text(price * qty);
			}
	  if (qty > 1)
	  {
		  $("#postcards_prices").show();
			}
			else
			{
		  $("#postcards_prices").hide();
			}
		});
	}
}
// init promo images at index
function init_promo_images()
{
	if ($("#index .promo").length == 1)
	{
		var period = 3500;
		var fade_out = 800;
		var num_imgs = $("#index .promo .image .list li").length;
		// animate images in #promo block
		$(window).load(function()
			{
				if ($("#index .promo .m_tabs li").length > 1 && num_imgs > 1)
				{
					$(document).everyTime(period+fade_out, "images", function()
						{
							animate_i_imgs(num_imgs, period, fade_out);
						}
					);
				}
			}
		);
		// navigate promo images
		$("#index .promo .m_tabs li a").on("click", function(e)
			{
				e.preventDefault();
				var blck = $(this).parents(".promo");
				var p = $(this).parents(".m_tabs li");
				if (!p.hasClass("a"))
				{
					var indx = $(".m_tabs li", blck).index(p);
					var new_img = $(".image .list li", blck).eq(indx);
					if ($(":animated", blck).length == 1)
					{
						if (!new_img.hasClass("a"))
						{
							$(".m_tabs .a", blck).removeClass("a");
							p.addClass("a");
							$(".image .list .next_a", blck).removeClass("next_a");
							new_img.addClass("next_a");
						}
					}
					else
					{
						$(document).stopTime("images");
						$(".m_tabs .a", blck).removeClass("a");
						p.addClass("a");
						var old_img = $(".image .list .a", blck);
						$(".image .list .next_a", blck).removeClass("next_a");
						new_img.addClass("next_a");
						old_img.fadeOut(fade_out, function()
							{
								$(".image .list .next_a", blck).removeClass("next_a").addClass("a");
								old_img.removeClass("a").show();
								$(document).everyTime(period+fade_out, "images", function()
									{
										animate_i_imgs(num_imgs, period, fade_out);
									}
								);
							}
						);
					}
				}
			}
		);
	}
	return;
}
// init what to do popup
function init_whattodo(cookie_name)
{
	var expire = 165;
	var flg_seen = read_cookie(cookie_name);
	if (flg_seen != 'seen')
	{
		cast_blanket($("#ww_whattodo"), 0);
		$("#ww_whattodo :submit").on("click", function(e)
			{
				e.preventDefault();
				if ($("#frm_whattodo_chk").is(":checked"))
				{
					create_cookie(cookie_name, 'seen', expire);
				}
				remove_blanket($("#ww_whattodo"), 0);
    submit_frm('done');
			}
		);
		$("#ww_whattodo .close a").on("click", function(e)
			{
				e.preventDefault();
				remove_blanket($("#ww_whattodo"), 0);
    submit_frm('done');
			}
		);
	}
	else
	{
		submit_frm('done');
	}
}
// checking string length and cut if needed
function check_str_lngth(elm, max, parent)
{
	var elm_val = elm.val();
	if (elm_val.length > max)
	{
		var elm_val_new = elm_val.substring(0, max);
		elm.val(elm_val_new);
		$(".str_lngth span", elm.parents(parent)).text("0");
	}
	else
	{
		$(".str_lngth span", elm.parents(parent)).text(max - elm_val.length);
	}
	return;
}
// cookies
function create_cookie(name, value, days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires="+date.toGMTString();
	}
	else
	{
		var expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

function read_cookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	var ca_lngth = ca.length;
	for (var i = 0; i < ca_lngth; i++)
	{
		var c = ca[i];
		while (c.charAt(0) == ' ')
		{
			c = c.substring(1, c.length);
		}
		if (c.indexOf(nameEQ) == 0)
		{
			return c.substring(nameEQ.length, c.length);
		}
	}
	return null;
}

function erase_cookie(name)
{
	create_cookie(name, "", -1);
}
// positioning popup
function position_popup(popup)
{
	var view_width = $(window).width();
	var view_height = $(window).height();
	var popup_width = popup.width();
	var popup_height = popup.height();
	var popup_loading_left = Math.ceil((view_width - popup_width) / 2) + $(document).scrollLeft();
	var popup_loading_top = Math.ceil((view_height - popup_height) / 2) + $(document).scrollTop();
	if (view_width - popup_width < 0)
	{
		popup_loading_left = $(document).scrollLeft() + 10;
	}
	if (view_height - popup_height < 0)
	{
		popup_loading_top = $(document).scrollTop() + 10;
	}
	if (popup.css("position") == 'fixed')
	{
		var popup_loading_left = Math.ceil((view_width - popup_width) / 2);
		var popup_loading_top = Math.ceil((view_height - popup_height) / 2);
		if (view_width - popup_width < 0)
		{
			popup_loading_left = 10;
		}
		if (view_height - popup_height < 0)
		{
			popup_loading_top = 10;
		}
	}
	popup.css({left: popup_loading_left, top: popup_loading_top});
	return;
}
// setting equal height for a set of blocks
function set_eqheight_blcks(blcks)
{
	var li_heights = new Array();
	var i = 0;
	var li_max = 0;
	blcks.each(function()
		{
			li_heights[i] = $(this).height();
			++i;
		}
	);
	if (li_heights.length > 0)
	{
		li_heights.sort(sort_num);
		li_max = li_heights[0];
	}
	blcks.each(function()
		{
			$(this).height(li_max);
		}
	);
	return;
}
// ww add 2 cart
function show_ww_goodadd()
{
	cast_blanket($("#ww_goodadd"), 0);
	// close
 $("#ww_goodadd .btn_cont").on("click", function(e)
		{
			e.preventDefault();
			remove_blanket($("#ww_goodadd"), 0);
		}
	);
}
// sorting
function sort_num(arg_1, arg_2)
{
	if (arg_1 > arg_2)
	{
		return -1;
	}
	else
	{
		return 1;
	}
}
// switch tabs tell window
function switch_tell_tabs(part)
{
	$("#ww_tell .method li").each(function()
		{
			$(this).removeClass("a");
			if ($("."+part, $(this)).length == 1)
			{
				$(this).addClass("a");
			}
			else
			{
				var cur_class = $("a", $(this)).attr("class");
				$("#"+cur_class).hide();
			}
		}
	);
	$("#"+part).show();
	if (!$.browser.msie || ($.browser.msie && $.browser.version > 6))
	{
		position_popup($("#ww_tell"));
	}
	return;
}
$(document).ready(function(){
 $('.wrap_r').show(10, function()
		{
			// copy buffer init
  	$("#lnk_goodurl").trigger("click");
		}
	);
	init_input_hint();
	init_offfloat();
	init_promo_images();
	$(".btns_sites .list li a").hover(
		function()
		{
			var parent = $(this).parents("li");
			if ($(".smth", $(this)).length < 1)
			{
				$("<span></span>").attr({className: "smth"}).appendTo($(this));
			}
			parent.addClass("hover");
		},
		function()
		{
			var parent = $(this).parents("li");
			parent.removeClass("hover");
		}
	);
	// ballon for discount info
	$(".price_oldprice").hover(
		function()
		{
			var str = $(".d_type", $(this)).text();
			var offset = $(this).offset();
			$('<div class="ww_balloon_140 iepng"><div class="wrap">Применяемая скидка:<br />'+str+'</div></div>').appendTo("body");
			$(".ww_balloon_140").css({left: offset.left - 80, top: offset.top - 50});
		},
		function()
		{
			$(".ww_balloon_140").remove();
		}
	);
	emule_fixed_ie6($("#lnk_right"), -209);
	// facebook info ww
	$(".ww_facebook a").on("click", function(e)
		{
			e.preventDefault();
			cast_blanket($("#ww_facebook"), 0);
		}
	);
	$("#ww_facebook .close a").on("click", function(e)
		{
			e.preventDefault();
			remove_blanket($("#ww_facebook"), 0);
		}
	);
	$("#ww_facebook .lnk_close").on("click", function(e)
		{
			e.preventDefault();
			remove_blanket($("#ww_facebook"), 0);
		}
	);
	// zoom button functionality - product info (tovar_images_group.tpl)
	$(".good_left .btns .btn_zoom a").on("click", function(e)
		{
			e.preventDefault();
			$(".good_left .cur_photo a").trigger("click");
		}
	);
	// buttons functionality - product info (tovar_images_group.tpl)
	$(".good_left .btns a").on("click", function(e)
		{
			e.preventDefault();
			var p = $(this).parents('li');
			if (!$(this).hasClass("a"))
			{
				if (p.hasClass("btn_photo"))
				{
				 $(".good_left .thumbs .t_photo").eq(0).trigger("click");
				 $(".good_left .btns .a").removeClass("a");
				 $(this).addClass("a");
				}
				else if (p.hasClass("btn_good"))
				{
				 $(".good_left .thumbs .t_good").eq(0).trigger("click");
				 $(".good_left .btns .a").removeClass("a");
				 $(this).addClass("a");
				}
				else if (p.hasClass("btn_zoom"))
				{
					$(".good_left .cur_photo a").trigger("click");
				}
			}
		}
	);
	// thumbs hover - product info (tovar_images_group.tpl)
	$(".good_left .thumbs a").hover(
		function()
		{
			var p = $(this).parents('li');
			var img = $(".photo", p).html();
			$(".good_left .cur_photo .tmp_photo").empty().css({zIndex: 2}).html(img);
		},
		function()
		{
			$(".good_left .cur_photo .tmp_photo").css({zIndex: -1}).empty();
		}
	);
	// thumbs select - product info (tovar_images_group.tpl)
	$(".good_left .thumbs a").on("click", function(e)
		{
			e.preventDefault();
			if (!$(this).hasClass("a"))
			{
				var p = $(this).parents('li');
				var img = $(".photo", p).html();
				$(".good_left .thumbs .a").removeClass("a");
				$(this).addClass("a");
				$(".good_left .cur_photo .tmp_photo").empty();
				$(".good_left .cur_photo a").empty().html(img);
			}
                        if ($(this).hasClass("t_photo"))
                        {
                            $(".good_left .btns .btn_photo a").addClass("a");
                            $(".good_left .btns .btn_good a").removeClass("a");
                        }
                        if ($(this).hasClass("t_good"))
                        {
                            $(".good_left .btns .btn_photo a").removeClass("a");
                            $(".good_left .btns .btn_good a").addClass("a");
                        }
		}
	);
	// product info links enable/disable
	if ($("#good_share_lnks").is(":visible"))
	{
		// init
		$(".good .btns_sites").each(function()
			{
				$("<div></div>").attr({className: "curtain"}).css({opacity: .5}).appendTo($(this));
			}
		);
		$("#chk_availout").on("change", function()
			{
				if ($(this).is(":checked"))
				{
					$(".good .curtain").hide();
				}
				else
				{
					$(".good .curtain").show();
				}
			}
		);
                if ($("#chk_availout").is(":checked"))
                {
                        $(".good .curtain").hide();
                }
                else
                {
                        $(".good .curtain").show();
                }
	}
	// good share url no change
	$("#frm_goodurl").on("change keyup", function()
		{
   $(this).val($(this).attr("title"));
		}
	);
	// what to do ww
	$("#editor .lnk_finalsave").on("click", function(e)
		{
			e.preventDefault();
			init_whattodo("whattodo");
		}
	);
	// adding_items_to_shop input fields highlight
	$("#adding_items_to_shop :input").on("focus", function()
		{
			$(this).addClass("inp_hover").addClass("inp_noerr");
		}
	);
	$("#adding_items_to_shop :input").on("blur", function()
		{
			$(this).removeClass("inp_hover");
		}
	);
	// #reg input fields highlight
	$("#reg :input").on("focus", function()
		{
			$(this).addClass("inp_hover").addClass("inp_noerr");
		}
	);
	$("#reg :input").on("blur", function()
		{
			$(this).removeClass("inp_hover");
		}
	);
	// non node popup close
	$("#ww_nonode .btn_ok").on("click", function(e)
		{
			e.preventDefault();
			remove_blanket($("#ww_nonode"), 0);
		}
	);
	// product all create link info popup if no source
	$(".prod_all .goods .thumb a, .prod_all .goods .lnk_create, .prod_all .goods .title a").on("click", function(e)
		{
			e.preventDefault();
			var p = $(this).parents("li");
			var href = $(".lnk_create", p).attr("href");
			var id = href.replace(/.*products\[\]=(\d+)/, "$1");
			if (!isNaN(parseFloat(id)) && isFinite(id))
			{
				$.post('/tovar/check_item', {item_id: id}, function(res)
				{
					if (res > 0)
					{
						window.location.href = href;
					}
					else
					{
						cast_blanket($("#ww_nosource"), 0);
						// continue
					 $("#ww_nosource .lnk_cont").on("click", function(e)
							{
								e.preventDefault();
								var href = $(".lnk_create", p).attr("href");
								window.location.href = href;
							}
						);
						// close
					 $("#ww_nosource .lnk_cancel").on("click", function(e)
							{
								e.preventDefault();
								$("#ww_nosource .lnk_cont").off("click");
								$("#ww_nosource .lnk_cancel").off("click");
								remove_blanket($("#ww_nosource"), 0);
							}
						);
					}
				});
			}
			else
			{
				window.location.href = href;
			}
		}
	);
	// vacancies hover
	$(".vacancies .list_v .li").hover(
		function()
		{
			if (!$(this).hasClass("hover"))
			{
				$(".vacancies .list_v .li").removeClass("hover");
				$(this).addClass("hover");
			}
		},
		function()
		{
		}
	);
	// vacancy expand/collapse
	$(".vacancies .list_v .lnk_more").on("click", function(e)
		{
			e.preventDefault();
			var p = $(this).parents(".li");
			$(".vacancies .list_v .a").each(function()
				{
					$(".description", $(this)).slideUp(400, function()
						{
							$(this).parents(".list_v .a").removeClass("a");
						}
					);
				}
			);
			p.addClass("a");
			$(".description", p).slideDown(400);
		}
	);
	// vacancy collapse
	$(".vacancies .list_v .lnk_less").on("click", function(e)
		{
			e.preventDefault();
			var p = $(this).parents(".li");
			$(".description", p).slideUp(400, function()
				{
					p.removeClass("a");
				}
			);
		}
	);
	// bcards tabs switch
	$(".bcards .pr_details .m_tabs a").on("click", function(e)
		{
			e.preventDefault();
			var m_tabs = $(".bcards .pr_details .m_tabs");
			var tabs = $(".bcards .pr_details .tabs");
			var p = $(this).parents(".tab");
			if (!p.hasClass("a"))
			{
				var indx = $(".tab", m_tabs).index(p);
				$(".a", m_tabs).removeClass("a");
				p.addClass("a");
				if ($(".tab", tabs).eq(indx).length == 1)
				{
					$(".a", tabs).removeClass("a");
					$(".tab", tabs).eq(indx).addClass("a");
				}
			}
		}
	);
	// .bcards .ptypes .list .thumb hover
	$(".bcards .ptypes .list .thumb").hover(
		function()
		{
			var p = $(this).parents('.li');
			if (!$(this).hasClass("hover"))
			{
   	$(".bcards .ptypes .list .hover").removeClass("hover");
   	p.addClass("hover");
			}
		},
		function()
		{
			var p = $(this).parents('.li');
			p.removeClass("hover");
		}
	);
	// setting equal height
	set_eqheight_blcks($(".hlp_eq_1"));
	set_eqheight_blcks($(".hlp_eq_2"));
	set_eqheight_blcks($(".hlp_eq_3"));
	// show info after image loaded bcards
	if ($(".bcards .promo").length == 1)
	{
	 var bcard_img = $(".bcards .promo").css("backgroundImage");
	 if (bcard_img != null)
	 {
	 	$(".bcards .promo .col_l").css({visibility: "hidden"});
	 	var bcard_img_r = bcard_img.replace(/url\("?(.*)"?\)/, "$1");
	 	bcard_img_r = bcard_img_r.replace('"', '');
		 var ximg = $("<img>").attr({id: "ximg2del", src: bcard_img_r+"?random="+(new Date()).getTime()}).css({display: "none"}).appendTo(document);
		 ximg.on("load", function()
				{
			 	$(".bcards .promo .col_l").css({visibility: "visible"});
			 	$("#ximg2del").remove();
				}
			);
			window.setTimeout(function()
				{
					if ($(".bcards .promo .col_l").css("visibility") == "hidden")
					{
				 	$(".bcards .promo .col_l").css({visibility: "visible"});
				 	$("#ximg2del").remove();
					}
				}, 7000
			);
		}
	}
	// vizitki photo popup
	$(".vizitki .images li a").on("click", function(e)
		{
			e.preventDefault();
			var p = $(this).parents(".images");
			var indx_p = $(".vizitki .images").index(p);
			var indx = $("li", p).index($(this).parent("li"));
			var i_count = $("li", p).length;
			var title = $("img", $(this)).attr("title");
			var ww = $("#ww_vphoto");
			$(".photo", ww).empty();
			$(".photo", $(this).parent("li")).clone().appendTo($(".photo", ww));
			$(".title", ww).text(title);
			if (i_count > 1)
			{
				$(".counter", ww).text("Изображение: "+(indx+1)+"/"+i_count);
				$(".nav_prev", ww).attr({rel: indx_p, href: indx - 1});
				$(".nav_next", ww).attr({rel: indx_p, href: indx + 1});
				if (indx == 0)
				{
					$(".nav_next", ww).show();
					$(".nav_prev", ww).hide();
				}
				else if (indx == i_count - 1)
				{
					$(".nav_next", ww).hide();
					$(".nav_prev", ww).show();
				}
				else
				{
					$(".nav_next", ww).show();
					$(".nav_prev", ww).show();
				}
			}
			cast_blanket($("#ww_vphoto"), 0);
		}
	);
	$("#ww_vphoto .lnk_close").on("click", function(e)
		{
			e.preventDefault();
			remove_blanket($("#ww_vphoto"), 0);
		}
	);
	$("#ww_vphoto .nav_prev, #ww_vphoto .nav_next").on("click", function(e)
		{
			e.preventDefault();
			var indx_p = $(this).attr("rel");
			var indx = parseInt($(this).attr("href"));
			var p = $(".vizitki .images").eq(indx_p);
			if (p.length == 1)
			{
				var elm = $("li", p).eq(indx);
				if (elm.length == 1)
				{
					var i_count = $("li", p).length;
					var title = $("a img", elm).attr("title");
					var ww = $("#ww_vphoto");
					$(".photo", ww).empty();
					$(".photo", elm).clone().appendTo($(".photo", ww));
					$(".title", ww).text(title);
					if (i_count > 1)
					{
						$(".counter", ww).text("Изображение: "+(indx+1)+"/"+i_count);
						$(".nav_prev", ww).attr({rel: indx_p, href: indx - 1});
						$(".nav_next", ww).attr({rel: indx_p, href: indx + 1});
						if (indx == 0)
						{
							$(".nav_next", ww).show();
							$(".nav_prev", ww).hide();
						}
						else if (indx == i_count - 1)
						{
							$(".nav_next", ww).hide();
							$(".nav_prev", ww).show();
						}
						else
						{
							$(".nav_next", ww).show();
							$(".nav_prev", ww).show();
						}
					}
				}
			}
		}
	);
	// vizitki/about lnk_create action
	$(".bcards .tstcards .lnk_create").on("click", function(e)
		{
			e.preventDefault();
			var p_form = $(this).parents(".image");
			$(":submit", p_form).trigger("click");
		}
	);
	// price for postcards
	init_postcards_price();
 $(".good form select[name=qty]").on("change", function()
		{
			init_postcards_price();
		}
	);
	//
	$("#header .m_top .li").hover(
		function()
		{
			if ($(".sub", $(this)).length == 1)
			{
				$(this).addClass("hover");
			}
		},
		function()
		{
			$(this).removeClass("hover");
		}
	);
	// search field init
	if ($("#frm_search").length == 1)
	{
		var s_val = $("#frm_search").val();
		if (s_val == '')
		{
			$("#frm_search").val($("#frm_search").attr("title"));
		}
	}
	// search input check
	$(".search_form").on("submit", function(e)
		{
			e.preventDefault();
			var keyword = $(".search_form input[name=search_keyword]");
			if (keyword.val() == keyword.attr("title"))
			{
				keyword.val('');
			}
			$(".search_form").off("submit");
			$(".search_form").submit();
		}
	);
	
	// ny terms info ww
	/*
	$(".add2cart").on("click", function(e)
		{
			e.preventDefault();
			var p = $(this).parents("form");
			if ($(".size_sel select", p).val() != 0)
			{
				init_nyterms("nyterms");
			}
		}
	);
	*/
});
