PartnerImages = function() {
    this.bigDiv = null;
    this.smallDiv = null;
    this.images = null;
    this.imageStates = new Object(); 
    this.bigImages = new Array();
    this.smallImages = new Array();
    this.nbSmallImages = 14;
    this.animate = false; 
}

PartnerImages.prototype =
          {
              Load: function(images, bigDiv, smallDiv, nbSmall, animate) {
                  this.bigDiv = document.getElementById(bigDiv);
                  this.smallDiv = document.getElementById(smallDiv);
                  this.images = images;
		this.nbSmallImages = nbSmall;
		this.animate = animate;
                  this.CheckImages();
                  this.ResetImageStates();
              },
              ResetImageStates: function() {
                  this.imageStates.states = new Array();
                  this.imageStates.length = this.smallImages.length;
                  this.imageStates.shown = 0;

                  for (var i = 0; i < this.smallImages.length; i++) {
                      this.imageStates[i] = 0;
                  }
              },
              GetRandomImageIndex: function() {
                  if (this.imageStates.shown == this.imageStates.length) {
                      this.ResetImageStates();
                  }
                  rn = Math.floor(Math.random() * this.imageStates.length);
                  while (this.imageStates.states[rn] == 1) {
                      rn++;
                      if (rn >= this.imageStates.length) rn = 0;
                  }

                  this.imageStates.shown++;
                  this.imageStates.states[rn] = 1;                    
                  return rn; 
              },
              ContinueLoad: function() {
                  for (i = 0; i < images.length; i++) {
                      if (images[i].fixed == 1) {
                          this.bigImages.push(images[i]);
                      } else {
                          this.smallImages.push(images[i]);
                      }
                  }

                  this.CreateFixedImages();
                  this.CreateSmallImages();
              },
              CreateFixedImages: function() {
                  html = "";
                  for (i = 0; i < this.bigImages.length; i++) {
                      im = this.bigImages[i];
                      html += "<A href='" + im.url + "'><IMG style='Image' class='large' src='" + im.image + "'></a>";
                  }

                  this.bigDiv.innerHTML = html;
              },
              CreateSmallImages: function() {
                  html = "";
                  for (var i = 0; i < this.smallImages.length && i < this.nbSmallImages; i++) {
                      rn = this.GetRandomImageIndex();
                      im = this.smallImages[rn];
                      html += "<A href='" + im.url + "'><IMG style='Image' class='small' src='" + im.image + "'></a>";
                  }

                  this.smallDiv.innerHTML = html;
                  
                  var self = this;
                  if (this.animate)
		{
		var CreateSmallImagesFunctionContinue = function() 
		{
                       self.CreateSmallImages(); 
		      $("#" + self.smallDiv.id).animate({opacity:1},'fast'); //fadeIn('slow');
		}

                  var CreateSmallImagesFunction = function() {
                        $("#" + self.smallDiv.id).animate({opacity:0.0},'fast', CreateSmallImagesFunctionContinue); // fadeOut('slow',CreateSmallImagesFunctionContinue );
                   }
                  setTimeout(CreateSmallImagesFunction , 5000);
		} else
		{
		var CreateSmallImagesFunctionContinue = function() 
		{
                       self.CreateSmallImages(); 
		}

                  setTimeout(CreateSmallImagesFunctionContinue , 5000);

		}

              },
              CheckImages: function() {

                  var i = 0;
                  var okCheckImages = false;
                  okCheckImages = true;
                  var self = this;
                  for (var i = 0; i < this.images.length; i++) {
                      var icon = this.images[i];
                      if (icon != null && icon.url != null) {
                          if (icon.img == null) {
                              var image = new Image();
                              image.src = icon.image;
                              icon.img = image;
                              okCheckImages = false;
                          } else {
                              if (icon.img.complete != true) {
                                  okCheckImages = false;
                              }
                          }
                      }
                  }

                  var self = this;
                  var CheckImageFunction = function() {
                        self.CheckImages();
                  };

                  if (okCheckImages == false) {
                      setTimeout(CheckImageFunction, 100);

                  } else {
                      this.ContinueLoad();
                  }
              }
          }

             