﻿//jQuery.noConflict();
//jQuery(document).ready(function($){
$(document).ready(function() {
    ///二级菜单
    $(".c1_title").mouseover(function() {
        $(this).children(".c2_title").show();
        $(this).children("a.c1").addClass("c1_over");
    })
    $(".c1_title").mouseout(function() {
        $(this).children(".c2_title").hide();
        $(this).children("a.c1").removeClass("c1_over");
    })
    $(".nav_btn01").mouseover(function() {
        $(this).children(".brand_all").show();
        $(this).children("a.link").addClass("link_over");
    })
    $(".nav_btn01").mouseout(function() {
        $(this).children(".brand_all").hide();
        $(this).children("a.link").removeClass("link_over");
    })

    ///团购倒计时显示
    $("dl.group_buy li.btn").mouseover(function() {
        $(this).siblings("li.time").show();
    })
    $("dl.group_buy li.btn").mouseout(function() {
        $(this).siblings("li.time").hide();
    })

    ///推荐专区切换
    $("div.hot").mouseover(function() {
        $("div.recommend").addClass("recommend_hot");
        $("div.recommend").removeClass("recommend_new");
    })
    $("div.new").mouseover(function() {
        $("div.recommend").addClass("recommend_new");
        $("div.recommend").removeClass("recommend_hot");
    })

    $(".hot_des li").mouseover(function() {
        var num = $(".hot_des li").index(this);
        $("ul.hot_pic li").hide();
        $("ul.hot_pic li").eq(num).show();
        $(".hot_des li").removeClass("curr");
        $(".hot_des li").eq(num).addClass("curr");
    })


    //本月新品上架图片左右切换
    var img_total2 = $(".goods_roll #hot_images2 span.item").size();
    var roll_total2 = Math.floor((img_total2 - 1) / 4) + 1;
    var hot_step2 = 304; //一屏即#hot_imgStage的宽度
    //var hot_width_total = img_total2*hot_step2;
    var now_index2 = 0;
    $(".goods_roll #hot_images2 span.item img").eq(0).addClass("curr");
    $("a.prev2").addClass("overP");
    if (img_total2 <= 4) {
        $("a.next2").addClass("overN");
    }

    $("a.prev2").click(function() {
        if (now_index2 > 0) {
            now_index2--;
            hot_slide2(now_index2);
            if (now_index2 == 0) {
                $("a.prev2").addClass("overP");
            } else {
                $("a.prev2").removeClass("overP");
            }
            $("a.next2").removeClass("overN");
        }
    });
    $("a.next2").click(function() {
        if (now_index2 < roll_total2 - 1) {
            now_index2++;
            hot_slide2(now_index2);
            if (now_index2 == roll_total2 - 1) {
                $("a.next2").addClass("overN");
            } else {
                $("a.next2").removeClass("overN");
            }
            $("a.prev2").removeClass("overP");
        }
    });

    function hot_slide2(now_index2) {
        $("#hot_images2").animate({ left: -now_index2 * hot_step2 + "px" });
    }


    //本月新品上架小图展示大图
    $(".goods_roll #hot_images2 span.item").mouseover(function() {
        var pic_total = $(".goods_roll #hot_images2 span.item").size();
        var pic_index = $(".goods_roll #hot_images2 span.item").index($(this));
        for (i = 0; i < pic_total; i++) {
            var temp = $("ul#picL_list li").eq(i).attr("id");
            if (temp == "picL" + pic_index) {
                $("ul#picL_list li").eq(i).show();
            } else {
                $("ul#picL_list li").eq(i).hide();
            }
        }
        $(".goods_roll #hot_images2 span.item img").removeClass("curr");
        $(this).children("img").addClass("curr");
    })


    ///新闻中心切换
    $(".news_tab li").mouseover(function() {
        var num = $(".news_tab li").index(this);
        $("div.news_cont").hide();
        $("div.news_cont").eq(num).show();
        $(".news_tab li a").removeClass("curr");
        $(".news_tab li a").eq(num).addClass("curr");
    })


    ///品牌专区套餐
    $("div.brand_show div.sale ul.item").mouseover(function() {
        $(this).children("li.btn").show();
    })
    $("div.brand_show div.sale ul.item").mouseout(function() {
        $(this).children("li.btn").hide();
    })


    ///品牌专区动态切换
    if ($("div.brand_show1 ul.active li.cont").size() != 0) {
        $("div.brand_show1 ul.active li.cont").eq(0).addClass("curr");
    }
    if ($("div.brand_show2 ul.active li.cont").size() != 0) {
        $("div.brand_show2 ul.active li.cont").eq(0).addClass("curr");
    }
    $("div.brand_show ul.active li.cont").mouseover(function() {
        $(this).parents("ul.active").children("li.cont").removeClass("curr");
        $(this).addClass("curr");
    })

    ///品牌专区商品切换
    /**$("div.brand_show h3.tab a").mouseover(function() {
    var num = $(this).parents("h3.tab").children("a").index(this); ///此处容易出错，要找出父对象定位
    $(this).parents("h3.tab").children("a").removeClass("curr");
    $(this).addClass("curr");
    $(this).parents("div.brand_show").children("div.goods").hide();
    $(this).parents("div.brand_show").children("div.goods").eq(num).show();
    })**/


    ///商品滑过显示5条最新评论 罗技
    $(".brand_show1 div.goods li.pic").mouseover(function() {
        var productId = $(this).attr("id");
        //$(this).find("div.com_box").html("");
        $.get("../AjaxService/BrandShowOneAjax.aspx?str=" + (new Date().getUTCMilliseconds()) + "", { productID: "" + productId + "" }, function(data) {
            $("div.com_box").html(data);
        });
        var x_position = $(this).offset().left;
        var y_position = $(this).offset().top;
        $("div.com_box").css("left", x_position + 160);
        $("div.com_box").css("top", y_position);
        $("div.com_box").show();
    })
    $(".brand_show1 div.goods li.pic").mouseout(function() {
        $("div.com_box").hide();
    })


    ///商品滑过显示5条最新评论 美加狮 
    $(".brand_show2 div.goods li.pic").mouseover(function() {
        var productId = $(this).attr("id");
        //$(this).find("div.com_box").html("");
        $.get("../AjaxService/BrandShowOneAjax.aspx?str=" + (new Date().getUTCMilliseconds()) + "", { productID: "" + productId + "" }, function(data) {
            $("div.com_box").html(data);
        });
        var x_position = $(this).offset().left;
        var y_position = $(this).offset().top;
        $("div.com_box").css("left", x_position + 160);
        $("div.com_box").css("top", y_position);
        $("div.com_box").show();
    })
    $(".brand_show2 div.goods li.pic").mouseout(function() {
        $("div.com_box").hide();
    })




    ///热销排行 商品划过 销量重点显示
    $(".ranking li.pic").mouseover(function() {
        $(this).siblings("li.total").children("b").addClass("over");
    })
    $(".ranking li.pic").mouseout(function() {
        $(this).siblings("li.total").children("b").removeClass("over");
    })



    ///晒单狂人手风琴
    if ($(".test3").size() != 0) {
        $(".test3").hrzAccordion({
            openOnLoad: "2",
            handlePosition: "left",
            containerClass: "container3",
            listItemClass: "listItem3",
            contentWrapper: "contentWrapper3",
            contentInnerWrapper: "contentInnerWrapper3",
            handleClass: "handle3",
            handleClassOver: "handleOver3",
            handleClassSelected: "handleSelected3",
            fixedWidth: "749" /**实际为750 但在火狐下移动时 最后一个handle3不稳定**/
        });
    }


    ///晒单狂人组图
    $(".tribeShow_tbl td").mouseover(function() {
        $(this).find("img.off").hide();
        $(this).find("img.on").show();
    })
    $(".tribeShow_tbl td").mouseout(function() {
        $(this).find("img.off").show();
        $(this).find("img.on").hide();
    })








    ///右侧条幅
    /** the list of posts**/
    var $list = $('#rp_list ul');
    /**number of related posts**/
    var elems_cnt = $list.children().length;

    /**
    * show the first set of posts.
    * 200 is the initial left margin for the list elements
    */
    load(200);


    function load(initial) {
        $list.find('li').hide().andSelf().find('div').css('margin-left', -initial + 'px');
        var loaded = 0;
        //show 5 random posts from all the ones in the list. 
        //Make sure not to repeat
        while (loaded < 5) {
            var r = Math.floor(Math.random() * elems_cnt);
            var $elem = $list.find('li:nth-child(' + (r + 1) + ')');
            if ($elem.is(':visible'))
                continue;
            else
                $elem.show();
            ++loaded;
        }
        //animate them
        var d = 200;
        $list.find('li:visible div').each(function() {
            $(this).stop().animate({
                'marginLeft': '-50px'
            }, d += 100);
        })
    }


    /**
    * hovering over the list elements makes them slide out
    */
    $list.find('li:visible').mouseover(function() {
        //$(this).find('div').addClass("curr");
        $(this).find('div').stop().animate({
            'marginLeft': '-212px'
        }, 200);
    }).mouseout(function() {
        //$(this).find('div').removeClass("curr");
        $(this).find('div').stop().animate({
            'marginLeft': '-50px'
        }, 200);
    })



    ///右侧条幅Ie6
    $(".rp_list_ie6 li").mouseover(function() {
        $(this).children("div.rp_links").show();
    })
    $(".rp_list_ie6 li").mouseout(function() {
        $(this).children("div.rp_links").hide();
    })


    //团购提前结束
    if ($("div.groupNowItem").size() != 0) {
        var NowItemNum = $("div.groupNowItem").size();
        if (NowItemNum != undefined) {
            for (i = 0; i < NowItemNum; i++) {
                if ($("div.groupNowItem").eq(i).find("b.goodsLeft").html() == "0") {
                    $("div.groupNowItem").eq(i).find("ul.tit li.left").addClass("leftOverToday");
                    $("div.groupNowItem").eq(i).find("ul.info li.left h3").html("今日遭遇疯抢，团购提前结束！");
                    $("div.groupNowItem").eq(i).find("ul.info li.right h2 a").addClass("btnOverToday");
                }
            }
        }
    }


    //团购图片小图显示大图
    $("div.groupPic ul.picSmall li").mouseover(function() {
        var num = $("div.groupPic ul.picSmall li").index($(this));
        $("div.groupPic ul.picBig li").hide();
        $("div.groupPic ul.picBig li").eq(num).show();
        $("div.groupPic ul.picSmall li").removeClass("curr");
        $(this).addClass("curr");
    })


    //团购某块tips显示
    $("ul.groupItem li.btn a").mouseover(function() {
        $(this).siblings("div.tips").fadeIn(600);
    })
    $("ul.groupItem li.btn a").mouseout(function() {
        $(this).siblings("div.tips").fadeOut(400);
    })


    //有谁参团了 信息滚动
    //查找calss为.groupJoin下面是否有calss为itemRow的div,如果有calss为itemRow超过3个才执行滚动
    var scrtime;
    var findItem = $("div.groupJoin>div.itemRow");
    if (findItem.lenth > 3) {
        $(".groupJoin_box").hover(function() {
            clearInterval(scrtime);
        }, function() {
            scrtime = setInterval(function() {
                var $ul = $(".groupJoin_box .groupJoin");
                var liHeight = $ul.find(".itemRow:last").height();

                $ul.animate({ marginTop: liHeight + "px" }, 500, function() {
                    $ul.find(".itemRow:last").prependTo($ul);
                    $ul.find(".itemRow:first").hide();
                    $ul.css({ marginTop: 0 });
                    $ul.find(".itemRow:first").fadeIn(500);
                });
            }, 5000);
        }).trigger("mouseleave");
    }

    //右侧今日团购 销量重点显示
    $("dl.groupNow ul.item").mouseover(function() {
        $(this).children("li.info").children("b").addClass("over");
    })
    $("dl.groupNow ul.item").mouseout(function() {
        $(this).children("li.info").children("b").removeClass("over");
    })

    //右侧即将开团 背景变色
    $("dl.groupSoon ul.item").mouseover(function() {
        $(this).addClass("over");
    })
    $("dl.groupSoon ul.item").mouseout(function() {
        $(this).removeClass("over");
    })

    //右侧 晒单评价滚动更新
    var scrtime2;
    var groupList = $(".groupShow .showBox .showBox2").find("ul.item").innerTHML;
    if (groupList != undefined) {
        $(".groupShow .showBox").hover(function() {
            clearInterval(scrtime2);
        }, function() {
            scrtime2 = setInterval(function() {
                var $ul = $(".groupShow .showBox .showBox2");
                var liHeight = $ul.find("ul.item:last").height();
                $ul.animate({ marginTop: liHeight + "px" }, 500, function() {
                    $ul.find("ul.item:last").prependTo($ul);
                    $ul.find("ul.item:first").hide();
                    $ul.css({ marginTop: 0 });
                    $ul.find("ul.item:first").fadeIn(500);
                });
            }, 5000);
        }).trigger("mouseleave");
    }
    //团购晒单列表排序切换
    if ($("div.groupShowList span.icon").size() != 0) {
        $("div.groupShowList span.icon").eq(0).addClass("iconNow");
        $("div.groupShowList span.icon").click(function() {
            $("div.groupShowList span.icon").removeClass("iconNow");
            $(this).addClass("iconNow");
        })
    }

    ///团购晒单中心-团购倒计时显示
    $("div.groupShowItem ul.itemGoods div.btn").mouseover(function() {
        $(this).find("span.time").show();
    })
    $("div.groupShowItem ul.itemGoods div.btn").mouseout(function() {
        $(this).find("span.time").hide();
    })











})
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	


