function goTop(){
  $(window).scroll(function(e) {
    if($(window).scrollTop()>100)
      $(".gotop").fadeIn(350).css("display","block");
    else
      $(".gotop").fadeOut(350).css("display","none");
  });
    
  $(".gotop").click(function(e) {
    $('body,html').animate({scrollTop:0},500);
    return false;
  });   
};

jQuery.faqfold = function(obj,obj_c,speed,obj_type,Event){
  if(obj_type == 2){
    $(obj+":first").find("b").html("-");
    $(obj_c+":first").show()}
  $(obj).bind(Event,function(){
    if($(this).next().is(":visible")){
      if(obj_type == 2){
        return false}
      else{
        $(this).next().slideUp(speed).end().removeClass("selected");
        $(this).find("b").html("+")}
    }
    else{
      if(obj_type == 3){
        $(this).next().slideDown(speed).end().addClass("selected");
        $(this).find("b").html("-")}else{
        $(obj_c).slideUp(speed);
        $(obj).removeClass("selected");
        $(obj).find("b").html("+");
        $(this).next().slideDown(speed).end().addClass("selected");
        $(this).find("b").html("-")}
    }
  })
}


getProductUrl = function(a) {
  var d = a,
  e = a.split("."),
  f = ["jpg", "jpeg", "gif", "png"],
  g = e.length,
  h = e[g - 1];
  return h.indexOf("?") > -1 && (h = h.split("?")[0]),
  h = h.toLowerCase(),
  $.each(f,
  function(a, f) {
      return f == h ? (e[g - 2] = e[g - 2], d = e.join("."), !1) : void 0
  }),
  d
} 

$(document).ready(function() { 
    var href = window.location.href.split('/')[window.location.href.split('/').length-1].substr(0,4);
    if(href=='')
    {
    var href = 'index';
    }
    $(".sf-menu a").each(function(){  
        $this = $(this);
        var Cts = $this[0].href;
        if(Cts.indexOf(href) > 0){  //匹配路径
            $this.parent().addClass("current");  
        }   
    });  


  jQuery(".index-slider").slide({mainCell:".bd ul",effect:"fold",autoPlay:true});
  TouchSlide({slideCell:"#mobile-focus",titCell:".hd ul",mainCell:".bd ul", effect:"left", autoPlay:true,autoPage:true,switchLoad:"_src" });


      
   //current
    (function () {
      $(".item").each(function (index, element) {
        var thisObj = this;
        if ("yes" == $(thisObj).attr("data-noanimate")) {
          return;
        }
        $(window).scroll(function (e) {
          setCurrent();
        });
        setCurrent();
        function setCurrent() {
  
          var wh = $(window).height();
          var st = $(window).scrollTop();
          var t = $(thisObj).offset().top;

          if (st >= t - (wh * (4 / 5))) {
            $(thisObj).addClass("current").addClass("animate");
          }
          else {
            $(thisObj).removeClass("current ").removeClass("animate");
          }
  
        }
  
      });
  
    })();
  


	goTop();

	// PC-NAV
	$('.main-nav ul.sf-menu').superfish({ 
		delay:       500,
		animation:   {opacity:'fast',height:'show'},
		speed:       'fast',
		autoArrows:  true,
		dropShadows: false 
	});
	$('.main-nav ul.sf-menu > li').last().addClass('last').end().hover(function(){ $(this).addClass('nav-hover'); },function(){ $(this).removeClass('nav-hover'); });

    //MOBILE-NAV
	$(".touch-toggle a").click(function(event){
        var className = $(this).attr("data-drawer");
        if( $("."+className).css('display') == 'none' ){      
         $("."+className).slideDown().siblings(".drawer-section").slideUp();
        }else{
         $(".drawer-section").slideUp(); 
        }
        event.stopPropagation();
       });

       $('.touch-menu a').click(function(){     
        if( $(this).next().is('ul') ){
         if( $(this).next('ul').css('display') == 'none' ){
          $(this).next('ul').slideDown();
          $(this).find('i').attr("class","iconfont icon-shang1");     
         }else{
          $(this).next('ul').slideUp();
          $(this).next('ul').find('ul').slideUp();
          $(this).find('i').attr("class","iconfont .icon-xia");
         }   
        }
       });
       
  $(".products-list-item img").height($(".products-list-item img").width()*0.75+"px");
  $(".cases-list-item img").height($(".cases-list-item img").width()*0.75+"px");
  $(".news-list-img img").height($(".news-list-img img").width()*0.75+"px");


  $(function(){
    $.faqfold("#faqfold .item h4","#faqfold .item .info","fast",1,"click"); 
  });
  $('.goods-photos-slide a').each(function(index, elem) {
    var _elem = $(elem)
    var imgSrc = _elem.attr('href');
    var newItem = $('<a class="goods-photos-list-box-item" href="javascript:void(0);"><img class="goods-photos-list-box-item-src" src="' + getProductUrl(imgSrc) + '" /></a>');
    newItem.on('mouseenter click', function(e){
      $('.goods-photos-slide a').css('display','none');
      _elem.css('display','block');
      e.preventDefault();
    });
    $('.goods-photos-list-box').append(newItem);
  });


});

