/*----------------------------------------------------------

* File Name: global.js

----------------------------------------------------------*/
(function ($) {
    function setup_search(node /* HTML elements */ ) {
        var $this = $(node),
            $parent = $this.parent(),
            $grand_parent = $parent.parent(),
            //Create an array of the dom elements that will be animated on input focus / blur.
            $arr = [$this, $parent, $grand_parent];
        $this.focus(function () {
            animate_search($arr, true);
        });
        $this.blur(function () {
            animate_search($arr, false);
        });
    };
    function animate_search(node /* HTML elements */ , boo /* Boolean */ ) {
        var $arr = node,
            $truthy = boo || false;
        //Loop through the dom elements array and animate them
        for (i = 0, maximum = $arr.length; i < maximum; i += 1) {
            if ($truthy === true) { // If the var === true increase the width by 100px.
                $arr[i].animate({
                    "width": "+=" + 100
                }, {
                    queue: false
                }, 500);
            } else { // Else decrease the width by 100px.
                $arr[i].animate({
                    "width": "-=" + 100
                }, {
                    queue: false
                }, 500);
            }
        }
    };
    //Initiate the setup_search function with the dom element of choice.
    setup_search("div#footer-search input#s");
})(jQuery);
