widgetContext = { "wid": "efc8f6beec08b5222bd4a66de4ff7556-24", "url": "http://widgets.chalkpartners.com/embed-widgets/efc8f6beec08b5222bd4a66de4ff7556-24/content/", "width": "300", "height": "250", "jquery": "http://widgets.chalkpartners.com/misc/jquery.js", "new_placement": "http://widgets.chalkpartners.com/embed-widgets/js/get-code/%252F", "base_url": "http://widgets.chalkpartners.com/" }
// $Id: iframe.js,v 1.7.2.3 2009/09/09 03:08:02 jtsnow Exp $

// Test for minimal Javascript required.
if (document.getElementsByTagName && document.createElement && document.createTextNode && document.documentElement && document.getElementById) {

	if (navigator.appName == 'Microsoft Internet Explorer') {
		IE = true;
	} else {
		IE = false;
	}

	var DrupalEmbed = DrupalEmbed || [];
	DrupalEmbed[DrupalEmbed.length] = {
	  src: widgetContext['url'],
	  wid: widgetContext['wid'],
	  width: widgetContext['width'],
	  height: widgetContext['height'],
	  new_placement: widgetContext['new_placement'],
	  newID: false,
	  base_url: widgetContext['base_url']
	};
	
	if (typeof embedWidgetInsert == 'undefined') {
	  embedWidgetInsert = function () {
			
		  for (var i in DrupalEmbed) {
				
		    if (!DrupalEmbed[i]['processed']) {
		      DrupalEmbed[i]['processed'] = true;
		      
		      // Keep track of how many widgets are embedded in this document.
		      if(undefined===window.widget_count){
		        window.widget_count = 0;
		      }
		      else {
		        widget_count++;
		      }

					
		      // Use unique ID for each widget on the page.
		      var script = document.getElementById('widget-embed-script-' + DrupalEmbed[i].wid);
					if (script) {
						script.setAttribute('id', 'widget-embed-script-' + DrupalEmbed[i].wid + widget_count);
						
						var extraFlashVars = '';
						// Test for '?' in script source string. Signalling extra flashVars have been appended.
						if (script.src.indexOf('?') != -1) {
							// If '?' exists, grab substring after '?' to end.
							extraFlashVars = '&' + script.src.substring(script.src.indexOf('?') + 1);
						}
	
						// widget_parent_swf_wrapper div
						var div = document.createElement('div');
						//div.setAttribute('id', 'widget-parent-swf-wrapper');
						if (!IE) {
							div.setAttribute('style', 'height:100px;left:-9999px;position:absolute;top:0px;width:100px;');
						} else {
							div.style.height = '100px';
							div.style.left = '-9999px';
							div.style.position = 'absolute';
							div.style.top = '0px';
							div.style.width = '100px';
						}
	
						var swfId = 'widget-parent-swf';
						var swfSrc = 'http://chalk-flash.s3.amazonaws.com/parent.swf'; //DrupalEmbed[0].base_url + 'parent.swf';
						var swfWidth = 200;
						var swfHeight = 100;
						var swfParams = {
							allowScriptAccess: 'always',
							flashVars: 'WID=widget-embed-wid-'+ DrupalEmbed[i].wid + '&myConnID=' + (navigator.userAgent + DrupalEmbed[i].wid).replace(/([^a-zA-Z0-9\-]+)/g, "").toLowerCase()
						};
						var obj = '<object' + ((window.ActiveXObject)? ' id="' + swfId + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" data="' + swfSrc + '"' : '');
								obj += ' width="' + swfWidth + '"';
								obj += ' height="' + swfHeight + '"';
								obj += '>';
						var param = '<param';
								param += ' name="movie"';
								param += ' value="' + swfSrc + '"';
								param += '>';
								param += '';
						var extraParams = '';
						var extraAttributes = '';
						for(var swfParam in swfParams){
							extraParams += '<param name="' + swfParam + '" value="' + swfParams[swfParam] + '">';
							extraAttributes += ' ' + swfParam + '="' + swfParams[swfParam] + '"';
						}
						var embed = '<embed id="' + swfId + '" src="' + swfSrc + '" type="application/x-shockwave-flash" width="' + swfWidth + '" height="' + swfHeight + '"';
						var embedEnd = extraAttributes + '></embed>';
						var objEnd = '</object>';
						div.innerHTML = obj + param + extraParams + embed + embedEnd + objEnd;
	
						// Insert div into document.
						script.parentNode.insertBefore(div, script);
						
						// Create iframe element.
						var iframe = document.createElement('iframe');
						iframe.setAttribute('id', 'widget-embed-' + widget_count);
						
						// IE and NOT IE8 
						if (IE && !(document.documentMode && document.documentMode == 8)) {
							iframe.setAttribute('className', 'widget-embed-wid-' + DrupalEmbed[i].wid);
						} else {
							iframe.setAttribute('class', 'widget-embed-wid-' + DrupalEmbed[i].wid);
						}
						iframe.setAttribute('frameBorder', '0');
						iframe.setAttribute('width', DrupalEmbed[i].width);
						iframe.setAttribute('height', DrupalEmbed[i].height);
						iframe.setAttribute('scrolling', 'no');

						var separator = DrupalEmbed[i].src.indexOf('?') == -1 ? '?' : '&';
						iframe.setAttribute('src', DrupalEmbed[i].src + separator + 'widgets_mode=' + DrupalEmbed[i].wid + extraFlashVars);
						
						// Insert iframe into document.
						script.parentNode.insertBefore(iframe, script);
					}
		    }
		  }
	  };
	}

	var headID = document.getElementsByTagName('head')[0]; 
	if (typeof widgetParentJS == 'undefined') {
		widgetParentJS = true;
		var widgetsScript = document.createElement('script');
		widgetsScript.type = 'text/javascript';
		widgetsScript.src = 'http://chalk-scripts.s3.amazonaws.com/widgets.js';
		headID.appendChild(widgetsScript);
	}

  embedWidgetInsert();
}
