function resetSlide2() {
  $("#home-banner-slide-2 div.bg").css("opacity", 0.0).css("display", "block");
  $("#home-banner-slide-2 div.section").css("top", 200);
  $("#home-banner-slide-2a div.hand").css("left", 50).css("top", -131);
  $("#home-banner-slide-2b div.left-hand").css("top", 0);
  $("#home-banner-slide-2c div.screen").css("opacity", 1);
}

function animateSlide2() {
  $("#home-banner-slide-2a").animate({top: 0}, 1000, function() {
    $("#home-banner-slide-2a div.bg").animate({opacity: 0.3}, 500, function() {
      $("#home-banner-slide-2a div.hand").animate({top: 0, left: 80}, 1000, function(){
        $("#home-banner-slide-2b").animate({top: 0}, 1000, function() {
          $("#home-banner-slide-2b div.bg").animate({opacity: 0.3}, 500, function() {
            $("#home-banner-slide-2b div.left-hand").animate({top: 20}, 500, function(){
              $("#home-banner-slide-2c").animate({top: 0}, 1000, function() {
                $("#home-banner-slide-2c div.bg").animate({opacity: 0.3}, 500, function() {
                  $("#home-banner-slide-2c div.screen").animate({opacity: 0}, 1000, function() {
                    $("#home-banner").cycle("resume");
                  });
                });
              });
            });
          });
        });
      });
    });
  });
}

$(window).load(function() {
  var banner =  $("#home-banner");
  
  if($.browser.msie && $.browser.version <= 7) {
    $("#home-banner-start").css("display", "none");
    $("#home-banner-slide-1").fadeIn(1000);
  } else {
    
    banner.cycle({
      timeout: 6000,
      before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
        var id = $(nextSlideElement).attr("id");
        
        if(id == "home-banner-slide-2") {
          resetSlide2();
        }
        
        if(id != "home-banner-slide-1" && id != "home-banner-slide-2") {
          $(this).css("background-position", "0px 0px");
          $(this).animate({backgroundPosition: "0px -50px"}, { queue: false, duration: 7000 });
        }
      },
      after: function(currSlideElement, nextSlideElement, options, forwardFlag) {
        var id = $(nextSlideElement).attr("id");
        if(id == "home-banner-slide-1") {
          banner.cycle("pause");
        } else if(id == "home-banner-slide-2") {
          banner.cycle("pause");
          animateSlide2();
        } else {
          banner.cycle("resume"); 
        }
      }
    });
    
    banner.cycle("pause");
    
    $("#home-banner-start").click(function() {
      banner.cycle("next");
      banner.cycle("resume");
      return false;
    });
  }
});
