/**
 * Set up gweb namespace if it doesn't exist already.
 */
var gweb = gweb || {};

/**
 * Partner icon rotator constructor.
 * @constructor
 */
gweb.PartnerIconRotator = function(arr, count, container) {
  this.partnerArray = arr;
  this.displayNumber = count;
  this.partnerIconContainer = gweb.dom.getElement(container);
};

/**
 * Returns a random number to be used when sorting arrays.
 * @return {number} will generate either -.5 or .5 .
 */
gweb.PartnerIconRotator.randOrd = function() {
  return (Math.round(Math.random()) - 0.5);
};

/**
 * Loops through supplied array when constructor is instantiated and generates a
 *     random sequence which is then used to generate icon/link output
 */
gweb.PartnerIconRotator.prototype.rotate = function() {

  this.partnerArray.sort(gweb.PartnerIconRotator.randOrd);
  var output = [];

  for (var i = 0; i < this.displayNumber; i++) {
    output.push('<a href="' + this.partnerArray[i]['link'] + '">');
    output.push('<img src="images/' + this.partnerArray[i]['icon']);
    output.push('" alt=""></a>');
  }
  this.partnerIconContainer.innerHTML = output.join('');
};

