var amul = 1;
var aw = 100;
$(document).ready(function () {
  aw = $('#mainPageContents').width();
  var left = parseInt($('#mainPageContents').css('left'));

  
  setTimeout(function () { animate1(); }, 200*amul);
  setTimeout(function () { animate2(); }, 42000 * amul);
  setTimeout(function () { animate3(); }, 100000 * amul);
  setTimeout(function () { animate4(); }, 150000 * amul);

  if(typeof(Bird) != "undefined"){ // no birds if eagle script is not loaded
    setTimeout(function () { animateBirds(); }, 100*amul);
    Bird.init(aw + 150, 400);
    setTimeout(function () { Bird.animate(6500); }, 25000);
  }
});

function animateBirds() {
   var birds = $('#abirds');
   start = ($(window).width() < aw) ? $(window).width() + 20 : aw + 20;
   end = start / 2 - 80;
   birds.show();
   birds.css('left', start).sprite({ fps: 2, no_of_frames: 2 })
     .animate({ left: start * 0.75 }, 10000 * amul, "linear")
     .animate({ left: start * 0.55, bottom: 25 }, 10000 * amul, "linear")
     .animate({ left: end, bottom: 0, opacity: 0 }, 5000 * amul, "linear", function () {
       birds.css('left', start).css('bottom', 65).css('opacity', 1);
       birds.hide();
       setTimeout(animateBirds, 120000 * amul);
     });
}

 function animate1() {
   var cloud = $('#acloud1');
   cloud.animate({ left: aw }, 190000 * amul, "linear", function () {
     cloud.css('left', "-300px");
     setTimeout(animate1, 200 * amul);
   });
}

function animate2() {
  var cloud = $('#acloud2');
  cloud.animate({ left: aw }, 160000 * amul, "linear", function () {
    cloud.css('left', "-300px");
    setTimeout(animate2, 200 * amul);
  });
}

function animate3() {
  var cloud = $('#acloud3');
  cloud.animate({ left: aw }, 130000 * amul, "linear", function () {
    cloud.css('left', "-300px");
    setTimeout(animate3, 200 * amul);
  });
}

function animate4() {
  var cloud = $('#acloud4');
  cloud.animate({ left: aw }, 120000 * amul, "linear", function () {
    cloud.css('left', "-300px");
    setTimeout(animate4, 200 * amul);
  });
}


