﻿$(document).ready(function () {

    setInterval(function () {
        $('#arm1').animate({ top: '+=4', left: '+=2' }, 1000).animate({ top: '-=4', left: '-=2' }, 1000);
    }, 2500);
    setInterval(function () {
        $('#arm2').animate({ top: '+=4', left: '+=2' }, 1000).animate({ top: '-=4', left: '-=2' }, 1000);
    }, 2000);
    setInterval(function () {
        $('#arm3').animate({ top: '+=4', left: '+=2' }, 1000).animate({ top: '-=4', left: '-=2' }, 1000);
    }, 1700);
    setInterval(function () {
        $('#arm4').animate({ top: '+=4', left: '+=2' }, 1000).animate({ top: '-=4', left: '-=2' }, 1000);
    }, 3000);
    setInterval(function () {
        $('#screen').animate({ top: '+=4', left: '+=2' }, 500).animate({ top: '-=4', left: '-=2' }, 500);
    }, 2000);



    $("#homeProjectsWrap").cycle({
    	fx: "scrollHorz",
    	speed: "slow",
    	timeout: 3000,
    	pager: ".pageNoNav",
    	prev: '#prev',
    	next: '#next',
    	timeout: 0,
    	easing: 'easeInOutElastic'
    });



    $("#slideshow").cycle({
    	fx: "scrollHorz",
    	speed: "slow",
    	timeout: 3000,
    	pager: ".pageNoNav",
    	prev: '.prev',
    	next: '.next',
    	timeout: 0,
    	easing: 'easeInOutElastic'
    });

    $('#ourWay').click(function () {
    	$(this).fadeOut(500, function () {
    	    $('#enjoyWay').animate({ 'margin-top': '-400px' }, function () {
    	        //complete function
    	        $('#close').fadeIn(500);


    	    });
    	});

    });

    	        $('#close').click(function () {

    	            $(this).fadeOut(500, function (e) {
    	                //e.stopPropagation();
    	                $('#enjoyWay').animate({ 'margin-top': '-45px' }, function () { $('#ourWay').fadeIn(500); });
    	            });
    	        });


    	        // stats animation
    	        $('#statsCol1').children().not(':eq(0)').hide();
    	        $('#statsCol2').children().not(':eq(0)').hide();
    	        startStatsCycle();
    	        $('.col4content').hover(stopStatsCycle, startStatsCycle);

    	        // client box limit to 4
    	        var boxes = $('.noTailClients').children();
    	        boxes.sort(function () { return 0.5 - Math.random() });
    	        $('.noTailClients').html(boxes.slice(0, 4));
    	        $('.noTailClients').children().last().addClass('end');

    	        // client quote pick random
    	        var n = Math.floor(Math.random() * $('#bubble .inner').children().length);
    	        $('#bubble .inner').children().not(':eq(' + n + ')').hide();

    	        $("#title h1").lettering('lines').children("span").lettering(); 
                $.fn.cycleChildren = function (d) {
             var e = $(this);
             var nextStat = Math.floor(Math.random() * $(e).children().length);
             //don't show the same element twice in a row
             while (nextStat == $(e).children().filter(":visible").prevAll().length)
                 nextStat = Math.floor(Math.random() * $(e).children().length);
             $(e).children().filter(":visible").delay(d).fadeOut(600, function () {
                 $(e).children().eq(nextStat).fadeIn(600);
             });
             return $(this);
         }
    	    });

        // functions for stats content transitions

         var statsTimer = null;

         function doCycle() {
             $('#statsCol1').cycleChildren();
             $('#statsCol2').cycleChildren(400);
         }

        

         function startStatsCycle() {
            if (statsTimer)
                return;
            statsTimer = setInterval('doCycle()', 8000);
         }

         function stopStatsCycle() {
            if (!statsTimer) 
                return;
            clearInterval(statsTimer);
            statsTimer = null;
         }
