
myapp.factory('menuFactory', function () {
    //var factory = {}; // empty object
    //var facData = [{name : 'asd'}];

    //var timeViewNav = new TimelineMax({});
    //var timeMoveCont = new TimelineMax({});
    //var timeMenuColl = new TimelineMax({});




    // FUNCTION TO GET POSITION OF ENTERED ELEMENT

    function getPos(ev, eleID, mouseState){
        x=parseInt(ev.clientX);
        y=parseInt(ev.clientY);
        docHeight = parseInt($(document).height());

        // a = 50;
        // b = 12.5;
        // c = a / b;
        // d = 100 / c;
        // e = ""+d+"%";
        // console.log(e);

        prcOffSetY1 =  (docHeight / y);
        prcY = (100 / prcOffSetY1);
        // console.log("Y: "+prcY+"%");


        prcOffSetX1 =  (docHeight / x);
        prcX = (100 / prcOffSetX1);
        // console.log("X: "+prcX+"%");

        //console.log(cursor="Your Mouse Position Is : X:" + x + " and Y:" + y) ;
        //document.getElementById("displayArea").innerHTML=cursor
        // console.log(eleID);
        var entrance = "";
        var leave = "";
        var ele = $("#menu_container ul li[data-id="+eleID+"]");

        // CHECK ELEMENT 1
        if (eleID == 1) {

            if (mouseState == "enter") {

                if (prcY < 30) {
                    entrance = "up";

                }

                if (prcY > 45) {
                    entrance = "down";
                }

                if (prcX > 24) {
                    entrance = "right";
                }

            }

            if (mouseState == "leave") {

                if (prcY < 30) {
                    entrance = "up-leave";
                }

                if (prcY > 45) {
                    entrance = "down-leave";
                }

                if (prcX > 24) {
                    entrance = "right-leave";
                }

            }

        }

        // CHECK ELEMENT 2
        if (eleID == 2) {

            if (mouseState == "enter") {

                if (prcY < 30) {
                    entrance = "up";
                }

                if (prcY > 45) {
                    entrance = "down";
                }

                if ((prcX < 29)) {
                    entrance = "left";
                }


            }

            if (mouseState == "leave") {

                if (prcY < 30) {
                    entrance = "up-leave";
                }

                if (prcY > 45) {
                    entrance = "down-leave";
                }

                if (prcX < 30) {
                    entrance = "left-leave";
                }




                // if (prcX > 24) {
                //     entrance = "right-leave";
                // }

            }

        }


        // CHECK ELEMENT 3
        if (eleID == 3) {

            if (mouseState == "enter") {

                if (prcY < 52) {
                    entrance = "up";
                }

                if (prcY > 70) {
                    entrance = "down";
                }

                if (prcX > 25) {
                    entrance = "right";
                }



            }

            if (mouseState == "leave") {

                if (prcY > 70) {
                    entrance = "down-leave";
                }

                if ((prcY < 55) && (prcY > 45)) {
                    entrance = "up-leave";
                }

                if ((prcX > 24) && (prcX < 30)) {
                    entrance = "right-leave";
                }

            }

        }

        // CHECK ELEMENT 4
        if (eleID == 4) {

            if (mouseState == "enter") {

                if (prcY < 52) {
                    entrance = "up";
                }

                if (prcY > 73) {
                    entrance = "down";
                }

                if (prcX < 29) {
                    entrance = "left";
                }



            }

            if (mouseState == "leave") {

                if (prcY > 70) {
                    entrance = "down-leave";
                }

                if (prcY < 55) {
                    entrance = "up-leave";
                }

                if (prcX < 27.5) {
                    entrance = "left-leave";
                }


            }

        }


        ele.attr("data-entrance", entrance);

        //console.log(entrance);

    }





    // MENU FUNCTIONS : Open, Close, Hover
    var menuOCF = {
        menuOpen : function() {
            $("#main_nav").addClass("open");
            //$("#main_container").addClass("menu_open");

        },
        menuClosed : function() {
            $("#main_nav").removeClass("open");
            //$("#main_container").removeClass("menu_open");

        },

        menuHoverAnimate : function () {
            $("#menu_container ul li").mouseenter(function (ev) {
                var eleID = $(this).attr("data-id");
                var mouseState = "enter";
                //getPos(ev, eleID, mouseState);
                //$("#menu_container ul li:after").css("bottom","0");
            });


            $("#menu_container ul li").mouseleave(function (ev) {
                var eleID = $(this).attr("data-id");
                var mouseState = "leave";
                //getPos(ev, eleID, mouseState);
                //$("#menu_container ul li:after").css("bottom","0");
            });

        }


    };


    // RETURNING THE OBJECT WITH THE FUNCTIONS DEFINED INSIDE
    return menuOCF;

});


myapp.factory('homeAnimationFactory', function () {

    var homeAnimeObj = {};


    var timeLinesMonR = new TimelineMax({});
    var timeScreenLeft = new TimelineMax({});

    function myLoop (ele,cls,iter,delay) {  //  create a loop function

        setTimeout(function () {    //  call a 3s setTimeout when the loop is called
            $(ele).eq(i).addClass(cls);          //  your code here
            i++;                     //  increment the counter
            if (i < iter) {            //  if the counter < 10, call the loop function
                myLoop(ele,cls,iter,delay);             //  ..  again which will trigger another
            }                        //  ..  setTimeout()
        }, delay);
        //console.log(i);
    }

    function delay(ele,cls,delay) {
        setTimeout(function(){
            $(ele).addClass(cls);
        },delay);
    }



    function homeAnimeEnvelopeBoy(){
        // setTimeout(function(){
        //     myLoop(".cls-18","anime fadeInLeft",24,100);
        //     $("#envelope_right").css({"transform":"rotate(0deg)", "opacity" : "1"});
        //     $("#envelope_left").css({"transform":"rotate(0deg)", "opacity" : "1"});
        // },500);

        var cls141 = $(".cls-13,.cls-14, .cls-15, .cls-16, .cls-17");


        delay("#boy","anime zoomIn", 1);
        delay(".cls-13,.cls-14, .cls-15, .cls-16, .cls-17","anime zoomIn", 500);
    }




    function homeAnimeRightMonitorKeys() {

        for(i=0;i<100;i++){
            element = $("#keys .cls-8:nth-child("+i+")");
            timeLinesMonR.to(element, 0.02, {fill:"#d5f3d4"}, "+=0.01");
            //timeLinesMonR.to($("#keys .cls-8:nth-child("+i+")"),50,{fill:"#222",ease: Power4.easeOut});
        }

        for(i=0;i<87;i++){
            element = $("#screenLeft rect:nth-child("+i+")");
            timeScreenLeft.to(element, 0.02, { opacity: 1}, "+=0.01");
            //timeLinesMonR.to($("#keys .cls-8:nth-child("+i+")"),50,{fill:"#222",ease: Power4.easeOut});
        }
    }


    function animateKeyboardKeys() {
// ANIMATE THE KEYBOARD KEYS
        $("#keys .cls-8").mouseenter(function(){
            $(this).css("fill","#e8674e");
        });

        $("#keys .cls-8").mouseleave(function(){
            $(this).css("fill","#d5f3d4");
        });

// ANIMATE THE SCREEN LEFT
        $("#screenLeft .cls-6").mouseenter(function(){
            $(this).css("fill","#f2675d");
        });

        $("#screenLeft .cls-6").mouseleave(function(){
            $(this).css("fill","#ccc");
        });


        $("#screenLeft .cls-5").mouseenter(function(){
            $(this).css("fill","#f2675d");
        });

        $("#screenLeft .cls-5").mouseleave(function(){
            $(this).css("fill","#9acae6");
        });

    }



    function homeAnimeBooks (){
        delay("#books .cls-11","anime66 zoomIn", 100);
        delay("#books .cls-10","anime66 zoomIn", 500);
        delay("#books .cls-9","anime66 zoomIn", 900);
        delay("#books .blue_book","anime66 zoomIn", 1300);
    }



    function booksHover() {
        $("#books .cls-11, #books .cls-9, #books .cls-10, #books .blue_book").mouseenter(function(){
            $(this).removeClass("anime66 zoomIn");
            $(this).css({"opacity" : "1"});
        });


        $("#books .cls-11, #books .cls-9, #books .cls-10").mouseenter(function(){
            //ele = $(this);
            //tl3.to(ele,0.1,{y:0, opacity: 1, ease: Power4.easeOut});
        });

    }


    homeAnimeObj = {
        initAll : function() {
            $(document).ready(function () {
                homeAnimeEnvelopeBoy();
                homeAnimeBooks();
                homeAnimeRightMonitorKeys();
                animateKeyboardKeys();
                booksHover();
            });

        }
    };

    return homeAnimeObj;

});


myapp.factory('projectsFactory', function () {




    // var projectsGenOgj = {projFac :[
    //     {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 : ''
    //     }
    // ]};



           var 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 : ''
               }
           ];
            return customers2;





    //return projectsGenOgj;


});

myapp.factory('customerFactory', function ($http) {
    var factory = {};

    factory.getItems = function() {
        return $http.get('https://api.github.com/users/angular/repos');
    };

    return factory;

});


myapp.factory('codeFactory', function () {
    var codeFac = {};

    function getCodeContent(ele) {
        //var asd = $(".code_container").find("font-size");
         //$(".code_container span:contains("+ele+")").css("color","red");

/*         if ($(".code_container span:contains("+ele+")").length > 0) {
             $(this).css("color","red");
         }*/

        console.log("elVAL " + ele);

        var element = ele;
        if (element.length > 3) {
         $(".code_container .code-toolbar code span").each(function () {

             //console.log(element);

             var thisText = $(this).text();
             console.log(thisText);
                // if($(this).is(":contains("+ele+")")) {

             if (thisText.indexOf(element) !== -1) {
                 $(this).css("color","red");
                 $(this).parent().css("display","block");
                 $(this).css("display","block");
             } else {
                 $(this).css("color","");
                 $(this).css("display","none");
             }


/*
             if (thisText.indexOf(element) !== 0) {

             }*/

/*                if($(this).text() == element) {
                    $(this).css("color","red");
                    $(this).parent().css("display","block");

                }*/

                /* else {
                    $(this).css("color","");
                    $(this).parent().css("display","none");
                }*/

/*             if (($(this).text !== element) && ($(this).siblings().text !== element)) {
                 $(this).css("color","");
                 $(this).parent().css("display","none");
             }*/


/*             if (thisText.indexOf(ele)) {
                 $(this).css("color","red");
                 console.log(this);
             }*/

            //console.log("E" + element);



/*
             if ($(this).text === element) {
                 $(this).css("color","red");
                 console.log(this);
             }
*/

         })
        }

        if ((element.length < 3) && (element.length > 0)) {
            $(".code_container .code-toolbar code span").each(function(){
                $(this).parent().css("display","block");
            });
        }
        //asd.remove();
        //return asd;
    }

    codeFac = {
        getItems : function(ele) {
            //console.log("asd");
            //console.log(getCodeContent(ele));
            getCodeContent(ele);
        }
    };



    return codeFac;

})