function Initialize_Gallery(currentVideo) {

  var configurationUrl = '/about/news/overlays/xml/gallery_configuration.xml';
  new Ajax.Request(configurationUrl, {
  method: 'get',
    onSuccess: function(transport) {
      this.gallery = new Gallery(transport.responseText, currentVideo);
    }
  }
  );
}

// ======== Gallery class ================
var Gallery = Class.create();
Gallery.prototype = {

  initialize: function(configXML, currentVideo){
  
    this.currentVideo = currentVideo;
    this.thumbs = [];
    
    this.jsonConfigSet = xml2json.parser(configXML);  
        
    this.thumbs = this.InitializeThumbs(this.jsonConfigSet);
    
    this.SetTitle();
    this.SetDescription(); 
  },

  InitializeThumbs: function (configSet) {
    
    var temp;
    var thumbCollection = [];
    var configSection;
    var currentThumb;
    
    if(!configSet.videodata.length) {
    
      configSection = this.jsonConfigSet.videodata;
      currentThumb = $('video0');
          
      temp = new Thumbnail(currentThumb, configSection);
      thumbCollection = thumbCollection.concat(temp); 
      
    } else {
      for(var i = 0; i < configSet.videodata.length; i++) {
          
          configSection = this.jsonConfigSet.videodata[i];
          currentThumb = $('video'+i);
          
          temp = new Thumbnail(currentThumb, configSection);
          thumbCollection = thumbCollection.concat(temp); 
        } 
    }
    
    return thumbCollection;
  },
  
  SetTitle: function() {
    $('gallery_title').innerHTML = (this.thumbs[this.currentVideo]).title;
  },
  
  SetDescription: function() {
    $('gallery_description').innerHTML = (this.thumbs[this.currentVideo]).description;
  }
}

// ======== Thumbnail class ================
var Thumbnail = Class.create();
Thumbnail.prototype = {

  initialize: function(element, videoConfigSection) {
 
    this.element = element;
    this.title = videoConfigSection.title;
    this.imageSrc = videoConfigSection.thumbimagesrc;
    this.description = videoConfigSection.description;
  
    this.SetImage();
    this.SetTitle();
    
  },
  
  SetImage: function  () {
    //Setup Image
    var children = getChildren(this.element);
    var firstChild = children[0];
    this.image = getChildren(firstChild)[0];
    this.image.src = this.imageSrc;
  },
  SetTitle: function () {
    //Setup title
    this.descElement = getChildren(this.element)[1];
    this.descElement.innerHTML = this.title;
  }
}

function getChildren(element) {
  
  var children = 0;
  
  if(element.children)
    children = element.children;
  else if(element.childNodes)
    children = element.childNodes;
  else
    children = [];
    
  var childrenNoWhiteSpace = [];
	for(var i = 0; i < children.length; i++) {
		if(children[i].nodeType != 3){
      childrenNoWhiteSpace = childrenNoWhiteSpace.concat(children[i]);
		}
	}
	return childrenNoWhiteSpace;
}
