/**
 * This is part of a patch to address a jQueryUI bug.  The bug is responsible
 * for the inability to scroll a page when a modal dialog is active. If the content
 * of the dialog extends beyond the bottom of the viewport, the user is only able
 * to scroll with a mousewheel or up/down keyboard keys.
 *
 * @see http://bugs.jqueryui.com/ticket/4671
 * @see https://bugs.webkit.org/show_bug.cgi?id=19033
 * @see /views_ui.module
 * @see /js/jquery.ui.dialog.min.js
 *
 * This javascript patch overwrites the $.ui.dialog.overlay.events object to remove
 * the mousedown, mouseup and click events from the list of events that are bound
 * in $.ui.dialog.overlay.create
 *
 * The original code for this object:
 * $.ui.dialog.overlay.events: $.map('focus,mousedown,mouseup,keydown,keypress,click'.split(','),
 *  function(event) { return event + '.dialog-overlay'; }).join(' '),
 *
 */

(function ($, undefined) {
  if ($.ui && $.ui.dialog) {
    $.ui.dialog.overlay.events = $.map('focus,keydown,keypress'.split(','),
                                 function(event) { return event + '.dialog-overlay'; }).join(' ');
  }
}(jQuery));
;
(function ($) {

showDoor = function() {
  $("#skip").animate({opacity:1}, 1000);
  $("#door-closed").animate({opacity:1}, 750).delay(800).queue(openDoor);
}
openDoor = function() {
  $(this).dequeue();
  $("#door-open").animate({opacity:1}, 400).delay(1000).queue(hideDoor);
}  
hideDoor = function() {
  $(this).dequeue();
  $("#door-closed").remove();
  $("#door-open").animate({opacity: 0}, 700, showYOU);
}
showYOU = function() {
  $("#door-open").remove();
  $("#YO").animate({opacity: 1}, 500);
  $("#U").animate({opacity: 1}, 500, showTimes);
}
showTimes = function() {
//  $("#times").css({opacity: 1});
  $("#x-small").animate({opacity: 1}, 500, showUS);
}  
showUS = function() {
  $("#US").animate({opacity: 1}, 500).delay(500).queue(transformUXUS1);
}  
transformUXUS1 = function() {
  $(this).dequeue();
  $("#YO").animate({opacity: 0, left:"-=86"}, 700);
  $("#U").animate({left:"-=86"}, 700);
  $("#x-small-light").animate({ opacity:1 }, 700);  
  $("#times").animate({left:"+=27"}, 700, transformUXUS2);  
}
transformUXUS2 = function() {
  $("#YO").hide();
  $("#U").animate({top:"+=51"}, 600);
  $("#x-big").animate({opacity:1}, 600).delay(600).queue(showSlide1a);
}
showSlide1a = function() {
  $(this).dequeue();
  $("#intro-slide-1a").animate({opacity:1}, 500).delay(1000).queue(showSlide1b);
}
showSlide1b = function() {
  $(this).dequeue();
  $("#intro-slide-1b").animate({opacity:1}, 500).delay(2500).queue(showSlide2a);
}
showSlide2a = function() {
  $(this).dequeue();
  $("#intro-slide-1a").animate({opacity:0}, 500);
  $("#intro-slide-1b").animate({opacity:0}, 500);  
  $("#intro-slide-2a").delay(500).animate({opacity:1}, 500).delay(2000).queue(showSlide2b);
}
showSlide2b = function() {
  $(this).dequeue();
  $("#intro-slide-2b").animate({opacity:1}, 500).delay(4000).queue(showSlide3a);
}
showSlide3a = function() {
  $(this).dequeue();
  $("#intro-slide-2a").animate({opacity:0 }, 500);
  $("#intro-slide-2b").animate({opacity:0 }, 500);  
  $("#intro-slide-3a").delay(500).animate({opacity:1}, 500).delay(700).queue(showSlide3b);
}
showSlide3b = function() {
  $(this).dequeue();
  $("#intro-slide-3b").animate({opacity:1}, 500).delay(3500).queue(hideSlide3);
}
hideSlide3 = function() {
  $(this).dequeue();
  $("#intro").animate({opacity:0 }, 600, endIntro);  
}
endIntro = function() {
  window.location = 'work';
}

skipIntro = function() {
  $("#intro").animate({opacity:0 }, 400, endIntro);  
}  

$(window).load(function()
{
  // set jquery animation refresh rate
  $.fx.interval = 30;
  // start the first move of the intro animation
  showDoor();  
});

})(jQuery);
;

