Class(function(extend, using, self){
    extend("pages/page");
    using("lib/jquery.min.js");

    var $p1 = $('#page1');
    var $p2 = $('#page2');
    var $b1 = $('#btn1');
    var $b2 = $('#btn2');
    var $b3 = $('#btn3');
    var $i = $('#info');
    var $s1 = $('#speed1');
    var $s2 = $('#speed2');
    var $ip = $('#ip');
    var $ad = $('#address');
    var $sp = $('#span-loading');
    var $cd = $('#span-countdown');
    var $av = $('#advise');
    var $sg = $('#suggest1');
    var $sg2 = $('#suggest2');
    var timer_cd;
    var QT;


    self.initEvent = function(){
        // 开始测速
        $b1.on('click', function () {
            $i.show();
            $b1.hide();
            $b3.show();
            //startCountdown();
            QT.startRateTest();
        });

        // 重新测速
        $b2.on('click', function () {
            $p2.hide();
            $p1.show();
            $i.hide();
            $b1.show();
            $b3.hide();
			
        });

        // 停止测速
        $b3.on('click', function () {
            QT.stopRateTest();
            $p2.hide();
            $p1.show();
            $i.hide();
            $b3.hide();
            $b1.show();
        });
    }

    self.func(function(curData){

        self.addCall("showTestResult", function(){
            $p1.hide();
            $p2.show();
            $s1.text(QT.uploadspeed);
            $s2.text(QT.downloadspeed);
            $ip.text(QT.ip);
            $ad.text(QT.address || '未知');
            $av.text(QT.adviseNetSpeed);
            if(QT.adviseNetSpeed < 600){
                $sg.hide();
                $sg2.show();
            } else if (QT.adviseNetSpeed >= 600) {
				$sg.show();
                $sg2.hide();
			}
        });

        self.addCall("startLoading", function(){
            var arr = ['', '.', '..', '...'];
            var index = 0;
            setInterval(function(){
                if(index > 3){
                    index = 0;
                }
                $sp.text(arr[index]);
                index++;
            }, 300);
        });

        self.addCall("startCountdown", function(){
            clearTimeout(timer_cd);
            countdown(20);
        });

        self.addCall("countdown", function(n){
            if(n >= 0){
                $cd.text(n);
                timer_cd = setTimeout(function(){
                    countdown(n - 1);
                }, 1000);
            }
        });

        QT =  curData;
        $b3.hide();
        startLoading();


        this.sup().constructor(curData);
        this.initEvent();
    })

});
