(function() { //Anonymous function prevents pollution of the global namespace.
	var prefix = 'education_com-schlfndr';
	//CSS Injection
	var headid    = document.getElementsByTagName("head")[0],
	    cssnode   = document.createElement('link');
	cssnode.type  = 'text/css';
	cssnode.rel   = 'stylesheet';
	cssnode.href  = 'http://www.education.com/widget/schoolFinderFlash/widget.css.php?bg=bee4f1&wrap=education_com-schlfndr&size=standard&previewCss=';
	cssnode.media = 'screen';
	headid.appendChild(cssnode);
	    
	//Generate New Elements
	var par = document.getElementById(prefix);
	if (!par) { return false; }
	var objel  = document.createElement('div'),
	    linkel = document.createElement('div'),
	    gyo    = document.createElement('div');
	gyo.id = prefix+'-gyo';
	gyo.innerHTML = '<a href="http://www.education.com/schoolfinder/tools/localschools-widget/">Get Your Own Widget</a>';
	linkel.innerHTML = par.innerHTML+'<div style="clear:both; margin:0;"></div>';
	linkel.id = prefix+"-lnks";
	par.innerHTML = ""; //Clear the wrapper div, since the links have been copied to linkel.
	if (!headid) par.appendChild(cssnode);

	//Flash Injection
	objel.innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flashswflash.cab#version=10,9,8,0' width='300' height='440'><param name='movie' value='http://www.education.com/swf/widget/medium.swf' /><param name='flashvars' value='map_key=ABQIAAAAzsL4atS5Q5qfH_yiPsycvRQZIST_u97KSn7jO7X0-xnXiVw8WhRZ2VAF343fURdsVUl1GAL_ofKXjA&host_name=www.education.com&widget_searchterm=palm+harbor++FL&widget_key=2698ebd370b94977f7705335f905837f&search_type=searchbyaddress' /><param name='quality' value='high' /><embed src='http://www.education.com/swf/widget/medium.swf' flashvars='map_key=ABQIAAAAzsL4atS5Q5qfH_yiPsycvRQZIST_u97KSn7jO7X0-xnXiVw8WhRZ2VAF343fURdsVUl1GAL_ofKXjA&host_name=www.education.com&widget_searchterm=palm+harbor++FL&widget_key=2698ebd370b94977f7705335f905837f&search_type=searchbyaddress' quality='high' pluginspage='http://www.adobe.com/shockwave/download/download.cgi?p1_prod_version=shockwaveflash' type='application/x-shockwave-flash' width='300' height='440'></embed></object>";
	
	//Inject newly-created elements into the wrapper div.
	par.appendChild(objel);
	par.appendChild(linkel);
	par.appendChild(gyo);

	//Dynamically add classes to the links. This reduces the code to copy/paste.
	var links = linkel.getElementsByTagName('a');
	//Makes sure the three links specified in the widget code are present.
	if (links.length > 1) {
		links[0].className = "education_com-schlfndr-lnk";
		for (var i=1;i<links.length;i++) { links[i].className = "education_com-schlfndr-schlnk"; }
	} else {
		//This is where a user could be reported for removing SchoolFinder links
		//from widget code.
	}

})();
