window.transitionend = 'webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend';

window.on_transitionend = function($element, do_function) {
  if (Modernizr.csstransitions) {
    $element.on(window.transitionend, do_function);
  } else {
    do_function(false)
  }
};

$(function() {
  var $body = $('body');

  window.enable_touch_swipe = function(selector, function_swipe_left, function_swipe_right) {
    var touch_position_x = 0;
    var delta = 0;

    $body.on('touchstart', selector, function(event) {
      touch_position_x = event.originalEvent.touches[0].pageX;
    });

    $body.on('touchmove', selector, function(event) {
      delta = event.originalEvent.touches[0].pageX - touch_position_x;
    });

    $body.on('touchend', selector, function(event) {
      var width_trigger = 50;
      if (delta > width_trigger) {
        function_swipe_left($(this))
      } else if (delta < (width_trigger * -1)) {
        function_swipe_right($(this));
      }
      delta = 0;
    });
  };

  window.document_height = $(document).height();
  window.window_height = $(window).height();
  window.window_width = $(window).width();
  window.scroll_top = $(window).scrollTop();

  $(window).on('scroll', function(event) {
    window.scroll_top = $(window).scrollTop();
  });

  $(window).on('resize', function(event) {
    window.document_height = $(document).height();
    window.window_height = $(window).height();
    window.window_width = $(window).width();
  });
});