﻿var mylib =
{
    catalogPage:
	{
	    init: function () {
	        Pather();
	    }
	},
    productListPage:
	{
	    init: function () {
	        Pather();

	        if ($.cookie('hidefilter') == "1") {
	            $("#filter > div.line").hide();
	            $("#hidefilter").text("показать");
	        }

	        $("#hidefilter").click(
		      function () {
		          var a = $(this);
		          if (a.text() == "скрыть") {
		              $("#filter > div.line").hide();
		              a.text("показать");
		              $.cookie('hidefilter', '1');
		          }
		          else {
		              $("#filter > div.line").show();
		              a.text("скрыть");
		              $.cookie('hidefilter', null);
		          }
		          return false;
		      });

	        $("#productlist a.comparelist").click(function () {
	            $("#producttable input:checkbox:checked").each(function () {
	                AddToCompareList($(this));
	            });
	            return false;
	        });

	        $("a.closesubfilter").click(function () {
	            var a = $(this);
	            if (a.text() == "скрыть") {
	                a.parent().children("table").hide();
	                a.text("показать");
	            }
	            else {
	                a.parent().children("table").show();
	                a.text("скрыть");
	            }
	            return false;
	        });

	        $("a.closesubfiltermaker").click(function () {
	            var a = $(this);
	            if (a.text() == "скрыть") {
	                a.parent().parent().prevUntil("tr.u").hide();
	                a.text("показать ещё");
	            }
	            else {
	                a.parent().parent().prevUntil("tr.u").show();
	                a.text("скрыть");
	            }
	            return false;
	        });
	    }
	},
    productPage:
	{
	    init: function () {
	        Pather();

	        $('a.buybtn').bind("click", function (e) {
	            var count = 1;
	            var attr = $(this).attr("multi");
	            var IsMulty = attr == undefined ? false : true;
	            if (IsMulty) {
	                count = parseInt(attr);
	            }
	            AddToBasket(this, count, e, true);
	            return false;
	        });

	        $("a.aservice").bind("click", function (e) {
	            var a = $(this);
	            var div = a.next();
	            if (div.is(":visible")) {
	                a.css("background", "url(/images/icon_plus_s.png) no-repeat left 5px");
	            }
	            else {
	                a.css("background", "url(/images/icon_minus_s.png) no-repeat left 5px");
	            }
	            div.toggle();
	            return false;
	        });

	        var w = 600;
	        var h = 600;
	        $('a.thickbox').openDOMWindow({
	            borderColor: "#b0b0b0",
	            overlayColor: "#25323a",
	            overlayOpacity: "60",
	            width: w,
	            height: h,
	            borderSize: "1",
	            positionType: 'centered',
	            positionTop: 20,
	            eventType: 'click',
	            windowSource: 'iframe',
	            windowPadding: 0,
	            loader: 1,
	            loaderImagePath: 'http://images.LG-goods.ru/images/loadingAnimation.gif',
	            loaderHeight: 16,
	            loaderWidth: 17,
	            shadow: true
	        });

	        $("#errorShow").bind("click", function (e) {
	            $("#errorBlock").toggle();
	            return false;
	        });

	        $("#errorSend").bind("click", function (e) {
	            var msgBlock = $("#errorMessage");
	            var msg = msgBlock.val() + "&msg=" + escape($("#errorTextBox").val());

	            $.get("/SendError.ashx?" + msg, function (data) {
	                $("#errorBlock").html("Ваще сообщение об ошибке принято. Спасибо!");
	            });

	            return false;
	        });
	    }
	},
    allPages:
	{
	    init: function () {
	          onResize();
	        var mHeight = 558;
	        var mWidth = 680;
	        if ($.browser.msie) {
	            mHeight = mHeight + 2;
	        }
	        $('a.devpoint').openDOMWindow({
	            borderColor: "#7DBB24",
	            borderSize: "1",
	            height: mHeight,
	            width: mWidth,
	            positionType: 'centered',
	            positionTop: 50,
	            eventType: 'click',
	            positionLeft: 50,
	            windowSource: 'iframe',
	            windowPadding: 0,
	            loader: 1,
	            loaderImagePath: '/images/loader.gif',
	            loaderHeight: 30,
	            loaderWidth: 220,
	            overlayOpacity: 0
	        });

	        $("#townselect, #townselect2").click(function () {
	            $("#townselectorblock").toggle();
	            return false;
	        });

	        var timerOnce;
	        $("#townselect").hover(function () {
	            var position = $("#town").position();
	            var block = $("#townselectorpopup");
	            block.css("top", (position.top + 30) + "px");
	            block.css("left", (position.left + $("#town").width() - 155) + "px");
	            block.show();
	            return false;
	        },
            function () {
                timerOnce = window.setTimeout(function () {
                    $("#townselectorpopup").hide();
                }, 2000);

            });

	        $("#townselectorpopup").hover(function () {
	            if (timerOnce != undefined) {
	                window.clearTimeout(timerOnce);
	            }
	        },
            function () {
                $("#townselectorpopup").hide();
            }
            );


	       /* $("a.compare").live("click", function (e) {
	            var a = $(this);
	            AddToCompare(a);
	            return false;
	        });*/

	        $("a.tech").live("click", function () {
	            var a = $(this);
	            $.get(a.attr("href"), function (data) {
	                var div = $("#tech_popup");
	                div.children("div.techcontent").html(data);
	                var position = a.position();
	                div.css("left", position.left + "px");
	                div.css("top", (position.top + 15) + "px");
	                div.show();
	            });
	            return false;
	        });

	        $("#tecgclose a.close").click(function () {
	            var div = $("#tech_popup");
	            div.hide();
	            return false;
	        });

	        $("body").click(
	          function (e) {
	              var div = $("#tech_popup");
	              div.hide();
	          });

	        $("a.miniAdd").live("click", function (e) {
	            var count = 1;
	            var attr = $(this).attr("multi");
	            var IsMulty = attr == undefined ? false : true;
	            if (IsMulty) {
	                count = parseInt(attr);
	            }
	            AddToBasket(this, count, false, false);
	        });

	        $("a.miniDel").live("click", function (e) {
	            var goodcount = 1;
	            var attr = $(this).attr("multi");
	            var IsMulty = attr == undefined ? false : true;
	            if (IsMulty) {
	                goodcount = parseInt(attr);
	            }
	            DeleteToBasket(this, goodcount);
	            var elem = $(this);
	            var tr = elem.parent().parent();
	            var count = tr.find("span.c");
	            var productCount = parseInt(count.text());
	            var newCount = productCount - goodcount;
	            if (newCount == 0) {
	                var separator = tr.next();
	                if (separator != undefined) {
	                    separator.remove();
	                }
	                tr.remove();
	            }
	            else {
	                count.text(newCount);
	            }
	        });

	        $("#searchtb").example('поиск по товарам');

	        $("#basket_slide").click(function () {
	            if (isBasketSlided) {
	                $("#basket_goods").animate({ height: "0px", paddingTop: "0px", paddingBottom: "0px" }, 500, null, function ()
	                { isBasketSlided = false; $("#basket_slide").css("background", "url(/images/basket_slide.png) no-repeat") });

	                $("#basket_goods_d").animate({ height: "0px", paddingTop: "0px", paddingBottom: "0px" }, 500, null, function ()
	                { isBasketSlided = false; $("#basket_slide").css("background", "url(/images/basket_slide.png) no-repeat") });
	            }
	            else {
	                var w = $("#basket_goods table").height();
	                if (w != null) {
	                    $("#basket_goods").animate({ height: w + "px", paddingTop: "5px", paddingBottom: "5px" }, 500, null, function ()
	                    { isBasketSlided = true; $("#basket_slide").css("background", "url(/images/basket_slide_close.png) no-repeat") });
	                }

	                w = $("#basket_goods_d table").height();
	                if (w != null) {
	                    $("#basket_goods_d").animate({ height: w + "px", paddingTop: "5px", paddingBottom: "5px" }, 500, null, function ()
	                    { isBasketSlided = true; $("#basket_slide").css("background", "url(/images/basket_slide_close.png) no-repeat") });
	                }
	            }
	        });

	        $("body").click(
	          function () {
	              if (isDelivMenuShow) {
	                  $("#delivmenu").hide();
	                  isDelivMenuShow = false;
	              }
	              if (isSlided) {
	                  $("#slide").animate({
	                      marginTop: "-" + slideHeight + "px"
	                  }, 500);
	                  isSlided = false;
	                  $("#slidebtn").css("background", "url(/images/new/slide_btn.png)");
	              }

	              var popUp = $("#pather div.popupmenu");
	              popUp.hide();

	              $("#pather a.showPath img").attr("src", "/images/path.png");
	          });
	    }
	}
};
