$(document).ready(function() {
    if ($("#slide img").length%2!=0){
        $("#slide").append( $("#slide").html()  );
    }
    $("#slide img:even").addClass("even");
    $("#slide img:odd").addClass("odd");

    $("#slide img").each(function(i){
        var order = $("#slide img").length-i;
        $(this).css("z-index",order);
    });
    slideImg($("#slide img:first"));
});

function slideImg(el){
  var slideAmount = parseFloat(el.height())-434;
  if( el.is(".even") ){
      el.animate({bottom: -slideAmount+"px"},12000,function(){
          $(this).fadeOut("slow",function(){
              $(this).css("bottom","0");
          });
          showNext($(this));
      });
  } else {
      el.animate({top: -slideAmount+"px"},12000,function(){
          $(this).fadeOut("slow",function(){
              $(this).css("top","0");
          });
          showNext($(this));
      });
  }  
}

function showNext(el){
  if( el.next().is("img") ){
      slideImg( el.next() );
  } else { 
      $("#slide img:first").fadeIn("slow",function(){
          $("#slide img").show();
          slideImg($(this));    
      });
  }
}

