
//根据浏览器适宜大小
function fucWidthimg(ele, width, height) {

 
        var macRatio = (parseInt($(window).width())) / 1920;
        var imgwidth = width * macRatio;
        var imgheight = height * macRatio;

        $(ele).css({
            "width": imgwidth + 'px',
            "height": imgheight + 'px'
        });

 
}

function initUpDown(e) {

    if ($(e).children(".item").children("img:first").attr("class") == "no-none") {
        $(e).children(".arrows").children("a:first").addClass("none");
    }
    else {
        $(e).children(".arrows").children("a:first").attr("class", "up");
    }


    if ($(e).children(".item").children("img:last").attr("class") == "no-none") {
        $(e).children(".arrows").children("a:last").addClass("none");
    }
    else {
        $(e).children(".arrows").children("a:last").attr("class", "down");
    }

}
function initdesc(e) {

    if ($(e).children(".item").children("img:first").attr("class") == "no-none") {
        $(e).children(".desc").children("p").fadeIn().attr("class", "no-none");
    }
    else {
        $(e).children(".desc").children("p").fadeOut().attr("class", "none");
    }

}


$(function () {


    $('.arrows .down').click(function () {

        $(this).parent().siblings(".item").children("img.no-none:first").slideUp().next("img").slideDown().attr("class", "no-none").prev("img").attr("class", "none");
        initUpDown($(this).parent().parent());
        initdesc($(this).parent().parent());


    })
    $('.arrows .up').click(function () {

        $(this).parent().siblings(".item").children("img.no-none:first").slideUp().prev("img").slideDown().attr("class", "no-none").next("img").attr("class", "none");
        initUpDown($(this).parent().parent());
        initdesc($(this).parent().parent());


    })

    window.app = window.app || {};

    app.DEBUG = 1;
    app.SHOW_CLASS = "show";
    app.LANGUAGE = $("#select_language").val();
    app.MOBILE_WIDHT = 480;
    app.log = function() {
        if(app.DEBUG && console && console.log) {
            console.log.apply(console, arguments);
        }
    };
    app.change_language = function(language) {
        if(language === "en") {
            $("#select_language").val(app.LANGUAGE)
            document.location.href = "/en";
        }
    };
    app.listen_scroll = function() {
        var $window = $(window);
        var $header = $(".header");
        var fixTop = 900;

        $window.off('scroll.h').on('scroll.h', function(e) {
           if($window.scrollTop() > fixTop) {
               if(!$header.hasClass('fixed')) {
                   $(".header").addClass('fixed');
               }
           } else {
               if($header.hasClass('fixed')) {
                   $(".header").removeClass('fixed');
               }
           }
        });
    };
    app.init_header = function() {
        //$(".header_logo").addClass(app.SHOW_CLASS);
        //$(".header_inner").addClass(app.SHOW_CLASS);
        // $("#select_language").fancySelect({
        //     forceiOS: true
        // }).on('change.fs', function() {
        //     if($(this).val() !== app.LANGUAGE) {
        //         app.change_language($(this).val());
        //     }
        // });
        $(".js_header_btn").on('click', function() {
            $(this).toggleClass('open');
            app.toggle_menu();
        });
    };
    app.toggle_menu = function() {
        var $menu = $(".menu");
        if($menu.hasClass('open')) {
            $menu.removeClass('open');
            $('body').css('overflow-y', 'auto');
        }else {
            $menu.css({
                transition: "none",
                display: "block"
            });
            setTimeout(function() {
                $menu.addClass('open');
                $('body').css('overflow-y', 'hidden');
            }, 50);

        }
    };
    app.init_menu = function() {
        $(".menu").addClass(app.SHOW_CLASS)
        setTimeout(function() {
            $(".menu").css({
                transition: "none"
            });
        }, 1000);
    };
    app.add_footer_ttl_clicker = function() {
        $(".footer_box_links").hide();

        $(".footer_ttl").off("click.f").on("click.f", function() {
            var $this = $(this);
            var $footer_box_links = $(this).siblings(".footer_box_links");
            $(".footer_ttl").not($this).removeClass("open");
            $(".footer_box_links").not($footer_box_links).slideUp();
            if($this.hasClass("open")) {
                $footer_box_links.slideUp();
            }else {
                $footer_box_links.slideDown();
            }
            $this.toggleClass("open");
        });
    };
    app.remove_footer_ttl_clicker = function() {
        $(".footer_ttl").off("click.f").removeClass("open");
        $(".footer_box_links").show();
    };
    app.init_footer = function() {
        $(window).on("resize", function() {
            if($(window).width() > app.MOBILE_WIDHT) {
                app.remove_footer_ttl_clicker();
            }else {
                app.add_footer_ttl_clicker();
            }
        }).trigger("resize");
    };
    app.init = function() {
        app.init_header();
        app.init_menu();
        app.init_footer();

    };

    app.init();

});