var app = angular.module("Smece", ['smoothScroll', 'ngAnimate', '720kb.socialshare']);

app.controller('SmeceKont', function ($scope, $timeout, $anchorScroll, $location, $http) {

    // DUGMAT ZA KORAKE
    $scope.SakrijFF1 = false;
    $scope.SakrijFF2 = true;
    $scope.SakrijFF3 = true;
    $scope.SakrijFF4 = true;
    $scope.SakrijFF5 = true;
    $scope.SakrijFF6 = true;
    $scope.SakrijFF5Vrijeme = true;

    // PRVI DIO INFO
	$scope.Naslov = 'Ako bi smeće koje se prikupi u Crnoj Gori na godišnjem nivou pretvorili u prazne aluminijumske limenke, do koje bi visine stigli?';
    $scope.Konzervi = 15.80;
    $scope.Smeca = 0.24;
    //sekunde
    $scope.Vrijeme = 0.02;
    var metara = 1.8;
    var t = 10;
    var mytimeout = 0;
    $scope.Visina = 2;
    $scope.PrikaziBrzinu = 0;
    $scope.PrikaziBrzinu1 = 0;

    // za prikaz cijelog dijela
	$scope.Opis = 1;

    // za promjenu boje
    $scope.Crna = 0;

    // povuci na dno
    $location.hash('start');    
    $anchorScroll();  

    $scope.FF1 = function() {        
        $scope.SakrijFF1 = true;        
        metara = 56;
        t = 25;
        $scope.Opis = 0;    
        $scope.onTimeout1 = function(){        
            $scope.Visina++;
            mytimeout = $timeout($scope.onTimeout1,t);
            if ($scope.Visina > metara) {
                $timeout.cancel(mytimeout);
            }
        }    
        $scope.onTimeout1();
 
        $timeout(function() {
        	$scope.Opis=1;
            $scope.Naslov = 'Most Milenijum';
            $scope.Konzervi = 494.79;
            $scope.Smeca = 7.37;
            //sekundi
            $scope.Vrijeme = 0.71;
            $scope.SakrijFF2 = false;
    	}, 2000);
    };

    $scope.FF2 = function() {        
        $scope.SakrijFF2 = true;        
        metara = 1749;
        $scope.Visina = 57.5; 
        t = 10;
         $scope.onTimeout2 = function(){ 
            console.log(t);       
            $scope.Visina = $scope.Visina + 33.84;
            mytimeout = $timeout($scope.onTimeout2, 100);
            if ($scope.Visina > metara) {
                $timeout.cancel(mytimeout);
            }
        }    
        $scope.onTimeout2();
        $scope.Opis = 0;
        $timeout(function() {
        	$scope.Opis=1;
            $scope.Naslov = 'Lovćen';
            $scope.Konzervi = 15182.29;
            $scope.Smeca = 226.22;
            //sekundi
            $scope.Vrijeme = 21.85;
            $scope.SakrijFF3 = false;
    	}, 5000);
    };

    $scope.FF3 = function() {        
        $scope.SakrijFF3 = true; 
        $scope.Visina = 1749.5;       
        metara = 100000;
        t = 10;
         $scope.onTimeout2 = function(){ 
            console.log(t);       
            $scope.Visina = $scope.Visina + 1228.1375;
            mytimeout = $timeout($scope.onTimeout2, 100);
            if ($scope.Visina > metara) {
                $timeout.cancel(mytimeout);
            }
        }    
        $scope.onTimeout2();
        $scope.Opis = 0;
        $timeout(function() {
            $scope.Crna=1;
        }, 4000);
        $timeout(function() {
            $scope.Opis=1;
            $scope.Naslov = 'Kármánova linija';
            $scope.Konzervi = 868055.56;
            $scope.Smeca = 12934.03;
            //minuta
            $scope.Vrijeme = 20.82;
            $scope.SakrijFF4 = false;
        }, 8000);
    };

    $scope.FF4 = function() {        
        $scope.SakrijFF4 = true; 
        $scope.Visina = 100000.2;       
        metara = 384403000;
        t = 10;
         $scope.onTimeout2 = function(){ 
            console.log(t);       
            $scope.Visina = $scope.Visina + 2562020;
            mytimeout = $timeout($scope.onTimeout2, 100);
            if ($scope.Visina > metara) {
                $timeout.cancel(mytimeout);
            }
        }    

        
        $timeout(function() {
            $scope.PrikaziBrzinu = 1;
        }, 8000);
        $timeout(function() {
            $scope.PrikaziBrzinu = 0;
        }, 12000);    
        $scope.onTimeout2();
        $scope.Opis = 0;
        $timeout(function() {
            $scope.Opis=1;
            $scope.Naslov = 'Mjesec';
            $scope.Konzervi = 3336831597.22;
            $scope.Smeca = 49718790.80;
            //min
            $scope.Vrijeme = 80;
            $scope.SakrijFF5 = false;
        }, 15000);
    };

    $scope.FF5 = function() {
        $scope.SakrijFF5 = true; 
        $scope.Visina = 384403000.2;       
        metara = 2524171167.79;
        t = 10;
         $scope.onTimeout2 = function(){ 
            console.log(t);       
            $scope.Visina = $scope.Visina + 8559072.67114;
            mytimeout = $timeout($scope.onTimeout2, 100);
            if ($scope.Visina > metara) {
                $timeout.cancel(mytimeout);
            }
        }    
        $timeout(function() {
            $scope.PrikaziBrzinu1 = 1;
        }, 10000);
        $timeout(function() {
            $scope.PrikaziBrzinu1 = 0;
        }, 15000);
        $timeout(function() {
            //$scope.Info = true;
        }, 32000);
        $timeout(function () {
            $scope.prozor = true;
        }, 30000);
        $scope.onTimeout2();
        $scope.Opis = 0;
        $timeout(function() {
            $scope.Opis=1;
            $scope.Naslov = 'Negdje oko planete Vulkan';
            $scope.Konzervi = 21911208053.69;
            $scope.Smeca = 326477000.00;
            // godina
            $scope.Vrijeme = 1;
            $scope.SakrijFF6 = false;
            $scope.SakrijFF5Vrijeme = false;
        }, 25000);
    };

    // prikaz prozora za mail
    $scope.prozor = false;
    $scope.hvala = false;
    

    // uzmi mail
    $scope.Mail = function (mail) {        
        $http.post('api/mail/' + mail).success(function(data) {
            $scope.hvala = true;
            $timeout(function () {
                $scope.prozor = false;
            }, 3000);
        });
    }
});
