
/******************** index ********************/
$(document).on("pageshow", "#index", function () {

    var wid = $(window).width();
    $("#index_play").css("height", wid / 3 + "px");
    $("#index_play img").css("height", wid / 3 + "px");
    $("#index_textbg").css("margin-top", wid / 3 - 40 + "px");
    $("#index_text").css("margin-top", wid / 3 - 38 + "px");
    $("#index_num").css("margin-top", wid / 3 - 24 + "px");

    var t = n = 0; count = $(".img_content a").size();
    var st = 0;
    var play = ".play";
    var playNum = ".play .num a";
    var playConcent = ".play .img_content a";

    $(playConcent + ":not(:first)").hide();
    $(playNum + ":first").addClass("on");
    $(playNum).click(function () {
        var i = $(this).text() - 1;
        n = i;
        if (i >= count) return;
        $(playConcent).filter(":visible").hide().parent().children().eq(i).fadeIn("fast");
        $(this).removeClass("on").siblings().removeClass("on");
        $(this).removeClass("on2").siblings().removeClass("on2");
        $(this).addClass("on").siblings().addClass("on2");
    });
    t = setInterval(function () {
        if (st == 1) {
            n = n <= (count - 1) ? --n : 3;
        } else {
            n = n >= (count - 1) ? 0 : ++n;
        }
        $(".num a").eq(n).trigger('click');
    }, 2000);
    $(playConcent).bind("swiperight", function () { clearInterval(t) }, function () {
        var i;
        st = 0;
        if (n == 0) {
            i = 1;
            n = 1;
        } else {
            i = n + 1;
            n++;
        }
        if (i >= count) {
            i = 0;
            n = 0;
        }
        $(playConcent).filter(":visible").hide().parent().children().eq(i).fadeIn(1000);
        $(".num a").eq(n).removeClass("on").siblings().removeClass("on");
        $(".num a").eq(n).removeClass("on2").siblings().removeClass("on2");
        $(".num a").eq(n).addClass("on").siblings().addClass("on2");
    })
    $(playConcent).bind("swipeleft", function () { clearInterval(t) }, function () {

        var i;
        st = 1;
        if (n == 0) {
            i = 3;
            n = 3;
        } else {
            i = n - 1;
            n--;
        }
        $(playConcent).filter(":visible").hide().parent().children().eq(i).fadeIn(1000);
        $(".num a").eq(n).removeClass("on").siblings().removeClass("on");
        $(".num a").eq(n).removeClass("on2").siblings().removeClass("on2");
        $(".num a").eq(n).addClass("on").siblings().addClass("on2");
    })
    $(play).hover(function () { clearInterval(t) }, function () {
        t = setInterval(function () {
            if (st == 1) {
                n = n <= (count - 1) ? --n : 3;
            } else {
                n = n >= (count - 1) ? 0 : ++n;
            }
            $(".num a").eq(n).trigger('click');
        }, 2000);
    });
   
});

function sharelist() {
    if ($("#content_share").is(":hidden")) {
        $("#content_share").show();
    }
    else {
        $("#content_share").hide();
    }
}
function share() {
    $("#content_share").hide();
    alert("分享成功");
}

/******************** information_list ********************/

$(document).on("pageshow", "#information_list", function () {
    $("#information_list").ready(loaded);

    var count = 0;
    function addList() {
        var pageindex = $('#hpageindex').val();
        var pagesize = $("#hpagesize").val();
        var where = $("#where").val();


        if (pageindex == '' || pageindex == '1' || pageindex == null) {
            pageindex = 2;
        }
        if (pagesize == '' || pagesize == null) {
            pagesize = 3;
        }
        $.ajax({
            url: "program/operate.ashx?a=getnewlist",
            data: { pageindex: pageindex, pagesize: pagesize, where: where },
            cache: false,
            error: function () { alert('加载失败'); },
            success: function (result) {
                //  alert(result);
                if (result != '' && result != "1" && result != "2") {


                    setTimeout(function () {
                        var html = "";

                        $("#information_list_ul").append(result);   // prepend
                        $("#information_list_ul").listview('refresh');

                        myScroll.refresh();
                    }, 1000)

                } else if (result == "1") {

                    $("#information_list_addinfo_img_2").hide();
                    information_list_addinfoSpan.text("没有更多数据");
                } else if(result=="2") {
                    $("#information_list_addinfo_img_2").hide();
                    information_list_addinfoSpan.text("加载失败");
                }
            }
        });
        pageindex = Number(pageindex) + 1;
        $('#hpageindex').val(pageindex);
    };

    function refreshList() {
        setTimeout(function () {
            myScroll.refresh();
        }, 1000)
    }

    var myScroll, information_list_addinfo, information_list_addinfoSpan, information_list_refreshinfo, information_list_refreshinfoSpan;
    function loaded() {

        information_list_addinfo = $('#information_list_addinfo');
        information_list_addinfoSpan = $('#information_list_addinfo_span');

        information_list_refreshinfo = $('#information_list_refreshinfo');
        information_list_refreshinfoSpan = $('#information_list_refreshinfo_span');

        myScroll = new iScroll("information_list_out", {
            topOffset: 35,

            onScrollMove: function () {
                if (this.distY > 0 && this.y > 5 && !information_list_refreshinfo.hasClass('flag')) {
                    information_list_refreshinfo.addClass('flag');
                    this.minScrollY = 0;
                } else if (this.distY > 0 && this.y < 5 && information_list_refreshinfo.hasClass('flag')) {
                    information_list_refreshinfo.removeClass('flag');
                    this.minScrollY = 35;
                } else if (this.distY < 0 && this.y < (this.maxScrollY - 5) && !information_list_addinfo.hasClass('flag')) {
                    information_list_addinfo.addClass('flag');
                    this.maxScrollY = this.maxScrollY;
                } else if (this.distY < 0 && this.y > 5 && information_list_addinfo.hasClass('flag')) {
                    information_list_addinfo.removeClass('flag');
                    this.maxScrollY = 0;
                }
            },

            onScrollEnd: function () {
                if (information_list_addinfo.hasClass('flag')) {
                    information_list_addinfoSpan.text("加载中");
                    $("#information_list_addinfo_img_1").hide();
                    $("#information_list_addinfo_img_2").show();
                    addList();
                }
                else if (information_list_refreshinfo.hasClass('flag')) {
                    information_list_refreshinfoSpan.text("刷新中");
                    $("#information_list_refreshinfo_img_1").hide();
                    $("#information_list_refreshinfo_img_2").show();
                    refreshList();
                }
            },

            onRefresh: function () {
                information_list_addinfo.removeClass('flag');
                information_list_addinfoSpan.text("向上拖拽加载更多");
                $("#information_list_addinfo_img_2").hide();
                $("#information_list_addinfo_img_1").show();

                information_list_refreshinfo.removeClass('flag');
                information_list_refreshinfoSpan.text("向下拖拽刷新");
                $("#information_list_refreshinfo_img_2").hide();
                $("#information_list_refreshinfo_img_1").show();
            }
        });
    }
});

/******************** product_list ********************/

function typelist() {
    if ($("#content_type").is(":hidden")) {
        $("#content_type").show();
        $("div[class='content_type_left']").hide();
    }
    else {
        $("#content_type").hide();
        $("img[id^='content_type_right_list_img']").attr({
            "src": "images/product_list_01.png"
        });
        $("span[id^='content_type_right_list_span']").css("color", "#fff");
    }
}

function type_show(cur) {
    $("div[class='content_type_left']").hide();
    $("#content_type_left_" + cur).show();

    $("img[id^='content_type_right_list_img']").attr({     /* ^代表以此开头 $代表以此结尾 */
        "src": "images/product_list_01.png"
    });
    $("#content_type_right_list_img_" + cur).attr({
        "src": "images/product_list_02.png"
    });

    $("span[id^='content_type_right_list_span']").css("color", "#fff");
    $("#content_type_right_list_span_" + cur).css("color", "#00c6ff");     /* 产品列表页 分类选中文本颜色 */
}

function type_choose() {
    $("#content_type").hide();

    $("img[id^='content_type_right_list_img']").attr({
        "src": "images/product_list_01.png"
    });
    $("span[id^='content_type_right_list_span']").css("color", "#fff");
}

$(document).on("pageshow", "#product_list", function () {
    $("#product_list").ready(loaded);

    var count = 0;
    function addList() {


        var pageindex = $('#hpageindex').val();
        var pagesize = $("#hpagesize").val();
        var where = $("#where").val();


        if (pageindex == '' || pageindex == '1' || pageindex == null) {
            pageindex = 2;
        }
        if (pagesize == '' || pagesize == null) {
            pagesize = 3;
        }
        $.ajax({
            url: "program/operate.ashx?a=getproductlist",
            data: { pageindex: pageindex, pagesize: pagesize, where: where },
            cache: false,
            error: function () { alert('加载失败'); },
            success: function (result) {
                //  alert(result);
                if (result != '' && result != "1" && result != "2") {


                    setTimeout(function () {
                        var html = "";

                        $("#product_list_ul").append(result);   // prepend
                        $("#product_list_ul").listview('refresh');

                        myScroll.refresh();
                    }, 1000)

                } else if (result == "1") {

                    $("#product_list_addinfo_img_2").hide();
                    product_list_addinfoSpan.text("没有更多数据");
                } else if (result == "2") {
                    $("#product_list_addinfo_img_2").hide();
                    product_list_addinfoSpan.text("加载失败");
                }
            }
        });
        pageindex = Number(pageindex) + 1;
        $('#hpageindex').val(pageindex);
        //setTimeout(function () {
        //    var html = "";
        //    for (var i = 0; i < 1; i++) {
        //        count++;
        //        $("#product_list_ul").append("<li><a href='product_info.html' data-transition='slide'>新增产品标题</a></li>");   // prepend
        //        $("#product_list_ul").listview('refresh');
        //    }
        //    myScroll.refresh();
        //}, 1000)
    };

    function refreshList() {
        setTimeout(function () {
            myScroll.refresh();
        }, 1000)
    }

    var myScroll, product_list_addinfo, product_list_addinfoSpan, product_list_refreshinfo, product_list_refreshinfoSpan;
    function loaded() {

        product_list_addinfo = $('#product_list_addinfo');
        product_list_addinfoSpan = $('#product_list_addinfo_span');

        product_list_refreshinfo = $('#product_list_refreshinfo');
        product_list_refreshinfoSpan = $('#product_list_refreshinfo_span');

        myScroll = new iScroll("product_list_out", {
            topOffset: 35,

            onBeforeScrollEnd: function () {
               
                if (this.distY > 0 && this.y > 55 && !product_list_refreshinfo.hasClass('flag')) {
                    product_list_refreshinfo.addClass('flag');
                    this.minScrollY = 0;
                } else if (this.distY > 0 && this.y < 55 && product_list_refreshinfo.hasClass('flag')) {
                    product_list_refreshinfo.removeClass('flag');
                    this.minScrollY = 55;
                } else if (this.distY < 0 && this.y < (this.maxScrollY - 55) && !product_list_addinfo.hasClass('flag')) {
                    product_list_addinfo.addClass('flag');
                    this.maxScrollY = this.maxScrollY;
                } else if (this.distY < 0 && this.y > 55 && product_list_addinfo.hasClass('flag')) {
                    product_list_addinfo.removeClass('flag');
                    this.maxScrollY = 0;
                }
            },

            onScrollEnd: function () {
                if (product_list_addinfo.hasClass('flag')) {
                    product_list_addinfoSpan.text("加载中");
                    $("#product_list_addinfo_img_1").hide();
                    $("#product_list_addinfo_img_2").show();
                    addList();
                }
                else if (product_list_refreshinfo.hasClass('flag')) {
                    product_list_refreshinfoSpan.text("刷新中");
                    $("#product_list_refreshinfo_img_1").hide();
                    $("#product_list_refreshinfo_img_2").show();
                    refreshList();
                }
            },

            onRefresh: function () {
                product_list_addinfo.removeClass('flag');
                product_list_addinfoSpan.text("向上拖拽加载更多");
                $("#product_list_addinfo_img_2").hide();
                $("#product_list_addinfo_img_1").show();

                product_list_refreshinfo.removeClass('flag');
                product_list_refreshinfoSpan.text("向下拖拽刷新");
                $("#product_list_refreshinfo_img_2").hide();
                $("#product_list_refreshinfo_img_1").show();
            }
        });
    }
});



/******************** product_list1 ********************/

function typelist() {
    if ($("#content_type").is(":hidden")) {
        $("#content_type").show();
        $("div[class='content_type_left']").hide();
    }
    else {
        $("#content_type").hide();
        $("img[id^='content_type_right_list_img']").attr({
            "src": "images/product_list_01.png"
        });
        $("span[id^='content_type_right_list_span']").css("color", "#fff");
    }
}

function type_show(cur) {
    $("div[class='content_type_left']").hide();
    $("#content_type_left_" + cur).show();

    $("img[id^='content_type_right_list_img']").attr({     /* ^代表以此开头 $代表以此结尾 */
        "src": "images/product_list_01.png"
    });
    $("#content_type_right_list_img_" + cur).attr({
        "src": "images/product_list_02.png"
    });

    $("span[id^='content_type_right_list_span']").css("color", "#fff");
    $("#content_type_right_list_span_" + cur).css("color", "#00c6ff");     /* 产品列表页 分类选中文本颜色 */
}

function type_choose() {
    $("#content_type").hide();

    $("img[id^='content_type_right_list_img']").attr({
        "src": "images/product_list_01.png"
    });
    $("span[id^='content_type_right_list_span']").css("color", "#fff");
}

$(document).on("pageshow", "#product_list1", function () {
    $("#product_list1").ready(loaded);
    var count = 0;
    function addList() {
        var pageindex = $('#hpageindex').val();
        var pagesize = $("#hpagesize").val();
        var where = $("#where").val();

        if (pageindex == '' || pageindex == '1' || pageindex == null) {
            pageindex = 2;
        }
        if (pagesize == '' || pagesize == null) {
            pagesize = 3;
        }
        $.ajax({
            url: "program/operate.ashx?a=getshoplist",
            data: { pageindex: pageindex, pagesize: pagesize, where: where },
            cache: false,
            error: function () { alert('加载失败'); },
            success: function (result) {
                //  alert(result);
                if (result != '' && result != "1" && result != "2") {
                    setTimeout(function () {
                        var html = "";
                        $("#product_list1_ul").append(result);   // prepend
                        $("#product_list1_ul").listview('refresh');
                        myScroll.refresh();
                    }, 1000)

                } else if (result == "1") {
              
                    $("#product_list1_addinfo_img_2").hide();
                    product_list1_addinfoSpan.text("没有更多数据");
                } else if (result == "2") {
                    $("#product_list1_addinfo_img_2").hide();
                    product_list1_addinfoSpan.text("加载失败");
                }
            }
        });
        pageindex = Number(pageindex) + 1;
        $('#hpageindex').val(pageindex);
     
    };

    function refreshList() {
        setTimeout(function () {
            myScroll.refresh();
        }, 1000)
    }

    var myScroll, product_list1_addinfo, product_list1_addinfoSpan, product_list1_refreshinfo, product_list1_refreshinfoSpan;
    function loaded() {

        product_list1_addinfo = $('#product_list1_addinfo');
      
        product_list1_addinfoSpan = $('#product_list1_addinfo_span');

        product_list1_refreshinfo = $('#product_list1_refreshinfo');
        product_list1_refreshinfoSpan = $('#product_list1_refreshinfo_span');

        myScroll = new iScroll("product_list1_out", {
            topOffset: 35,

            onScrollMove: function () {
                if (this.distY > 0 && this.y > 5 && !product_list1_refreshinfo.hasClass('flag')) {
                    product_list1_refreshinfo.addClass('flag');
                    this.minScrollY = 0;
                } else if (this.distY > 0 && this.y < 5 && product_list1_refreshinfo.hasClass('flag')) {
                    product_list1_refreshinfo.removeClass('flag');
                    this.minScrollY = 35;
                } else if (this.distY < 0 && this.y < (this.maxScrollY - 5) && !product_list1_addinfo.hasClass('flag')) {
                    product_list1_addinfo.addClass('flag');
                    this.maxScrollY = this.maxScrollY;
                } else if (this.distY < 0 && this.y > 5 && product_list1_addinfo.hasClass('flag')) {
                    product_list1_addinfo.removeClass('flag');
                    this.maxScrollY = 0;
                }
            },

            onScrollEnd: function () {
                if (product_list1_addinfo.hasClass('flag')) {
                    product_list1_addinfoSpan.text("加载中");
                    $("#product_list1_addinfo_img_1").hide();
                    $("#product_list1_addinfo_img_2").show();
                    addList();
                }
                else if (product_list1_refreshinfo.hasClass('flag')) {
                    product_list1_refreshinfoSpan.text("刷新中");
                    $("#product_list1_refreshinfo_img_1").hide();
                    $("#product_list1_refreshinfo_img_2").show();
                    refreshList();
                }
            },

            onRefresh: function () {
                product_list1_addinfo.removeClass('flag');
                product_list1_addinfoSpan.text("向上拖拽加载更多");
                $("#product_list1_addinfo_img_2").hide();
                $("#product_list1_addinfo_img_1").show();

                product_list1_refreshinfo.removeClass('flag');
                product_list1_refreshinfoSpan.text("向下拖拽刷新");
                $("#product_list1_refreshinfo_img_2").hide();
                $("#product_list1_refreshinfo_img_1").show();
            }
        });
    }
});


