﻿function popupopen(strLink, width, height) {
  window.open(strLink, 'pop', 'toolbar=no,menubar=no,width=' + width + ',height=' + height + ',scrollbars=1,top=0,left=90');
}

function BannerImage(xmlstring, position, imageid, linkid, time, buildersubdivisionid) {
  this.timer; 
  this.currentImageIndex = 0;
  this.xmlString = xmlstring;
  this.imageId = imageid;
  this.linkId = linkid;
  this.time = time;
  this.imagesXML = parseXML(this.xmlString);
  if (buildersubdivisionid != null && buildersubdivisionid != '') {
    this.images = $(this.imagesXML).find("image[position='" + position + "'][buildersubdivisionid='" + buildersubdivisionid + "']")
  }
  else {
    this.images = $(this.imagesXML).find("image[position='" + position + "']")
  }
  this.numberOfImages = $(this.images).length;
}

BannerImage.prototype.Start = function() {

  if (this.numberOfImages > 0) {
    this.UpdateImages();
  }
  else {
    $("#" + this.imageId).hide();
  }

}

BannerImage.prototype.UpdateImages = function() {

  var image = $(this.images).eq(this.currentImageIndex);
  $("#" + this.imageId).attr('src', $(image).attr("imagepath"));

  $("#" + this.linkId).attr({
    href: '', target: ''
  });

  $("#" + this.linkId).attr({
    href: $(image).attr("url"), target: $(image).attr("target")
  });

  if (this.currentImageIndex == this.numberOfImages - 1) {
    this.currentImageIndex = 0;
  }
  else {
    this.currentImageIndex += 1;
  }

  if (this.numberOfImages > 1) {
    var foo = this;
    this.timer = setTimeout(function() { foo.UpdateImages(); }, this.time);
  }

}


function parseXML(xml) {
  if (window.ActiveXObject && window.GetObject) {
    var dom = new ActiveXObject('Microsoft.XMLDOM');
    dom.loadXML(xml);
    return dom;
  }
  if (window.DOMParser)
    return new DOMParser().parseFromString(xml, 'text/xml');
  throw new Error('No XML parser available');
} 
