//初始化
$(function(){
    $(document).bind("touchmove",function(e){
        e.preventDefault();
    });
    //首页
    FUN.dirty(function(){
        var condition = $("div.step-2").css("opacity");
        return (condition > 0.9999);
    },function(){
        $("div.page-1 img.next-page").addClass("second-next-page");
    });

    FUN.PreLoading();


});
//翻动页面事件
$(function(){
    var number = $("div.page").length;
    //向上滑动start
    $("div.page").swipeUp(function(){
        if(!$(this).hasClass("MoveToTop") && !$(this).hasClass("MoveFromBottom") && !$(this).hasClass("MoveToBottom") && !$(this).hasClass("MoveFromTop")){
            var index = $(this).index("div.page");
            if(index != (number-1)){
                //一到二，二到三，三到四
                if(index == 0 || index === 1 || index === 2 || index === 3 || index === 4 ){
                    FUN.dirty(function(){
                        var condition = $("div.page-"+(index+2)+" div.step-2").css("opacity");
                        return (condition > 0.9999);
                    },function(){
                        $("div.page-"+(index+2)+" img.next-page").addClass("second-next-page");
                    });
                }else if (index == 5){
                    FUN.dirty(function(){
                        var condition = $("div.page-"+(index+2)+" div.step-2").css("opacity");
                        return (condition > 0.9999);
                    },function(){
                        $(".agree").show('slow');
                        $("div.page-"+(index+2)+" img.next-page").addClass("second-next-page");
                    });
                }
                else if (index == 6){
                	var total =1;
                    FUN.dirty(function(){
                    	var condition = $("div.page-"+(index+2)+" div.step-1").css("opacity");
                        return (condition > 0.9999);
                    },function(){
                        FUN.Count(0,clickNumber,"special_number");
                    });
                }
                else{
                    clearInterval(FUN.circle);
                }

                var the = $(this);

                the.addClass("MoveToTop").removeClass("current");
                the.next("div.page").removeClass("hide").addClass("MoveFromBottom");
                the.find("img.next-page").removeClass("second-next-page");
                setTimeout(function(){
                    the.removeClass("MoveToTop").addClass("hide");
                    the.next("div.page").removeClass("MoveFromBottom").addClass("current");
                },1000);
            }
        }
    });
    //向上滑end
    //点击下翻按钮start
    $("img.next-page").bind("click",function(){
        var page = $(this).parents("div.page");
        var number = $("div.page").length;

        if(!page.hasClass("MoveToTop") && !page.hasClass("MoveFromBottom") && !page.hasClass("MoveToBottom") && !page.hasClass("MoveFromTop")){
            var index = page.index("div.page");
            if(index != (number-1)){
                //一到二，二到三，三到四
                if(index == 0 || index === 1 || index === 2 || index === 3 || index === 4 ){
                    FUN.dirty(function(){
                        var condition = $("div.page-"+(index+2)+" div.step-2").css("opacity");
                        return (condition > 0.9999);
                    },function(){
                        $("div.page-"+(index+2)+" img.next-page").addClass("second-next-page");
                    });
                }else if (index == 5){
                    FUN.dirty(function(){
                        var condition = $("div.page-"+(index+2)+" div.step-2").css("opacity");
                        return (condition > 0.9999);
                    },function(){
                        $(".agree").show('slow');
                        $("div.page-"+(index+2)+" img.next-page").addClass("second-next-page");
                    });
                }
                else if (index == 6){
                    var total =1;
                    FUN.dirty(function(){
                        var condition = $("div.page-"+(index+2)+" div.step-1").css("opacity");
                        return (condition > 0.9999);
                    },function(){
                        FUN.Count(0,clickNumber,"special_number");
                    });
                }
                else{
                    clearInterval(FUN.circle);
                }

                var the = page;
                the.addClass("MoveToTop").removeClass("current");
                the.next("div.page").removeClass("hide").addClass("MoveFromBottom");
                the.find("img.next-page").removeClass("second-next-page");
                setTimeout(function(){
                    the.removeClass("MoveToTop").addClass("hide");
                    the.next("div.page").removeClass("MoveFromBottom").addClass("current");
                },1000);
            }
        }
    });
    //点击下翻按钮end
    //我愿意按钮start
    $("img.agree").bind("click",function(){
        var page = $(this).parents("div.page");
        var number = $("div.page").length;

        if(!page.hasClass("MoveToTop") && !page.hasClass("MoveFromBottom") && !page.hasClass("MoveToBottom") && !page.hasClass("MoveFromTop")){
            var index = page.index("div.page");
            if(index != (number-1)){

                var total =1;
                FUN.dirty(function(){
                	var condition = $("div.page-"+(index+2)+" div.step-1").css("opacity");
                    return (condition > 0.9999);
                },function(){
                    FUN.Count(0,clickNumber,"special_number");
                });
                
                var the = page;
                the.addClass("MoveToTop").removeClass("current");
                the.next("div.page").removeClass("hide").addClass("MoveFromBottom");
                the.find("img.next-page").removeClass("second-next-page");
                setTimeout(function(){
                    the.removeClass("MoveToTop").addClass("hide");
                    the.next("div.page").removeClass("MoveFromBottom").addClass("current");
                },1000);
            }
        }
    });
    //我愿意按钮end

    //向下滑动start
    $("div.page").swipeDown(function(){
        if(!$(this).hasClass("MoveToTop") && !$(this).hasClass("MoveFromBottom") && !$(this).hasClass("MoveToBottom") && !$(this).hasClass("MoveFromTop")){
            var index = $(this).index("div.page");
            if(index != 0){
                if(index == 2 || index == 1 || index === 2 || index === 3 || index === 4 || index == 5 ||index == 6 || index == 7){
                    FUN.dirty(function(){
                        var condition = $("div.page-"+(index)+" div.step-2").css("opacity");
                        return (condition > 0.9999);
                    },function(){
                        $("div.page-"+(index)+" img.next-page").addClass("second-next-page");
                        
                    });
                }else if(index == 3){                    FUN.dirty(function(){
                        var condition = $("div.page-"+(index)+" div.step-2").css("opacity");
                        return (condition > 0.9999);
                    },function(){
                        $("div.page-"+(index)+" img.next-page").addClass("second-next-page");
                        $("div.page-"+(index)+" img.back-3").addClass("page-3-back");
                    });
                }else{
                    clearInterval(FUN.circle);
                }

                var the = $(this);

                the.addClass("MoveToBottom").removeClass("current");
                the.prev("div.page").removeClass("hide").addClass("MoveFromTop");
                the.find("img.next-page").removeClass("second-next-page");

                setTimeout(function(){
                    the.removeClass("MoveToBottom").addClass("hide");
                    the.prev("div.page").removeClass("MoveFromTop").addClass("current");
                },1000);
            }
        }
    });
    //向下滑动end
});
//区分系统

$(function(){
    var system = FUN.Separate(),href;
    if(system == "ios"){
        if(FUN.isWeiXin()){
            href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.wenwenwo';
            $("#download").attr("href",href);
        }else{}
    }else{
        if(FUN.isWeiXin()){
            href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.wenwenwo';
            $("#download").attr("href",href);
        }else{}
    }
})


//音乐控制
$(function(){
    $("#music-control").click(function(){
        var condition = $(this).data("condition");
        if(condition == "play"){
            $("#audi")[0].pause();
            $(this).attr("src","./images/pause.png").data("condition","pause");
        }else{
            $("#audi")[0].play();
            $(this).attr("src","./images/play.png").data("condition","play");
        }
    })
});