//	Tim Wood & Steve Stoft - Nov 23, 2008
/*
---------------------------------------------------------------
US Energy Use Converted to Gasoline Gallon Equivalents
721 solar,        7,124 wind
36,582 hydro,      30,456 nuclear
650,123 fossil (natural gas, oil, coal, gasoline)
[restart now]  [from Jan 1]  [info]
---------------------------------------------------------------

This script just checks for the zfacts link and then creates
the iframe holding the gizmo.  All gizmo logic is in a
separate file.
*/

/* Declare config vars */
var zF22_colorClean;
var zF22_color2;
var zF22_colorDirty;
var zF22_textColor;
var zF22_bgColor;
var zF22_borderColor;
var zF22_textSize;
var zF22_cps;
var zF22_width;
var zF22_height;
var zF22_id;
var zF22_tall;


function zF22_setVars() {
	var params = "";
	var param_array = new Array("colorClean", "color2", "colorDirty",
			"textColor", "bgColor", "borderColor", "textSize",
			"cps", "width", "height", "tall");
	for(var j=0; j<param_array.length; j++) {
		var param_str = "zF22_" + param_array[j];
		var param_ptr = eval(param_str);
		if(typeof(param_ptr) != 'undefined') {
			params = params + param_array[j] + "=" + param_ptr + "&";
		}
	}
	
	return escape(params);
}

function zF22_createIframe (iframeName) {
	var iframe;
	var baseUrl = "http://zfacts.com/giz";
	var gizUrl = "/G22/G22iframe"; //.html is added later
	/* Default is tall mode */
	var width="150px"; /* Default Width */
	var height="90px"; /* Default Height */
	var borderColor="#000"; /* Default Border Color */
	if(typeof(zF22_tall) != 'undefined') {
		if(zF22_tall)	
			gizUrl = gizUrl + "-tall.html?";
		else { /* Wide mode size */
			gizUrl = gizUrl + ".html?";
			width="195px";
			height="55px";
		}
	}
	else { // Default to tall mode
		gizUrl = gizUrl + "-tall.html?";
	}
	if(typeof(zF22_width) != 'undefined') {
			width = zF22_width;
	} else {
		zF22_width = width;
	}
	if(typeof(zF22_height) != 'undefined') {
			height = zF22_height;
	} else {
		zF22_height = height;
	}
	if(typeof(zF22_id) == 'undefined') {
			zF22_id = 1;
	}
	if(typeof(zF22_borderColor) != 'undefined') {
			borderColor = zF22_borderColor;
	}
	
	var params = zF22_setVars();
	//alert(unescape(params));
		
	if (document.createElement && (iframe =
		document.createElement('iframe'))) {
			iframe.id = iframeName;
			iframe.name = iframeName;
			iframe.src = baseUrl + gizUrl + params;
			iframe.frameBorder = "0";
			iframe.border = "0";
			iframe.vspace="0";
			iframe.hspace="0";
			iframe.marginwidth="0";
			iframe.marginheight="0";
			iframe.width=width;
			iframe.scrolling="no";
			iframe.height=height;
			iframe.style.border="1px solid " + borderColor;
			//document.getElementById("ZF22_" + zF22_id).appendChild(iframe);
			var link = document.getElementById("ZF22_" + zF22_id);
			link.parentNode.replaceChild(iframe, link);
		}
}

function zF22_validate(rPage) {
	var self = this;
	var rPage = "http://zfacts.com/p/green-energy.html";
	var Lnks="";
	var links=document.getElementsByTagName('a');
	for(i=0; i<links.length; i++)
	{ Lnk=links[i].href.toLowerCase();
		if(Lnk==rPage)
		{ var txt=links[i].innerHTML;
			if(txt.length > 0 && txt!=' ')
			{ 
				self.ok=true;
				break;
			}
		}
	}
	if(!self.ok) {
		setTimeout(zF22_validate, 250);
		//alert("No link to " + rPage);
	}
	else {
		zF22_createIframe("G22");
	}
}

//document.write("<span id=ZF22_" + zF22_id + "></span>");
zF22_validate();
