Modernizr.addTest('ipad', function () {
  return !!navigator.userAgent.match(/iPad/i);
});

Modernizr.addTest('iphone', function () {
  return !!navigator.userAgent.match(/iPhone/i);
});

Modernizr.addTest('ipod', function () {
  return !!navigator.userAgent.match(/iPod/i);
});

Modernizr.addTest('appleios', function () {
  return (Modernizr.ipad || Modernizr.ipod || Modernizr.iphone);
});

Modernizr.addTest('positionfixed', function () {
    var test = document.createElement('div'),
        control = test.cloneNode(false),
        fake = false,
        root = document.body || (function () {
            fake = true;
            return document.documentElement.appendChild(document.createElement('body'));
        }());

    var oldCssText = root.style.cssText;
    root.style.cssText = 'padding:0;margin:0';
    test.style.cssText = 'position:fixed;top:42px';
    root.appendChild(test);
    root.appendChild(control);

    var ret = test.offsetTop !== control.offsetTop;

    root.removeChild(test);
    root.removeChild(control);
    root.style.cssText = oldCssText;

    if (fake) {
        document.documentElement.removeChild(root);
    }

    /* Uh-oh. iOS would return a false positive here.
* If it's about to return true, we'll explicitly test for known iOS User Agent strings.
* "UA Sniffing is bad practice" you say. Agreeable, but sadly this feature has made it to
* Modernizr's list of undectables, so we're reduced to having to use this. */
    return ret && !Modernizr.appleios;
});

(function ($) {

  Drupal.behaviors.fkf = {
    attach: function (context, settings) {

      // Handle BG & Window resizing

      $(window, context).resize(function() {

        var screen_width = $(window).width();
        var screen_height = $(window).height();
        var screen_ratio = screen_width / screen_height;

        var img_ratio = 2160 / 1024;

        if ( img_ratio >= screen_ratio ) {
          $('body').removeClass('fkfbgw');
          $('body').addClass('fkfbgh');
        }
        else {
          $('body').removeClass('fkfbgh');
          $('body').addClass('fkfbgw');
        }


      });
      $(window, context).resize();

      // ANIMATE BLOCKS FROM LEFT SIDEBAR

      if ( $('body').hasClass('front') ) {

        $(document).ready(function () {
          $('#sidebar-first .block').hide();
        });

        $(window).load(function () {
          window.setTimeout(function () {
            $('#sidebar-first .block').each(function () {
              var block = this;
              $('#sidebar-first').queue('fkfqueue', function (next) {
                $(block).fadeIn(500, function () { next(); });
              });
            });
            $('#sidebar-first').dequeue('fkfqueue');
          }, 1000);
        });

      }


      // MOVE BGs to body bg for iPad and such
      $('html.no-positionfixed body').css({
        'background': '#5BABDC url('+ $('#background img').attr('src') +') fixed no-repeat top left',
        'background-size': 'cover'
      });
      $('html.no-positionfixed #background').remove();




    }
  };

}(jQuery));;

