﻿$(document).ready(function () {
//    $("#webmenu").click(function () {
//        $(".web_tool").slideToggle(100);
//    });


    classMarginRight($(".accessories"));
    classMarginRight($(".news"));
    // imgCount();
    //    loadlatest($("#latest .huang"), "#latest_d_");
    //    loadlatest($("#recommend .huang"), "#recommend_d_");
    //    loadlatest($("#accessories .huang"), "#accessories_d_");
    //    loadlatest($("#news .huang"), "#latest_d_");
    window.setTimeout("loadlatest($(\"#latest .huang\"), \"#latest_d_\")", 500);
    window.setTimeout("loadlatest($(\"#recommend .huang\"), \"#recommend_d_\")", 1000);
    window.setTimeout("loadlatest($(\"#accessories .huang\"), \"#accessories_d_\")", 1500);
    window.setTimeout("loadlatest($(\"#news .huang\"), \"#news_d_\")", 2000);
    $("#latest #latest_s_1").click(function () {
        var _psId = $(this).attr("id");
        var count = _psId.lastIndexOf("_");
        _psId = _psId.substr(count + 1);

        $("#latest .chen").css("background", "url(images/huang.gif) no-repeat").css("color", "#eb6100");
        $("#latest .huang").css("background", "url(images/huang.gif) no-repeat").css("color", "#eb6100").css("padding-left", "0px");
        $(this).css("background", "url(images/org.jpg) no-repeat").css("color", "white").css("padding-left", "5px");

        $(".latest_d").css("display", "none");
        $("#latest_d_" + _psId).css("display", "block");


    });
    $("#latest .huang").click(function () {
        var _psId = $(this).attr("id");
        var count = _psId.lastIndexOf("_");
        _psId = _psId.substr(count + 1);

        //        GetIndex($("#latest_d_" + _psId), _psId);

        $("#latest .chen").css("background", "url(images/huang.gif) no-repeat").css("color", "#eb6100");
        $("#latest .huang").css("background", "url(images/huang.gif) no-repeat").css("color", "#eb6100").css("padding-left", "0px");
        $(this).css("background", "url(images/org.jpg) no-repeat").css("color", "white").css("padding-left", "5px");
        $(".latest_d").css("display", "none");
        $("#latest_d_" + _psId).css("display", "block");
        //loadlatest($("#latest .huang"), '#latest_d_');
    });
    $("#recommend .chen").click(function () {
        var _psId = $(this).attr("id");
        var count = _psId.lastIndexOf("_");
        _psId = _psId.substr(count + 1);

        $("#recommend .chen").css("background", "url(images/huang.gif) no-repeat").css("color", "#eb6100");
        $("#recommend .huang").css("background", "url(images/huang.gif) no-repeat").css("color", "#eb6100").css("padding-left", "0px");
        $(this).css("background", "url(images/org.jpg) no-repeat").css("color", "white").css("padding-left", "5px");

        $(".recommend_d").css("display", "none");
        $("#recommend_d_" + _psId).css("display", "block");
    });

    $("#recommend .huang").click(function () {
        var _psId = $(this).attr("id");
        var count = _psId.lastIndexOf("_");
        _psId = _psId.substr(count + 1);

        //GetIndex($("#recommend_d_" + _psId), _psId);

        $("#recommend .chen").css("background", "url(images/huang.gif) no-repeat").css("color", "#eb6100");
        $("#recommend .huang").css("background", "url(images/huang.gif) no-repeat").css("color", "#eb6100").css("padding-left", "0px");
        $(this).css("background", "url(images/org.jpg) no-repeat").css("color", "white").css("padding-left", "5px");
        $(".recommend_d").css("display", "none");
        $("#recommend_d_" + _psId).css("display", "block");
    });
    $("#accessories .chen").click(function () {
        var _psId = $(this).attr("id");
        var count = _psId.lastIndexOf("_");
        _psId = _psId.substr(count + 1);

        $("#accessories .chen").css("background", "url(images/huang.gif) no-repeat").css("color", "#eb6100");
        $("#accessories .huang").css("background", "url(images/huang.gif) no-repeat").css("color", "#eb6100").css("padding-left", "0px");
        $(this).css("background", "url(images/org.jpg) no-repeat").css("color", "white").css("padding-left", "0px");

        $(".tu").css("display", "none");
        $("#accessories_d_" + _psId).css("display", "block");
    });

    $("#accessories .huang").click(function () {
        var _psId = $(this).attr("id");
        var count = _psId.lastIndexOf("_");
        _psId = _psId.substr(count + 1);

        //GetIndex($("#accessories_d_" + _psId), _psId);

        $("#accessories .chen").css("background", "url(images/huang.gif) no-repeat").css("color", "#eb6100");
        $("#accessories .huang").css("background", "url(images/huang.gif) no-repeat").css("color", "#eb6100").css("padding-left", "0px");
        $(this).css("background", "url(images/org.jpg) no-repeat").css("color", "white").css("padding-left", "0px");
        $(".tu").css("display", "none");
        $("#accessories_d_" + _psId).css("display", "block");
    });

    $("#news .chen").click(function () {
        var _psId = $(this).attr("id");
        var count = _psId.lastIndexOf("_");
        _psId = _psId.substr(count + 1);

        $("#news .chen").css("background", "url(images/huang.gif) no-repeat").css("color", "#eb6100");
        $("#news .huang").css("background", "url(images/huang.gif) no-repeat").css("color", "#eb6100").css("padding-left", "0px");
        $(this).css("background", "url(images/org.jpg) no-repeat").css("color", "white").css("padding-left", "5px");

        $(".video").css("display", "none");
        $("#news_d_" + _psId).css("display", "block");
    });

    $("#news .huang").click(function () {
        var _psId = $(this).attr("id");
        var count = _psId.lastIndexOf("_");
        _psId = _psId.substr(count + 1);

        //GetIndex($("#news_d_" + _psId), _psId);

        $("#news .chen").css("background", "url(images/huang.gif) no-repeat").css("color", "#eb6100");
        $("#news .huang").css("background", "url(images/huang.gif) no-repeat").css("color", "#eb6100").css("padding-left", "0px");
        $(this).css("background", "url(images/org.jpg) no-repeat").css("color", "white").css("padding-left", "5px");
        $(".video").css("display", "none");
        $("#news_d_" + _psId).css("display", "block");
    });


});

function imgCount() {
    var imgcount = $("#change_3 a").size();
    var data = "<ul class=\"ul_change_a2\">";
    for (var i = 0; i < imgcount; i++) {
        data += "<li><span></span></li>";
    }
    data += "</ul>";
    $("#change_3").append(data);
}


function classMarginRight(classInfo) {
    for (var i = 0; i < classInfo.size(); i++) {
        if ((i + 1) % 5 == 0) {
            classInfo[i].style.marginRight = "1px";
        }
    }
}

function GetIndex(divDoc, _psId) {
    if (divDoc.html() == "") {
        $.ajax({
            type: "POST",
            url: "theme/ashx/index.ashx",
            data: "psId=" + _psId,
            dataType: "html",
            error: function () {
                alert("ajax载入失败index1");
            },
            success: function (data) {
                //alert(data);
                divDoc.append(data);
                classMarginRight($(".accessories"));
                classMarginRight($(".news"));
            }
        });
    }
}

function GetIndexs(divDoc1, divDoc2, othis, _psId) {
    if ($("#" + divDoc1 + "_d_" + _psId).html() == "") {
        $.ajax({
            type: "POST",
            url: "theme/ashx/index.ashx",
            data: "psId=" + _psId,
            dataType: "html",
            error: function () {
                alert("ajax载入失败index2");
            },
            success: function (data) {
                //divDoc.append(data);
		divDoc.html(data);
                classMarginRight($(".accessories"));
                classMarginRight($(".news"));
            }
        });
    }
}
function loadlatest(list,name) {
    for (var i = 0; i < list.size(); i++) {
        var _psId = $(list[i]).attr("id");
        var count = _psId.lastIndexOf("_");
        _psId = _psId.substr(count + 1);
        //window.setTimeout("GetIndex($(name + _psId), _psId)", 500 * (i + 1));
        GetIndex($(name + _psId), _psId);
    }
}



