


var currentImage = 0;
var numLogos = 0;

function rotateImage() {
  
    
  if (window.currentImage + 1 == window.numLogos) {
    window.currentImage = 0;
  } else {
    window.currentImage = window.currentImage + 1;
  }
  
  jQuery('ul.logos li').removeAttr('style');
  jQuery('ul.logos .next_image').removeClass('next_image');
  
  
  jQuery.nextImage = jQuery('ul.logos li:eq('+window.currentImage+')');
  jQuery.currentImage = jQuery('ul.logos .current_image');
  
  if ( !jQuery.nextImage.hasClass('current_image') ) {
  
    jQuery.nextImage.addClass('next_image');
    
    jQuery.currentImage.delay(50).fadeOut('slow', function(){

      jQuery('ul.logos .current_image').removeClass('current_image');
      
      //jQuery.currentImage.removeClass('current_image');
      jQuery.nextImage.removeClass('next_image').addClass('current_image');
      
    })
  
    
    
        
  
  }
  

}




function displayLogos(images, maxSize, speed) {
  
  //maxSize = 150
  
  /* Get Image Size */
  
  style = "width:" +maxSize +"px; height: "+maxSize+"px;"; 
  
  output = "<ul class='logos' style='"+style+"'>"; 
    
    count = 0;    
    for(var i in images) {
    

    
      imagePath = images[i][0];
      width = images[i][1];
      height = images[i][2];
      
      /* Resize Image */
      if (width < height) {
        scale = maxSize / height;
        orientation = 'portrait';
      } else {
        scale = maxSize / width;
        orientation = 'landscape';
      }
      
      newWidth = Math.round(width * scale);
      newHeight = Math.round(height * scale);
      
      padding = 0;
      if (orientation == 'portrait') {
        padding = (maxSize - newWidth) / 2
        padding = Math.round(padding)
        
        paddingStyleStr = "style='margin: 0 "+padding+"px;'";
      } else {
        padding = (maxSize - newHeight) / 2
        padding = Math.round(padding)
        paddingStyleStr = "style='margin: "+padding+"px 0;'";
      
      }
      
      
      
      if (count == 0) {
        output = output + "<li class='current_image'>";
      } else {
        output = output + "<li>";      
      }
      
      output = output + "<img "+paddingStyleStr+" src='"+imagePath+"' width='"+newWidth+"px' height='"+newHeight+"px' /></li>"; 
     
    
    count = count + 1;
    }

    
    output = output + "</ul>";
  
    document.write(output);
    
    window.numLogos = count;
    
    setInterval("rotateImage();", speed);

}
