
$(function() {
  $("#content").snowfall({
  image: [
    "images/realLeaf1.png",
    "images/realLeaf2.png",
    "images/realLeaf3.png",
    "images/realLeaf3.png",
    "images/realLeaf4.png",
    "images/realLeaf2.png",
    "images/realLeaf3.png"
  ],
  flakeCount:10,
  minSize: 40,
  maxSize: 70,
  minSpeed:1,
  maxSpeed:4
});
  //角色轮播
  $(".roleBanner").slide({
    mainCell: ".bd ul",
    effect: "left",
    autoPage: true,
    //delayTime:500,
    vis: 5,
    scroll: 1,
    pnLoop: true,
    trigger: "click",
    autoPlay: true,
    easing: "easeOutCubic"
  });

  Carousel.init($(".J_Poster"));

  var showNews = document.getElementById("section1");
  var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
  var clientHeight = window.innerHeight || 　document.body.clientHeight;
  $(window).resize(function() {
    if ($(window).height() < 600) {
      //$('#sider').css('left',-$newWidth);
      $(".ceBox").css({
        "top": "0",
        "marginTop": "0"
      })
      //resizeNav();
      //$('#sider').css('transform','scale('+wh/975+')');
    }
    if ($(window).width() < 1400) {
      $(".popRole,.popRole .popbg").css({
        "width": $(window).width()
      })
    } else {
      $(".popRole,.popRole .popbg").css({
        "width": "100%"
      })
    }
    if ($(window).height() < 600) {
      $(".popRole,.popRole .popbg").css({
        "height": $(window).height()
      })
    } else {
      $(".popRole,.popRole .popbg").css({
        "height": "100%"
      })
    }
    scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
    //获得浏览器的可视高度
    clientHeight = window.innerHeight || 　document.body.clientHeight;
    //console.log(getTop(showNews)+"==="+(scrollTop + clientHeight));

    if ($(window).height() <= 870 && getTop(showNews) >= (scrollTop + clientHeight)) {
      $(".topItem").addClass("fixed");
    } else {
      $(".topItem").removeClass("fixed");
    }

  })

  //console.log($(window).height());
  if ($(window).height() <= 870) {
    $(".topItem").addClass("fixed");
  } else {
    $(".topItem").removeClass("fixed");
  }
  $(window).scroll(function() {
    showImg();
  });

  function showImg() {
    //获得滚动条的高度
    scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
    //获得浏览器的可视高度
    clientHeight = window.innerHeight || 　document.body.clientHeight;
    if (getTop(showNews) <= (scrollTop + clientHeight) && $(window).height() <= 870) {
      $(".topItem").removeClass("fixed");
    } else if (getTop(showNews) > (scrollTop + clientHeight) && $(window).height() <= 870) {
      $(".topItem").addClass("fixed");
    }
  }

  //获得图片相对于浏览器顶部的高度  兼容浮动布局和定位布局
  function getTop(obj) {
    var iTop = 0;
    while (obj) {
      iTop += obj.offsetTop;
      obj = obj.offsetParent;
    }
    return iTop;
  }

  //轮播
  var index = 0,
    len = $('.roleList li').size();
  var mark = false; //锁
  //var $height;
  //初始化ul的宽度
  //$(".banner ul").css({"width":len*1315+"px"});
  //console.log(len);
  $('.roleList li a').each(function(i) {
    $(this).click(function() {
      var _top = $("#p3").offset().top;
      $(".popRole").css({
        "top": _top
      });
      $(".popRole").stop(true).fadeIn();
      $("body,html").css({
        "overflow": "hidden"
      });

      $(".popRole ul li").hide().eq(i).show();
      $(".popRole ul li .per").css({
        "left": "-90px",
        "opacity": "0"
      });
      $(".popRole ul li .ptext").css({
        "right": "-15px",
        "opacity": "0"
      });
      $(".popRole ul li .per").eq(i).animate({
        "left": "-60",
        "opacity": "1"
      });
      $(".popRole ul li .ptext").eq(i).animate({
        "right": "15px",
        "opacity": "1"
      });
      if (mark) {
        //console.log("1")
        //$('.popRole ul').stop(true).animate({'left':-(i*1315)});
      } else {
        //console.log("2")
        //$('.popRole ul').css({'left':-(i*1315)});
      }
      $("html, body").animate({
        scrollTop: _top + "px"
      })
      index = i;
    });
  });
  $("#popRole span.closeBar").click(function() {
    $("#popRole").stop(true).fadeOut();
    $("body,html").css({
      "overflow": "auto"
    });
  });
  $('.popRole .prev').click(function() {
    startMove("left");
  })
  $('.popRole .next').click(function() {
    startMove("right");
  })
  //左右翻页
  function startMove(target) {
    mark = true;
    if (target == "left") {
      index--;
      if (index < 0) {
        index = len - 1;
      }
    } else if (target == "right") {
      index++;
      if (index > len - 1) {
        index = 0;
      }
    }
    $('.roleList li a').eq(index).click();
  }

  var playid = 0;
  $('#music_player').jPlayer({
    swfPath: "http://zhuxian.wanmei.com/js/jplayer",
    wmode: "window",
    supplied: "mp3",
    ended: function() {
      setStopCss();
    }
  });

  function setStopCss() {
    $('.vBtns a').attr('class', 'play_off');
  }

  function stopM() {
    $("#music_player").jPlayer('pause');
    setStopCss();
  }





  $('[action=Play]').each(function(index, elem) {
    var url = $(elem).attr('mp3');
    $(this).click(function() {
      //console.log(index);
      //console.log(playid);
      if (index != playid) {
        setStopCss();
      }
      if (this.className == 'play_off') {
        $('#music_player').jPlayer("setMedia", {
          mp3: url
        });
        $('#music_player').jPlayer('play');
        //console.log("进来了")
        this.className = 'play_on';
      } else {
        $("#music_player").jPlayer('pause');
        this.className = 'play_off';
      }
      playid = index;
    });
  });

});