// Test for minimal Javascript required by Drupal.
if (document.getElementsByTagName && document.createElement && document.createTextNode && document.documentElement && document.getElementById) {
  var DrupalEmbed = DrupalEmbed || [];
  DrupalEmbed[DrupalEmbed.length] = {
    src: "http://www.adfini.com/embed-widgets/content/iframe/1-YWRXSHB1V3U3WjFUay5hZGZpbmkuY29t?embed_widgets_mode=1", 
    wid: "1-YWRXSHB1V3U3WjFUay5hZGZpbmkuY29t", 
    width: 300, 
    height: 380  };
  
  for (var i in DrupalEmbed) {
    if (!DrupalEmbed[i]['processed']) {
      DrupalEmbed[i]['processed'] = true;
      
      var separator = DrupalEmbed[i].src.indexOf('?') == -1 ? '?' : '&';
      
      if(undefined===window.widget_count){
        window.widget_count = 0;
      }
      else {
        widget_count++;
      }
      
      var script = document.getElementById('drupal-embed-script-' + DrupalEmbed[i].wid);
      script.setAttribute('id', 'drupal-embed-script-' + DrupalEmbed[i].wid + widget_count);
      
      var iframe = document.createElement('iframe');
      iframe.setAttribute('id', 'drupal-embed-' + widget_count);
	  iframe.setAttribute('name', 'drupal-embed-' + widget_count);
      iframe.setAttribute('frameBorder', '0');
      iframe.setAttribute('marginheight', '0');
      iframe.setAttribute('marginwidth', '0');
      iframe.setAttribute('allowTransparency', 'true');
      iframe.setAttribute('backgroundColor', 'transparent');
      iframe.setAttribute('scrolling', 'no');
      iframe.setAttribute('width', DrupalEmbed[i].width);
      iframe.setAttribute('height', DrupalEmbed[i].height);
      iframe.setAttribute('src', DrupalEmbed[i].src + separator + 'embed_widgets_id=' + DrupalEmbed[i].wid);
      
      iframe.onload = function () {
			var iframeDocument = this.contentDocument ? this.contentDocument : (this.contentWindow ? this.contentWindow.document : null);
			if (iframeDocument) {
				try
				{
					var height = iframeDocument.height || iframeDocument.body.scrollHeight || null;
				}
				catch(e)
				{
					var height = null;
				}
				if (height) {
					this.setAttribute('height', (380) + 'px');
				}
			}
		}
		script.parentNode.insertBefore(iframe, script);
    }
  }
}
