﻿function supportCss3(style) {
    var prefix = ['webkit', 'Moz', 'o'],
        i,
        humpString = [],
        htmlStyle = document.documentElement.style,
        _toHumb = function (string) {
            return string.replace(/-(\w)/g, function ($0, $1) {
                return $1.toUpperCase();
            });
        };

    for (i in prefix)
        humpString.push(_toHumb(prefix[i] + '-' + style));

    humpString.push(_toHumb(style));

    for (i in humpString)
        if (humpString[i] in htmlStyle) return true;

    return false;
}
var timekey;

$(function(){
    //$('#announcement').scrollbox();
    $('#openqr a').hover(function(){
        var index = $('#openqr a').index(this)+1;
        $('.footlogo')
            .removeClass('open1')
            .removeClass('open2')
            .addClass('open'+index);
    },function(){
        $('.footlogo')
            .removeClass('open1')
            .removeClass('open2');
    });
    $('#announcement_btn_t').click(function(){
        $('#announcement').trigger('backward');
        return false;
    });
    $('#announcement_btn_b').click(function(){
        $('#announcement').trigger('forward');
        return false;
    });
    $('#open-nav').click(function(){
        $('.phone-nav-box-in').width(($(window).width()*0.6)-40);
        $('html').addClass('open-phone-nav');
        return false;
    });
    $('.phone-nav-mask').click(function(){
        $('html').removeClass('open-phone-nav');
        return false;
    });
    //var glide = $('.slider').glide().data('api_glide');

    $('.nav ul li a').hover(function(){
        clearTimeout(timekey);
        var index = $('.nav ul li a').index($(this));
        var thisnav = $('.header-nav .ul .li').eq(index);
        thisnav.prevAll().removeClass('nl-r').addClass('nl-l');
        thisnav.nextAll().removeClass('nl-l').addClass('nl-r');
        if(thisnav.html()){
            $('.nav ul li a').not($(this)).removeClass('hover');
            $(this).addClass('hover');
            $('.header-nav').addClass('hn-show');
            $('.header-nav .ul .li').not(thisnav).removeClass('hn-li-show');
            thisnav.addClass('hn-li-show');
        }else{
            $('.nav ul li a').removeClass('hover');
            $('.header-nav').removeClass('hn-show');
        }
    },function(){});

    $('.header').hover(function(){},function(){
        timekey = setTimeout(function(){
            $('.nav ul li a').removeClass('hover');
            $('.header-nav').removeClass('hn-show');
        },1000);
    });

    if(supportCss3('transform')){
    }else{
        $('.header-nav').addClass('no3d');
    }
    $('.header-nav').removeClass('qdqdn');



    $('.nav-left li.top-li>a').click(function(){
        var $this = $(this).parent();
        var $ul = $('ul',$this);
        $ul = $ul.eq(0);
        if($ul.length){
            //if($(window).width()>640){
                $('.nav-left li.top-li').not($this).removeClass('open');
                $('.nav-left li.top-li>ul').not($ul).stop(false,false).slideUp();
                if($this.hasClass('open')){
                    $this.removeClass('open');
                    $ul.stop(false,false).slideUp();
                }else{
                    $this.addClass('open');
                    $ul.stop(false,false).slideDown();
                }
            //}else{
            //    $('.nav-left li.top-li').not($this).removeClass('open');
            //    if($this.hasClass('open')){
            //        $this.removeClass('open');
            //    }else{
            //        $this.addClass('open');
            //    }
            //}
            return false;
        }
    });

if($(window).width()>640){
    $('.nav-left li.top-li>a.hover').click();
}



    var tc = $("#sly1-text .text-c");
    //var tr1 = $("#sly1-text .text-r b");
    //var tr2 = $("#sly1-text .text-r span");

    var $sly_btn =  $('.sly-btn');

    var slyl = $('#sly1 ul li').length;

    if(slyl>5&&0){
        $("#sly1 ul").append($('#sly1 ul li').clone());
    }

    if($("#sly1").length){
        $('#sly1 img').load(function(){
            if(sly)sly.reload();
        });

        var sly = new Sly("#sly1", {
            horizontal: 1,
            itemNav: 'forceCentered',
            smart: 1,
            activateMiddle: 1,
            activateOn: 'click',
            mouseDragging: 1,
            touchDragging: 1,
            releaseSwing: 1,
            startAt: 0,
            scrollBar: $('.scrollbar'),
            //scrollBy: 1,
            speed: 1000,
            elasticBounds: 1,
            easing: 'easeOutExpo',
            dragHandle: 1,
            dynamicHandle: 1,
            clickBar: 1,
            prevPage: $('.sly-btn .sb1'),
            nextPage: $('.sly-btn .sb2')
        },{
            move:function () {
                var data = $(this.items[this.rel.activeItem]['el']).data();
                tc.text(data.title);
                $sly_btn.width(this.items[this.rel.activeItem].size);
                for( var i=0;i<=7;i++){
                    var j = this.rel.activeItem+i-3;
                    if(j>=0){
                        if(this.items[j]){
                            var $j = $('img',this.items[j]['el']);
                            if(!$j.data('load')){
                                $j.attr('src',$j.data('src'));
                                $j.data('load',1);
                            }
                        }
                    }
                }
                //if(slyl>5&&0) {
                //    var index = this.rel.activeItem + 1;
                //    var oldindex = index;
                //    var length = this.items.length;
                //    if (length / 2 > index) {
                //        index = index + length / 2;
                //    } else {
                //        index = index - length / 2;
                //    }
                //    var iteml = this.items[index - 2];
                //    var item = this.items[index - 1];
                //    var itemr = this.items[index];
                //    if (this.animation.to < 0) {
                //        this.pos.cur = (itemr.center);
                //        this.slideTo(item.center);
                //    }
                //    var endtocur = (this.pos.end + this.pos.start) - this.pos.cur;
                //    if (endtocur < 0) {
                //        this.pos.cur = (iteml.center);
                //        this.slideTo(item.center);
                //    }
                //}
            }
        }).init();

    }

    if($("#sly2").length){
    //$("#sly2 ul").append($('#sly2 ul li').clone());
        var sly2 = new Sly("#sly2", {
            horizontal: 1,
            itemNav: 'forceCentered',
            smart: 1,
            activateMiddle: 1,
            activateOn: 'click',
            mouseDragging: 1,
            touchDragging: 1,
            releaseSwing: 1,
            startAt: 0,
            pagesBar: $('.sly2 .sly-page ul'),
            activatePageOn: 'click',
            //scrollBy: 1,
            speed: 1000,
            elasticBounds: 1,
            easing: 'easeOutExpo',
            dragHandle: 1,
            dynamicHandle: 1,
            clickBar: 1,
            prevPage: $('.sly-btn .sb1'),
            nextPage: $('.sly-btn .sb2')
        },{
            move:function () {

                var data = $('.active', this.slidee).data();
                tc.text(data.title);
                $sly_btn.width(this.items[this.rel.activeItem].size);

                //var ii = this.rel.activeItem;
                //var ll =(this.items[ii].start-
                //        this.pos.cur+
                //        this.pos.start);
                //var l1 = ll/4;
                //var l2 = ll/5;
                //$('.img',this.items[ii].el).css({
                //    'transform':'translateX('+l1+'px)',
                //    '-o-ttransform':'translateX('+l1+'px)',
                //    '-moz-transform':'translateX('+l1+'px)',
                //    '-webkit-transform':'translateX('+l1+'px)'
                //});
                //$('.text',this.items[ii].el).css({
                //    'transform':'translateX('+l2+'px)',
                //    '-o-ttransform':'translateX('+l2+'px)',
                //    '-moz-transform':'translateX('+l2+'px)',
                //    '-webkit-transform':'translateX('+l2+'px)'
                //});



            }
        }).init();
    }
    if($("#sly3").length) {
        var sly3 = new Sly("#sly3", {
            horizontal: 1,
            itemNav: 'basic',
            smart: 1,
            activateOn: 'click',
            mouseDragging: 1,
            touchDragging: 1,
            releaseSwing: 1,
            startAt: 0,
            //scrollBar: $wrap.find('.scrollbar'),
            scrollBy: 1,
            //pagesBar: $wrap.find('.pages'),
            activatePageOn: 'click',
            speed: 300,
            elasticBounds: 1,
            easing: 'easeOutExpo',
            dragHandle: 1,
            dynamicHandle: 1,
            clickBar: 1,
            prevPage: $('.rongyu .btnl'),
            nextPage: $('.rongyu .btnr')
        }).init();
    }
    $(window).resize(function(){
        var ww = $(window).width();
        var wh = $(window).height();
        if(ww<=640){
            wh = wh-100;
            if(wh>418){wh = 418;}
            var lw = (385/592)*wh;

            $('#sly1 ul li , #sly1 ul li img').height(wh);
            //$('#sly2 ul li').height(wh+70);
        }else{
            $('#sly1 ul li , #sly1 ul li img').css({
                'height':'',
                'width':''
            });
            $('#sly2 ul li').css({
                'height':'',
                'width':''
            });
        }
        if(sly2)sly2.reload();
        if(sly)sly.reload();
    });
    $(window).resize();

    $('#sly1 img').load(function(){
        if(sly)sly.reload();
        if(sly2)sly2.reload();
    });
    $(window).load(function(){
        if(sly)sly.reload();
        if(sly2)sly2.reload();
    });
    if($('.ryzz ul li a').length){
        $('.ryzz ul li a').fancybox();
    }
});