/*
 * EzineArticles Widget v1.1
 *
 * Changes for v1.1 (03/13/09):
 *  Upgraded to jQuery 1.3.1
 *  Upgraded FlyDOM
 *
 * Notes:
 *  jQuery calls in this file should be called with the jQuery() and not $() or $j().
 *
 * Developers:
 *  jQuery does not like being called twice from the same page, so we have implemented
 *  a fix that should allow most pages to have the Widget and jQuery effects to peacefully
 *  coexist. As of 03/13/09, this script now checks for the "window.jQuery" namespace before
 *  it loads the library into the page.
 *
 *  This means that if you are adding the Widget to a page that has jQuery on it,
 *  you will want to include the <script> tags for the Widget AFTER you have loaded your
 *  copy of jQuery. If this is done, we will use your version and not load it again.
 *
 *  This method is compatible with jQuery 1.2 - 1.3.2, and most likely future-proof.
 */

if(!window.jQuery){
	document.write('<script type="text/javascript" src="http://ezinearticles.com/includes/js/jquery-1.3.1.min.js"></script>');
}
document.write('<script type="text/javascript" src="http://ezinearticles.com/includes/js/jquery-dom.js"></script>')
document.write('<link rel="stylesheet" href="http://ezinearticles.com/widget/inc_2/eawidget.css?v=280520081550" type="text/css" />\n');

function eawidget(obj) {
	var existing = getWidgetElementsByName('div', 'eawidget_container');
	var last_existing = existing.length;

	if (last_existing > 1) {
		document.write('<div>Sorry, EzineArticles only permits two widgets per page.</div>');
		return false;
	}
	if (last_existing > 0) {
		var div_container = obj.container + '_' + (last_existing + 1);
		var help_container = 'eawidget-about' + '_' + (last_existing + 1);
	} else {
		var div_container = obj.container;
		var help_container = 'eawidget-about';
	}
	var info_icon = '<div style="float:right"><a href="http://ezinearticles.com/widget/" target="blank" onmouseover="toggle_visibility(\'' + help_container + '\',\'\')" onmouseout="toggle_visibility(\'' + help_container + '\',\'\')" title="Information"><img src="http://ezinearticles.com/widget/gfx/help-sq.gif" width="14" height="14" alt="Information" /></a></div>';
	document.write('<div id="' + div_container + '" name="eawidget_container" class="eawidget eawidget-theme' + obj.theme + ' eawidget_container" style="width: ' + (obj.width - 9) + 'px; height: ' + (obj.height - 8) + 'px; border: 1px solid #' + obj.cborder + '; background-color: ' + obj.cbackground + '; overflow: hidden" >');
	document.write('<div id="' + help_container + '" class="eawidget-about" style="display:none; color:#000; width:' + (obj.width - 40) + 'px">This is the EzineArticles Widget.<br /><br />It can display EzineArticles articles published by any author or in any category.<br /><br />Click the information icon to get a widget for your website or blog.</div>');
	document.write('<div id="eawidget-header" class="eawidget-header" style="background-color: #' + obj.cheader + '"><div class="eawidget-innerheader" style="height: 12px"></div></div>');
	document.write('<div id="eawidget-topic" class="eawidget-topic" style="background: #' + obj.ctopic + '; color: #' + obj.ctopictext + '; border-bottom: 1px solid #' + obj.cheader + '; margin-top: 1px; overflow: hidden">.</div>');
	if (obj.bio > 0) {
		obj.height = (obj.height - 96);
	} else {
		obj.height = (obj.height - 45);
	}
	if (obj.gads > 0) {} else {
		obj.height = (obj.height - 25);
	}
	document.write('<ul id="eaul" class="eaul" style="height: ' + obj.height + 'px; margin:0;"></ul>');
	if (obj.type < 10) {
		if (obj.gads > 0) {}
	}
	if (obj.type < 10) {
		document.write('<script type="text/javascript">\n');
		document.write('<!--\n');
		document.write('    function toggle_visibility(id,lid) {\n');
		document.write('       var e = document.getElementById(id);\n');
		document.write('       if (lid) {\n');
		document.write('       	var l = document.getElementById(lid);\n');
		document.write('       }\n');
		document.write('       if(e.style.display == \'block\'){\n');
		document.write('          e.style.display = \'none\';\n');
		document.write('       	if (lid) {\n');
		document.write('        	  l.style.display = \'block\';\n');
		document.write('       	}\n');
		document.write('       }else{\n');
		document.write('          e.style.display = \'block\';\n');
		document.write('       	if (lid) {\n');
		document.write('          l.style.display = \'none\';\n}\n');
		document.write('       	}\n');
		document.write('    }\n');
		document.write('//-->\n');
		document.write('</script>\n');
		if (obj.type == 1) {
			jQuery('#' + div_container + ' div.eawidget-topic').html(info_icon + 'Recently Published Articles');
		} else if (obj.type == 2) {
			if (obj.bio == 1) {
				if (obj.authorpic != '') {
					jQuery('#' + div_container + ' div.eawidget-topic').html(info_icon + '<div id="topicinner" style="color: #000"><a href="http://ezinearticles.com/?expert=' + obj.authorlink + '" title="' + obj.stories[0].author + '" target="' + obj.widgettarget + '"><img style="float: left; margin: 0 5px 0 0" src="http://ezinearticles.com/members/mem_pics/small/' + obj.authorpic + '" alt="' + obj.stories[0].author + '" /></a>' + obj.authorbio + ' [<a href="http://ezinearticles.com/?expert=' + obj.authorlink + '" title="' + obj.stories[0].author + '" target="' + obj.widgettarget + '">Read more</a>]</div>');
				} else {
					jQuery('#' + div_container + ' div.eawidget-topic').html(info_icon + '<div id="topicinner" style="color: #000">' + obj.authorbio + ' [<a href="http://ezinearticles.com/?expert=' + obj.authorlink + '" title="' + obj.stories[0].author + '" target="' + obj.widgettarget + '">Read more</a>]</div>');
				}
			} else {
				if (obj.fcategory != '') {
					jQuery('#' + div_container + ' div.eawidget-topic').html(info_icon + '<div style="height: 15px">' + obj.fcategory + ' Articles by <a style="font-weight: 700; color: #000" href="http://ezinearticles.com/?expert=' + obj.authorlink + '" title="' + obj.stories[0].author + '" target="' + obj.widgettarget + '">' + obj.stories[0].author + '</a></div>');
				} else {
					jQuery('#' + div_container + ' div.eawidget-topic').html(info_icon + '<div style="height: 15px">Articles by <a style="font-weight: 700; color: #000" href="http://ezinearticles.com/?expert=' + obj.authorlink + '" title="' + obj.stories[0].author + '" target="' + obj.widgettarget + '">' + obj.stories[0].author + '</a></div>');
				}
			}
		} else if (obj.type == 3) {
			jQuery('#' + div_container + ' div.eawidget-topic').html(info_icon + obj.fcategory + ' Articles');
		}
		jQuery('#' + div_container + ' ul').html('');
		if (obj.type == 2) {
			var tpl = function() {
				return ['li', {
					'style': "border-bottom: 1px solid #" + obj.cdivider + ";"
				},
				['h3', {},
				['a', {
					'id': "href" + this.id,
					'class': "eawidget-title",
					'style': "text-decoration: none; font-weight: bold; color: #" + obj.ch3 + ";",
					'href': this.link,
					'target': obj.widgettarget
				},
				this.title], 'p', {
					'id': "l" + this.id,
					'style': "margin: 0 auto 0 auto; text-align: left; display: block"
				},
				['a', {
					'class': "easummary",
					'style': "text-decoration: none; font-weight: 400; letter-spacing: normal",
					'href': "javascript:toggle_visibility('" + this.id + "','l" + this.id + "');"
				},
				'<img src="http://ezinearticles.com/widget/gfx/ssummary.gif" width="7" height="7" alt="Show summary" /> View summary'], 'div', {
					'id': this.id,
					'style': "background-color: #fbfbfb; padding: 4px; display: none"
				},
				['p', {
					'class': "easummary",
					'style': "text-align: left;"
				},
				'<span>' + this.summary + '</span> [<a href="' + this.link + '" title="' + this.title + '" target="' + obj.widgettarget + '" style="text-decoration: none; font-weight: 400">continue</a>] <br /><a style="text-decoration: none; font-weight: 400" href="javascript:toggle_visibility(\'' + this.id + '\',\'l' + this.id + '\');" title="Hide summary"><img src="http://ezinearticles.com/widget/gfx/hsummary.gif" width="7" height="7" alt="Hide summary" /> Hide summary</a>'], ]];
			};
		} else {
			var tpl = function() {
				return ['li', {
					'style': "border-bottom: 1px solid #" + obj.cdivider + ";"
				},
				['h3', {},
				['a', {
					'id': "href" + this.id,
					'class': "eawidget-title",
					'style': "text-decoration: none; font-weight: bold; color: #" + obj.ch3 + ";",
					'href': this.link,
					'target': obj.widgettarget
				},
				this.title], 'p', {
					'id': "l" + this.id,
					'style': "margin: 0 auto 0 auto; text-align: left; display: block"
				},
				['a', {
					'class': "easummary",
					'style': "text-decoration: none; font-weight: 400",
					'href': "javascript:toggle_visibility('" + this.id + "','l" + this.id + "');"
				},
				'<img src="http://ezinearticles.com/widget/gfx/ssummary.gif" width="7" height="7" alt="Show summary" /> View summary'], 'div', {
					'id': this.id,
					'style': "background-color: #fbfbfb; padding: 4px; display: none"
				},
				['p', {
					'class': "easummary",
					'style': "text-align: left;"
				},
				'<span>' + this.summary + '</span> [<a href="' + this.link + '" title="' + this.title + '" target="' + obj.widgettarget + '" style="text-decoration: none; font-weight: 400">continue</a>] <br /><a style="text-decoration: none; font-weight: 400" href="javascript:toggle_visibility(\'' + this.id + '\',\'l' + this.id + '\');" title="Hide summary"><img src="http://ezinearticles.com/widget/gfx/hsummary.gif" width="7" height="7" alt="Hide summary" /> Hide summary</a>'], 'p', {},
				['a', {
					'style': "margin: 0 auto 0 auto; text-decoration: none; font-weight: 400",
					'href': this.categoryurl,
					'target': obj.widgettarget
				},
				'More ' + this.fcategory + ' Articles']]];
			};
		}
		for (var i = 0; i < obj.stories.length; i++) {
			jQuery('#' + div_container + ' ul').tplAppend(obj.stories[i], tpl);
		}
	} else {
		if (obj.type == 11) {
			jQuery('#' + div_container + ' div.eawidget-topic').html(info_icon + 'Author articles not found');
			jQuery('#' + div_container + ' ul').html('<div style="line-height: 1.5em; font-size: 11px;">Sorry, no articles from the author requested by this widget could be found at EzineArticles.<br /><br />It is possible the author does not have any published articles in the category requested, or at all. Please visit the link below to test and create a new widget:<br /><br /><a href="http://ezinearticles.com/" title="EzineArticles" target="' + obj.widgettarget + '">EzineArticles</a></div>');
		} else if (obj.type == 12) {
			jQuery('#' + div_container + ' div.eawidget-topic').html(info_icon + 'EzineArticles Widget');
			jQuery('#' + div_container + ' ul').html('<div style="line-height: 1.5em; font-size: 11px;">Welcome to the EzineArticles widget configuration page.<br /><br />Please choose some options to create your customized widget.</div>');
		}
	}
	document.write('<div id="eawidget-footer" class="eawidget-footer" style="background: #' + obj.cfooter + ';"><a id="eawidget-footerlink" style="text-decoration: none; font-weight: 700; letter-spacing: normal; color: #' + obj.cfootertext + '" href="http://ezinearticles.com/" target="' + obj.widgettarget + '">Powered by EzineArticles</a></div></div>');
}
function getWidgetElementsByName(tag, name) {
	var elem = document.getElementsByTagName(tag);
	var arr = new Array();
	for (i = 0, iarr = 0; i < elem.length; i++) {
		att = elem[i].getAttribute("name");
		if (att == name) {
			arr[iarr] = elem[i];
			iarr++;
		}
	}
	return arr;
}
