
//DEFINE CONTROLLERS FOR EVERY PAGE
// $scope.pageClass is used for animation purpose when change with CSS

// OLD PROJECT CONTROLLER
myapp.controller('projectsController1',['$scope', '$compile', '$routeParams', 'projectsFactory', 'customerFactory', function($scope, $compile, $routeParams, projectsFactory, customerFactory) {
//myapp.controller('projectsController',['$scope', function($scope, projectsFactory) {
    $scope.pageClass = 'page-projects';

    // factory not working while adding $compile
   // $scope.customers = projectsFactory.customers1;

    //var a  = $scope.customer2.id;

    $scope.test = projectsFactory.customers1;

    $scope.showdiv = function($event){

        $event.currentTarget = function() {$(this).css("color","red"); };
        $scope.templateURL = 'partials/my-customer.html';
        $scope.ID = $routeParams.ID;
    };

    $scope.ID = $routeParams.ID;

    $scope.asd = "123";

    // for project page
    $scope.isStatus = function(cust){
        return (cust.id == $scope.ID);
    };


    customerFactory.getItems().success(function(data){
        $scope.items = data;
    });

    // $scope.showdiv = function(){
    //     var compiledeHTML = $compile("<div my-Customer>BBBBBBBBB</div>")($scope);
    //     $("#test").append(compiledeHTML);
    // };


     $scope.customers2 =[
        {id : 1, name:'CRM Software',
            designer : 'Philip',
                technology : 'CSS3, HTML5',
                    description : ''
        },
         {id : 2, name:'CRM Software-2',
             designer : 'Philip',
             technology : 'CSS3, HTML5, HTML5',
             description : ''
         },
         {id : 3, name:'CRM Software',
             designer : 'Philip',
             technology : 'CSS3, HTML5',
             description : ''
         },
         {id : 4, name:'CRM Software',
             designer : 'Philip',
             technology : 'CSS3, HTML5',
             description : ''
         },
         {id : 5, name:'CRM Software',
             designer : 'Philip',
             technology : 'CSS3, HTML5',
             description : ''
         }
    ];



    $scope.msg = "asd";

}]);


myapp.controller('projectsController', function ($http, $scope, $rootScope, $routeParams, projectsFactory, customerFactory) {

    // GOOD PROJECT CONTROLLER

    $scope.ID = $routeParams.ID;
    $scope.pageClass = 'page-projects';
    $rootScope.bodyClass = "page-projects-b";
    $rootScope.pageTitle = "PROJECTS";
    // for filtering project on page project page
    $scope.isStatus = function(cust){
        return (cust.ID == $scope.ID);
    };


    //$scope.test = 123;


    document.getElementsByTagName("body")[0].className = "asd";

    $http.get('customerData.json').then(successCallback, errorCallback);



    function successCallback(response){
        //success code
        //$scope.dataBack = response;

        console.log("got Data");

        $scope.customerData = response.data;
        $scope.dataBack = response.data;

        $scope.customerPictures = response.data.Pictures;

    }
    function errorCallback(error){
        //error code
        console.log(error);
    }



    $scope.customers2 =[
        {id : 1, name:'CRM Software',
            designer : 'Philip',
            technology : 'CSS3, HTML5',
            description : ''
        },
        {id : 2, name:'CRM Software-2',
            designer : 'Philip',
            technology : 'CSS3, HTML5, HTML5',
            description : ''
        },
        {id : 3, name:'CRM Software',
            designer : 'Philip',
            technology : 'CSS3, HTML5',
            description : ''
        },
        {id : 4, name:'CRM Software',
            designer : 'Philip',
            technology : 'CSS3, HTML5',
            description : ''
        },
        {id : 5, name:'CRM Software',
            designer : 'Philip',
            technology : 'CSS3, HTML5',
            description : ''
        }
    ];








    $scope.looping = function () {
        var all = document.getElementsByClassName("monsterTest");
        max = all.length;

        for (var i=0; i < max; i++) {

            if (all[i].className == "monsterTest" ) {
                all[i].className = all[i].className + " newClass";
            }
            //all[i].className = "newClass";
            //console.log(all[i]);
        }

        console.log(all[29]);
    };


    $scope.showMore = function (eleID, eleCls, eleNewCls) {
        //max = eleArr.length;
        var ele = document.getElementById(eleID),
            counter = 0;

        //console.log($event.target);

       // ele.addEventListener("click", function(){
            console.log("click");
            var eleArr = document.getElementsByClassName(eleCls);

            for (var i=0, max = eleArr.length; i < max; i++)
            {
                if (eleArr[i].className == eleCls )
                {
                    if (counter < 10)
                    {
                        eleArr[i].className = eleArr[i].className + " " + eleNewCls;
                        counter++;
                    }
                }
            }
        //});
    };


    $scope.loopingV2 = function (eleCls, eleNewCls) {
        //max = eleArr.length;
        var eleArr = document.getElementsByClassName(eleCls);

        for (var i=0, max = eleArr.length; i < max; i++) {
            if (eleArr[i].className == eleCls ) {
                eleArr[i].className = eleArr[i].className + " " + eleNewCls;
            }
        }
    };


//https://api.github.com/users/angular/repos
    //test.php



    // customerFactory.getItems().success(function(data){
    //     $scope.items = data;
    // });

    //$scope.items = customerFactory.getItems;



    // $scope.customers2 =[
    //     {id : 1, name:'CRM Software',
    //         designer : 'Philip',
    //         technology : 'CSS3, HTML5',
    //         description : ''
    //     },
    //     {id : 2, name:'CRM Software-2',
    //         designer : 'Philip',
    //         technology : 'CSS3, HTML5, HTML5',
    //         description : ''
    //     },
    //     {id : 3, name:'CRM Software',
    //         designer : 'Philip',
    //         technology : 'CSS3, HTML5',
    //         description : ''
    //     },
    //     {id : 4, name:'CRM Software',
    //         designer : 'Philip',
    //         technology : 'CSS3, HTML5',
    //         description : ''
    //     },
    //     {id : 5, name:'CRM Software',
    //         designer : 'Philip',
    //         technology : 'CSS3, HTML5',
    //         description : ''
    //     }
    // ];


});


myapp.controller('codeController', function($scope, $rootScope, codeFactory) {
    $scope.pageClass = 'page-code';
    $rootScope.bodyClass = "page-code-b";
    $rootScope.pageTitle = "CODE SNIPPETS";
    $rootScope.headMoto = " Which witch watch which witch's watch";

    //$scope.bodyClass = 'page-code-b';
    // $("body").addClass($scope.pageClass);

    //$scope.testing = codeFactory.getItems();

    $scope.testing = function (obj, $event) {
        var inputElementVal = $scope.codeSearch;
        codeFactory.getItems(inputElementVal);
        //var currentElement = $event.target;
        //console.log(currentElement.value);//this will give you value of current element



        console.log($scope.codeSearch);


        //console.log("asd");
    };

    $scope.highCodeInit = function() {
        Prism.highlightAll();
    };



});



myapp.controller('contactController', function($scope, $rootScope) {
    $scope.pageClass = 'page-contact';
    $rootScope.bodyClass = "page-contact-b";
    $rootScope.pageTitle = "CONTACT";
    // $("body").addClass($scope.pageClass);
});




myapp.controller('homeController', function ($scope, $rootScope, homeAnimationFactory) {
    $scope.pageClass = 'page-home';
    $rootScope.bodyClass = "page-home-b";
    $rootScope.pageTitle = "HOME";
    $rootScope.headMoto = "Home sweet home...";
    $scope.homeAnimeAll = homeAnimationFactory.initAll;


});






myapp.controller('mainController', function ($scope, menuFactory) {

    $scope.menuOpen = menuFactory.menuOpen;
    $scope.menuClosed = menuFactory.menuClosed;
    $scope.menuHover = menuFactory.menuHoverAnimate;

    $scope.checkSwitch = function () {
        if ($("#switch").is(":checked")) {
            menuFactory.menuOpen();
        } else {
            return false;
        }

    }

    $scope.hamburgerInit = function () {
        $('#nav-icon2').click(function(){
            $(this).toggleClass('open');
        });
    }


    console.log(window.location.pathname);

        //return ($("#switch").is(":checked"));




});



