/// <reference path="jquery-1.4.2-vsdoc.js" />

/*Tab面板切换，第一种形式 第二种形式 更换显示样式*/
function setTab(name, cursel, n) {
    for (i = 1; i <= n; i++) {
        var menu = document.getElementById(name + i);
        var con = document.getElementById("con_" + name + "_" + i);
        menu.className = i == cursel ? "hover" : "";
        con.style.display = i == cursel ? "block" : "none";
    }
}





$(function() {



    // 头部搜索栏文本变化
    var defaultText = "输入品牌或商品关键字进行查找";
	var _text="搜索资讯";
    $("#search_input").focus(function() {
        if ($(this).val() == defaultText) {
            $(this).val("");
        }
        $(this).css("color", "#363636");

    });

    $("#search_input").blur(function() {
        if ($(this).val().length == 0) {
            $(this).val(defaultText);
        }
        $(this).css("color", "#DAD7D7");
    });


 $("#search_input_text").focus(function() {
        if ($(this).val() == _text) {
            $(this).val("");
        }
        $(this).css("color", "#363636");

    });

    $("#search_input_text").blur(function() {
         if ($.trim($(this).val()).length == 0) {
            $(this).val(_text);
        }
        $(this).css("color", "#DAD7D7");
    });

    // 购物车浮动层
    $("#shopcar").mouseover(function() {
        $(this).css("overflow", "visible");
        $(".mycart_float").fadeIn("slow");
    });

    $("#shopcar").mouseleave(function() {
        $(".mycart_float").fadeOut("normal");
    });

    // 导航栏浮动层
    $(".act_li").mouseover(function() {
        $(this).children(".navfloat").show();
        $(this).css("background", "#fff");
        $(this).children(".nav_a").addClass("actnav_a");
    });

    $(".act_li").mouseleave(function() {
        $(this).children(".navfloat").hide();
        $(this).css("background", "none");
        $(this).children(".nav_a").removeClass("actnav_a");
    });

	// 首页顶部广告关闭按钮
	$("#close_topad").click(function(){
		$(this).parent(".topfirstad").remove();
	});

    // 首页顶部公告关闭按钮
    $("#top-notice-close").click(function() {
        $(this).parent("#top-notice").remove();
    });	

    // 友情链接显示隐藏
    $("#morelink").mouseover(function() {
        $(this).css("overflow", "visible").css("height", "auto");
    });

    $("#morelink").mouseleave(function() {
        $(this).css("overflow", "hidden").css("height", "20px");
    })


    //首页及商品列表页-商品标签浮动层
    $(".proico").mouseover(function() {
        $(this).children("p").fadeIn("normal");

    });

    $(".proico").mouseleave(function() {
        $(this).children("p").fadeOut("normal");

    });


    // 商品列表页-商品背景
    $(".prolist_main").mouseover(function() {
        $(this).addClass("prolist_m2");
    });

    $(".prolist_main").mouseleave(function() {
        $(this).removeClass("prolist_m2");
    });

    // 商品详细页套餐overflow-x:scroll
    var length = $("#scollul>li").length * 150 + "px";
    $("#scollul").css("width", length);

    // 商品详细页运费计算浮动层
    $("#freightli").click(function() {
        var freightEm = $(this).children("em")
        var freightEmText = freightEm.html();
        if (freightEmText == "运费计算") {
            $("#freightWrap").slideDown("fast");
            freightEm.html("关闭计算");
        }
        else if (freightEmText == "关闭计算") {
            $("#freightWrap").slideUp("fast");
            freightEm.html("运费计算");
        }

    });
    $("#closeCal").click(function() {
        $("#freightWrap").slideUp("fast");
        $("#freightli").children("em").html("运费计算");
    });

    //商品详细页自提点浮动层
    $("#zitili").mouseover(function() {
        $(".zitiWrap").show();
    });

    $("#zitili").mouseleave(function() {
        $(".zitiWrap").hide();
    });


    //商品内页评论弹出层
    $(".plbtn").click(function() {
        var proComBox = $("#proComBox");
        if ($(this).html() == "我要评论") {
            proComBox.fadeIn("fast").css("top", "80px").css("bottom", "");
            proComBox.parent(".commbox").css("z-index", "10");


            //评分星星鼠标移动上去发生改变
            var strArr = new Array();
            strArr[0] = "很不喜欢";
            strArr[1] = "不喜欢";
            strArr[2] = "一般";
            strArr[3] = "喜欢";
            strArr[4] = "很喜欢";
            $("a[name=starPoint]").mouseover(function() {
                var point = $(this).attr("point");
                $("a[name=starPoint]").attr("class", "star");
                $(this).nextAll().attr("class", "s_1");
                $("#pointTxt").html(strArr[point - 1]);
                $("#hiCommentLevel").val(point);
            });

            $(this).html("取消评论");
        }
        else if ($(this).html() == "取消评论") {
            proComBox.fadeOut("fast");
            proComBox.parent(".commbox").css("z-index", "0");
            $(this).html("我要评论");
        }

    });

    $("#closepl").click(function() {
        $("#proComBox").fadeOut("fast");
        $(".plbtn").html("我要评论");
    });

    $(".plbtn2").click(function() {
        $("#proComBox").css("top", "").css("bottom", "40px");

    });

    // 计算文本框字数，comtext为文本框控件，numb为显示可输入字数控件id
    function CountComTxtNum(comtext, numb) {
        var textLength = $.trim($("#" + comtext).val()).length;
        $("#" + numb).html(1000 - textLength);
        if ($("#" + numb).html() < 0) {
            $("#" + numb).css("color", "#ff0000");
        }
        else {
            $("#" + numb).css("color", "#808080");
        }
    }

    //评论字数
    $("#txtcontent").keydown(function() {
        CountComTxtNum('txtcontent', 'comTextNum');
    })
    .keyup(function() { CountComTxtNum('txtcontent', 'comTextNum') })
    .focus(function() { CountComTxtNum('txtcontent', 'comTextNum') });

    // 咨询字数
    $("#txtConsultingContent").keydown(function() {
        CountComTxtNum('txtConsultingContent', 'zxTextNum');
    })
    .keyup(function() { CountComTxtNum('txtConsultingContent', 'zxTextNum') })
    .focus(function() { CountComTxtNum('txtConsultingContent', 'zxTextNum') });



    //商品内页咨询弹出层
    $(".zxbtn").click(function() {
        var proComBox = $("#proZixunBox");
        if ($(this).html() == "我要咨询") {
            proComBox.fadeIn("fast").css("top", "80px").css("bottom", "");
            $(this).html("取消咨询");
        }
        else if ($(this).html() == "取消咨询") {
            proComBox.fadeOut("fast");
            $(this).html("我要咨询");
        }

    });

    $("#closezx").click(function() {
        $("#proZixunBox").fadeOut("fast");
        $(".zxbtn").html("我要咨询");
    });

    $(".zxbtn2").click(function() {
        $("#proZixunBox").css("top", "").css("bottom", "40px");

    });

    // 限时抢购-商品边框
    $(".limitpro").mouseover(function() {
        $(this).addClass("limitpro_act");
    });

    $(".limitpro").mouseleave(function() {
        $(this).removeClass("limitpro_act");
    });



    //回到顶部按钮操作事件 
    var show_delay;
    var scroll_div_left = parseInt((document.body.offsetWidth - 1000) / 2) + 1000;
    $(".scroll_div").click(function() {
        document.documentElement.scrollTop = 0;
        document.body.scrollTop = 0;
    });
    $(window).resize(function() {
        //scroll_div_left = parseInt((document.body.offsetWidth - 1000) / 2) + 1000;
        //$(".scroll_div").css("left", scroll_div_left);
    });
    reshow(scroll_div_left, show_delay);



}); //jquery_ready_end








/* 回到页面顶部按钮显示 */
function reshow(marign_l, show_d) {
    //$(".scroll_div").css("left", marign_l);
    if ((document.documentElement.scrollTop + document.body.scrollTop) != 0) {
        $(".scroll_div").css("display", "block");
    }
    else {
        $(".scroll_div").css("display", "none");
    }
    if (show_d) window.clearTimeout(show_d);
    show_d = setTimeout("reshow()", 500);

}

