﻿var t = n = 0, count = 5;
function ShowProductCatalog() {
    $.get("/Home/ProductCatalog", function (result) {
        $("#ProductCatalogs").html(result);
    });
}

var t,n,count;
function displayImage() {
    t = n = 0;
    count = $("#play_list a").size();

    if ($("#play_list").height() >= 400)
        $("#play_list").height(430);
    $("#play_list").css("overflow", "hidden");

    $("#play_list a:not(:first-child)").hide();
    $("#play_text li").eq(0).css({ "background": "#999", "color": "#fff", "font-weight": "bolder" });

    $("#play_text li").mouseover(function () {
        var i = $(this).text() - 1;
        n = i;
        if (i >= count) return;
        $(this).css({ "background": "#999", "color": "#fff", "font-weight": "bolder" }).siblings().css({ "background": "#fff", "color": "#999", "font-weight": "normal" });
        $("#play_list a").filter(":visible").fadeOut(200, function () {
            $(this).parent().children().eq(i).fadeIn(300);
        });
    });

    t = setInterval("showAuto()", 5000);
    $("#play,#play_text").hover(function () {
        clearInterval(t)
    }, function () {
        t = setInterval("showAuto()", 5000);
    });
}

function showAuto() {
    if (n >= (count - 1)) {
        n = 0;
    }
    else {
        ++n;
    }

    var i = $("#play_text li").eq(n).text() - 1;
    if (i >= count) return;
    $("#play_text li").eq(n).css({ "background": "#999", "color": "#fff", "font-weight": "bolder" }).siblings().css({ "background": "#fff", "color": "#999", "font-weight": "normal" });
    $("#play_list a").filter(":visible").fadeOut(200, function () {
        $("#play_list a").parent().children().eq(i).fadeIn(300);
    });
}

function dispCategoryImage() {
    $("div[id^='divCatagoryPic']").each(
        function () {
            var index = $(this).attr("id").replace("divCatagoryPic", "");
            $.getScript("../../Scripts/Category/" + index + ".js");
        }
    );
}

function initProductInfo() {
    $.ajax({
        type: "GET",
        url: "/Home/MainPageProduct",
        success: function (result) {
            $("#ProductList").replaceWith(result);
            dispCategoryImage();
        }
    });
}

function ShowShopNews() {
    $.ajax({
        type: "GET",
        url: "/Home/ShowShopNews",
        success: function (result) {
            $("#ShopNews").html(result);
        }
    });
}

function ShowBrandList() {
    $.ajax({
        type: "GET",
        url: "/Home/ShowBrandList",
        success: function (result) {
            $("#BrandList").html(result);
        }
    });
}

function ShowHotSaleList() {
    $.ajax({
        type: "GET",
        url: "/Home/ShowHotSaleList",
        success: function (result) {
            $("#HotSaleList").html(result);
        }
    });
}

function ShowPopularityList(id) {
    $.ajax({
        type: "GET",
        url: "/Home/ShowPopularityList",
        data: { cid: id },
        success: function (result) {
            $("span[id^='spanPopularityList']").removeClass("jzl_navcoffee").addClass("jzl_navno");
            $("span[id='spanPopularityList" + id + "']").removeClass("jzl_navno").addClass("jzl_navcoffee");
            $("#PopularityList").html(result);
        }
    });
}

function ShowRecommendProducts() {
    $.ajax({
        type: "GET",
        url: "/Home/ShowRecommendProducts",
        success: function (result) {
            $("#RecommendProducts").html(result);
        }
    });
}

function ShowExpertAnswer() {
    $.ajax({
        type: "GET",
        url: "/Home/ShowExpertAnswer",
        success: function (result) {
            $("#ExpertAnswer").append(result);
        }
    });
}

function ShowUseTaste() {
    $.ajax({
        type: "GET",
        url: "/Home/ShowUseTaste",
        success: function (result) {
            $("#UseTaste").html(result);
        }
    });
}

function ShowHealthNews() {
    $.ajax({
        type: "GET",
        url: "/Home/ShowHealthNews",
        success: function (result) {
            $("#HealthNews").html(result);
        }
    });
}

function ShowHotNews() {
    $.ajax({
        type: "GET",
        url: "/Home/ShowHotNews",
        success: function (result) {
            $("#HotNews").html(result);
        }
    });
}
