﻿$(document).ready(
function () {
    //-----------------------------------------
    //    $("img").lazyload({
    //     effect: "fadeIn"
    //});

    var fHeight = $(".imgBorder").height();
    $(".imgBorder img").each(
    function () {
        var hight = fHeight - $(this).height();
        if (hight != fHeight) {
            $(this).css({ "margin-top": hight / 2 + "px" })
        }
    }
    );

    $(".newBook  :nth-child(2)").show(200);

    //-----------------------------------------
    var left = ($(".nav").offset().left);
    $("#Panel").css({ "left": left });

    //-----------------------------------------
    $(".newBook dt").click(
         function () {
             if ($(this).next("dd").css("display") == "none") {
                 $(".newBook dd").hide(300);
                 $(this).next("dd").show(300);
             }
         });
    //-----------------------------------------
    $(".LeftBarContent").css({ "display": "none" });
    $("#ChildrensBook h3,#HomeWork h3,#SocialSciences h3,#EpaperList h3").toggle(
    function () {
        $(this).next(".LeftBarContent").show(300);
    },
     function () {
         $(this).next(".LeftBarContent").hide(300)
     }
     );

    //-----------------------------------------
    var ClickCount = 0;

    $(".UpBtn").click(
    function () {
        if (ClickCount == 8) { ClickCount = -1 }
        ClickCount += 1;
        // $(".UpBtn").text(ClickCount);
        $("#bestSellresMain ul").animate({ "margin-top": ClickCount * $("#bestSellresMain li").height() * (-1) + "px" }, "300");
    }
    );

    $(".DownBtn").click(
    function () {

        if (ClickCount == 0) { ClickCount = 9 }
        ClickCount -= 1;

        $("#bestSellresMain ul").animate({ "margin-top": ClickCount * $("#bestSellresMain li").height() * (-1) + "px" }, "300");
    }
    );
    //-----------------------------------------
    $(".NavItemList li").hover(
            function () {
                var index = $(this).index()
                
                $("#Panel div").css({ "display": "none" })
                if (index == 1) {
                    
                    $(".SubNav").css({ "display": "block" });
                    $("#Panel").delay(200).animate({ "opacity": "show" }, 200);
                    return;
                }
                if (index == 2) {

                    $(".SubNewsNav").css({ "display": "block" });
                    $("#Panel").delay(200).animate({ "opacity": "show" }, 200);
                    return;
                }
                $("#Panel").animate({ "opacity": "hide" }, 300)
                
            },
            function () {
            });
    //---------------------------------------
    $("#Panel").hover(
            function () {
            },
            function () {
                $("#Panel").fadeOut(500)

            });
    //-----------------------------------------
    $(window).resize(
        function () {
            var left = ($(".nav").offset().left);
            $("#Panel").css({ "left": left })
        });
    //-----------------------------------------
    $(".CoverList li,#CoverList li").each(
            function () {
                var objp = $(this);
                $.post(
                            "/Home/Tags/",
                            { bookname: $(this).text() },
                            function (data) {
                                if (data.Url != "") {
                                    // obj.after('<a href=' + data.Url + ' class="TaoLogo" target="_blank"><img src="/Content/images/TaoLogo1.jpg" alt="去淘宝网订购" /></a>');
                                    objp.html(objp.html() + '<a href=' + data.Url + '  class="buyimg"  target="_blank">购买</a>');
                                }
                            },
                            "json"
                            );
            }
                  );

    //-----------------------------------------

    $("#EpaperList a").each(
            function () {

                var objp = $(this);

                $.get(
                        objp.attr("href"),
                         {},
                         function (data) {
                             var title = data.match(/<title>(.+)<\/title>/);
                             objp.text(title[1]);
                         }
                        );
            }
                  );
    //------------------------------------------
}
);
