﻿$(document).ready(function () {
    if ($("#hidBigID").val() == 15) {
        $("[name='typetabs-15']").attr("class", "pon1");
        $("[name='typetabs-16']").attr("class", "");
        $(".teimg_tenav").attr("id", "imgbj_tsa");
    } else {
        $("[name='typetabs-15']").attr("class", "");
        $("[name='typetabs-16']").attr("class", "pon1");
        $(".teimg_tenav").attr("id", "imgbj_ts");
    }
    $("#ranknav-tabs-list li").click(function () {
        for (var c = 1; c < 4; c++) {
            var currentTab = "ranktabs-" + c;
            if (currentTab == $(this).attr("name")) {
                $("[name='ranktabs-" + c + "']").attr("class", "ons");
                $("#hidType").val(c);
                App.GetAppList(App.GetSearchParApp());
            } else {
                $("[name='ranktabs-" + c + "']").attr("class", "");
            }
        }
    });
    $("#typenav-tabs-list p").click(function () {
        for (var c = 15; c < 17; c++) {
            var currentTab = "typetabs-" + c;
            if (currentTab == $(this).attr("name")) {
                if (c == 15) {
                    $(".teimg_tenav").attr("id", "imgbj_tsa");
                } else {
                    $(".teimg_tenav").attr("id", "imgbj_ts");
                }
                $("[name='typetabs-" + c + "']").attr("class", "pon1");
                $("#hidBigID").val(c);
                App.GetAppList(App.GetSearchParApp());
            } else {
                $("[name='typetabs-" + c + "']").attr("class", "");
            }
        }
    });
    $("#nav-tabs-list li").click(function () {
        for (var c = 1; c < 4; c++) {
            var currentTab = "tabs-" + c;
            if (currentTab == $(this).attr("name")) {
                $("#controlNumber").attr("class", "");
                $("#hidPageIndex").val("1");
                if (c == 1) {
                    $("#controlNumber").addClass("teimg_tenav_img");
                    $("#hidPageSize").val("28");
                 

                }
                else if (c == 2) {
                    $("#controlNumber").addClass("teimg_tenav_imga");
                    $("#hidPageSize").val("21");
                  
                }
                else if (c == 3) {
                    $("#controlNumber").addClass("teimg_tenav_imgb");
                    $("#hidPageSize").val("14");
                    
                }
                $("[name='tabs-" + c + "']").attr("class", "ons");
                App.GetAppList(App.GetSearchParApp());
            } else {
                $("[name='tabs-" + c + "']").attr("class", "");
            }
        }
    });
    //var urlPar="/app-category-"+$("#hidBigID").val()+"-"+$("#hidSmallID").val()+"-"+$("#hidType").val()+"-ajax";
    var urlPar = "/Template/index.aspx?Write=True&Ronds=" + Math.random() + "&bigid=" + $("#hidBigID").val() + "&type=" + $("#hidType").val() + "&a=ajax";
    App.GetAppList(urlPar);
});
        var App = {
            GetAppList: function (urlPar) {
                var xmlHttpReq1 = null;
                if (window.XMLHttpRequest) {
                    xmlHttpReq1 = new XMLHttpRequest();
                } else if (window.ActiveXObject) {
                    xmlHttpReq1 = new ActiveXObject("Microsoft.XMLHTTP");
                }
                if (xmlHttpReq1 != null) {
                    xmlHttpReq1.open("get", urlPar, true);
                    xmlHttpReq1.onreadystatechange = RequestCallBack;
                    xmlHttpReq1.send(null);
                }

                function RequestCallBack() {
                    if (xmlHttpReq1.readyState == 4) {
                        var livalues = new Array();
                        livalues = xmlHttpReq1.responseText.split('√√');
                        var pageindex = parseInt($("#hidPageIndex").val());
                        $("#applist").html(livalues[0]);
                        $("#pageList").html(livalues[1]);

                        var height = 0;
                        if (pageindex > 1) {
                            pageSum = Math.ceil(parseInt(livalues[2]) / $("#hidPageSize").val());
                            if (pageSum >= 3) {
                                height = 310/(pageSum - 1)*(pageindex-1);
                            } else {
                                height = 310 / pageSum * 2;
                            }
                            
                            $("#lunimg").attr("style", "margin-top:" + height + "px;");
                        }
                        else { $("#lunimg").attr("style", "margin-top:0px;"); }
                    }
                }

            },
            GetWonderApp: function () {
                $("#hidBigID").val("0");
                $("#hidSmallID").val("0");
                $("#hidType").val("1");
                App.GetAppList(App.GetSearchParApp());
            },
            GetSearchParApp: function () {
                return "/Template/index.aspx?Write=True&Ronds=" + Math.random() + "&bigid=" + $("#hidBigID").val() +"&type=" + $("#hidType").val() + "&pagesize=" + $("#hidPageSize").val() + "&a=ajax";
            }
        }

        function redirection(page) {
            var urlPar = App.GetSearchParApp();
            urlPar += "&page=" + page;
            $("#hidPageIndex").val(page);
            App.GetAppList(urlPar);
        }

