var g_images = [];
var g_slideIndex = 0;

function showSlide()
{
  $('imgItem').hide();

  var height = 166;
  var width = ( height / g_images[ g_slideIndex ].height ) * g_images[ g_slideIndex ].width;

  $('imgItem').src = g_images[ g_slideIndex ].src;
  $('imgItem').width = width;
  $('imgItem').height = height;

  $('imgItem').show();
  
  g_slideIndex++;
  if ( g_slideIndex >= g_images.length )
    g_slideIndex = 0;
}

new Ajax.Request( 'xml/images.xml', { 
  method: 'get',
  onSuccess: function( transport ) {
    var imageTags = transport.responseXML.getElementsByTagName( 'image' );

    for( var b = 0; b < imageTags.length; b++ ) {
      g_images.push( {
        src: imageTags[b].getAttribute('src'),
        width: imageTags[b].getAttribute('width'),
        height: imageTags[b].getAttribute('height')
      } );
    }
    
    showSlide();
    
    window.setInterval( showSlide, 5000 );
  }
} );