$(document).ready(function () {
  $(".initialFadeIn").fadeIn(1000);
  if ($.browser.msie) {
    $(".regionSelect").css({opacity: 0});
  }
  $(".regionSelect").click( function() {
    gotoRide($(this));
    return false;
  });
  
  $(".regionSelect").each(function(i) {
    var $this = $(this);
    
    $this.data("trail", $this.next(".trail").detach().attr("href"));
    $this.data("race", $this.next(".race").detach().attr("href"));
    $this.animate({
      top: i * 20,
      opacity: 1
    }, 1000, "easeInCirc");
  });

  function gotoRide($a) {
    $("#xtr_logotag").animate({top: 30}, {
      duration: 200,
      queue: false,
      complete: function () {
        var locale = "";
        if ($a.attr("rel")) {
          locale = $a.attr("rel") + "/";
        }

        $("#choose_text").attr("src", "images/" + locale + "choose-style.png");
        $("#choose_race img").attr("src", "images/" + locale + "choose-race.png");
        $("#choose_trail img").attr("src", "images/" + locale + "choose-trail.png");
        $("#choose_race, #left_arrow").attr("href", $a.data("race"));
        $("#choose_trail, #right_arrow").attr("href", $a.data("trail"));

        $("#select_region").animate({opacity: 0},{
          queue: false,
          duration: 500,
          easing: "easeOutCirc"
        });
        
        $("#bgimage").animate({opacity: 0}, {
          queue: false,
          duration: 500,
          easing: "easeOutCirc"
        });

        $("#choose_trail").show().css({opacity: 0}).animate({opacity: 1}, {
          queue: false,
          duration: 700
        });
        
        $("#choose_race").show().css({opacity: 0}).animate({opacity: 1}, {
          queue: false,
          duration: 700
        });

        $("#choose_style").show().css({opacity: 0}).animate({opacity: 1}, {
          duration: 500,
          complete: function () {
            var v=90;
            $(".blink_arrow").fadeOut(v).fadeIn(v).fadeOut(v).fadeIn(v).fadeOut(v).fadeIn(v);
          }
        });
      }
    });
  }
});