<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs
	title="Poker News from PokerNews.com"
	title_url="http://www.pokernews.com/"
	description="Gadget provides the Poker related information from the most authoritative source of Poker news. You can choose specific categories of Poker news that you would like to get and you will have up to date information about poker on your iGoogle profile."
	author="PokerNews Ltd"
	author_email="pokernewsltd@gmail.com"
	thumbnail="http://www.pokernews.com/gadgets/news/gg-thumb.gif"
	screenshot="http://www.pokernews.com/gadgets/news/gg-screen.gif"

	author_photo="http://www.pokernews.com/gadgets/author-logo.gif"
	author_aboutme="PokerNews Ltd builds and supports informational and community websites, which provide informational recourses about poker in more than 40 languages."
	author_link="http://www.pokernews.com/"
	author_quote="Learn and play poker in your language"

	width="300"
	height="250"
	scrolling="false"
	>

	<Require feature="ads"/>
	<Require feature="setprefs" />
	<Require feature="dynamic-height"/>

</ModulePrefs>

<UserPref name="clickurl" datatype="hidden" default_value=""/>
<UserPref name="aiturl" datatype="hidden" default_value=""/>

<UserPref name="fld_rss_categories" datatype="hidden" default_value=""/>
<UserPref name="fld_rss_items_count" datatype="hidden" default_value="10"/>


<Content type="html">

<![CDATA[

<style type="text/css">

.pn-wgt-widget {
		width: 100%;
		border-collapse: collapse;
		margin: 0 auto;
		padding: 0;
		font-size: 11px;
		font-family: Tahoma, Arial;
}

.pn-wgt-bg {
		border: 1px solid #12478C;
		background: #FFFFFF;
		border-collapse: collapse;
		margin: 0;
		padding: 0;
		text-align: left;
		width: 100%;
}

.pn-wgt-wrap .scroll {
		padding: 0 5px;
		height: 340px;
		overflow: auto;
}

.pn-wgt-wrap .scroll img {
		border: 0;
		margin-right: 5px;
}

.pn-wgt-wrap .scroll table {
		border-collapse: collapse;
}

.pn-wgt-wrap {
		padding: 5px;
}

.pn-wgt-top {
		background: #12478C;
		text-align: right;
		padding: 0 5px 6px 5px;
		line-height: 110%;
		color:#fff;
}

.pn-wgt-top img {
		display: block;
		float: left;
		border: 0 none;
		margin: 1px 5px 0 0;
		background: url(http://pokernews.com/gadgets/skins/1/pokernews.png) 0 0 no-repeat;
}

* html .pn-wgt-top img {
		background: none;
}

*:first-child + html .pn-wgt-top img {
		background: none;
}

.pn-wgt-top a {
		color:#FFF !important;
		font-size:9px !important;
		text-decoration:underline !important;
		font-family:Verdana, Arial, Helvetica, sans-serif !important;
}

.pn-wgt-wrap * {
		color: #666666;
		line-height: 130%;
}

.pn-wgt-wrap a {
		font-size: 11px;
		font-family: Tahoma, Arial;
		color: #12478D;
}

.pn-wgt-wrap a b {
		display: block;
		font-size:12px !important;
		font-family:Verdana, Arial, Helvetica, sans-serif !important;
		font-weight: bold;
		color:#12478D !important;
		text-decoration:none !important;
}

.pn-wgt-wrap .bottom-text {
		font-size: 11px;
		font-family: Tahoma, Arial;
		padding: 0 5px;
		margin: 5px 0;
		overflow: hidden;
		line-height: 130%;
}

.pn-wgt-wrap .scroll td {
		padding: 3px 0;
		font-size: 11px;
		font-family: Tahoma, Arial;
		border-bottom: 1px dotted #B7C7DD;
}

.pn-wgt-wrap .ok {
	color: #090;
	font: 11px verdana
}

.pn-wgt-wrap .pn-set-ll {
	margin: 5px 0;
	font: 12px verdana;
}

.pn-wgt-wrap .pn-categories {
	margin-bottom: 10px;
}

.hide {
	display: none;
}

</style>


<table class="pn-wgt-widget" style="width: 100%; margin-bottom: 2px;">
	<tbody>
		<tr>
			<td class="pn-wgt-bg" valign="top">
				<div class="pn-wgt-widget">
					<div class="pn-wgt-top"><img src="http://pokernews.com/gadgets/skins/1/s.gif" alt="Pokernews.com" width="105" height="17" /><a href="#" id="pn-set-btn" onclick="return toggleSettings();" title="">Settings</a></div>
					<div class="pn-wgt-wrap">
						<div class="scroll">

							<div id="pn-tab-main">

							</div>

							<div id="pn-tab-set" style="display:none;">

							</div>

						</div>
						<div class="bottom-text">
							Read more poker news from <a href="http://www.pokernews.com/news/" title="News from Pokernews.com" target="_blank">PokerNews.com</a>.
						</div>
					</div>
				</div>
			</td>
		</tr>
	</tbody>
</table>

<script type="text/javascript">

var prefs = new _IG_Prefs();
var tabs = new Array('pn-tab-main', 'pn-tab-set');
var tabActive = '';
var htmlCache = new Array();
var xmlURL = 'http://www.pokernews.com/news/rss.xml';

showMainTab();

function showMainTab() {
	_gel('pn-tab-main').innerHTML = 'loading...';
	if (htmlCache[getViewID('main')]) {
		_gel('pn-tab-main').innerHTML = htmlCache[getViewID('main')];
		_IG_AdjustIFrameHeight();
	}

	var settings = getSettings();
	requestURL = xmlURL;
	if (settings[0] || settings[1]) {
		requestURL = requestURL + '?xml&l=' + settings[1];
		if (settings[0]) {
			requestURL = requestURL + '&c=' + settings[0];
		}
	}

	_IG_FetchXmlContent(
		requestURL,
		function(feed) {
			if (feed == null) {
				htmlCache[getViewID('main')] = 'There are no data';
			}
			else {
				htmlCache[getViewID('main')] = htmlArticlesList(feed);
			}
			_gel('pn-tab-main').innerHTML = htmlCache[getViewID('main')];
			_IG_AdjustIFrameHeight();
		},
		settings[1]
	);
}

function showSettingsTab() {
	_gel('pn-tab-set').innerHTML = 'loading...';
	if (htmlCache[getViewID('settings')]) {
		_gel('pn-tab-set').innerHTML = htmlCache[getViewID('settings')];
		_IG_AdjustIFrameHeight();
	}

	var settings = getSettings();
	_IG_FetchXmlContent(
		xmlURL + '?xml&cl',
		function(feed) {
			if (feed == null) {
				htmlCache[getViewID('settings')] = 'There are no data';
			}
			else {
				htmlCache[getViewID('settings')] = htmlSettings(feed);
			}
			_gel('pn-tab-set').innerHTML = htmlCache[getViewID('settings')];
			_IG_AdjustIFrameHeight();
		}
	);
}

function htmlSettings(xml) {
	var countOptions = new Array(3, 4, 5, 6, 7, 8, 9, 10);

	var html = '';

	html += '<div class="pn-set-ll">';
	html += '<label for="fld_count">News in list:</label>';
	html += '<select name="fld_count" id="fld_count" size="1" onchange="saveSettings(\'fld_count\');">';

	var settings = getSettings();
	var selectedCategories = settings[0].split(',');

	for (var i = 0; i < countOptions.length; i++) {
		var optVal = countOptions[i];
		var optSelected = '';
		if (optVal == settings[1]) {
			optSelected = ' selected="selected"';
		}
		html += '<option value="' + optVal + '"' + optSelected + '>' + optVal + '</option>';
	}

	html += '</select>';
	html += '</div>';

	html += '<table class="pn-categories">';
	html += '<tbody>';

	if (!xml.getElementsByTagName) {
		var xml = (new DOMParser()).parseFromString(xml, "text/xml");
	}
	var categoriesList = xml.getElementsByTagName('category');
	for (var i = 0; i < categoriesList.length; i++) {
		var nodeList = categoriesList.item(i).childNodes;
		for (var j = 0; j < nodeList.length; j++) {
			var node = nodeList.item(j);
			if (node.nodeName == 'id') {
				var id = node.firstChild.nodeValue;
			}
			if (node.nodeName == 'title') {
				var title = node.firstChild.nodeValue;
			}
		}


		var optSelected = '';
		if (inArray(id, selectedCategories)) {
			optSelected = ' checked="checked"';
		}

		html += '<tr>';
		html += '<td><input type="checkbox" name="fld_' + id + '" id="fld_cat_' + id + '" onclick="saveSettings(\'fld_cat_' + id + '\');" value="' + id + '"' + optSelected + ' /></td>';
		html += '<td><label for="fld_' + id + '">' + title + '</label></td>';
		html += '</tr>';
	}
	html += '</tbody>';
	html += '</table>';
	htmlCache[getViewID('settings')] = html;
	return html;
}

function htmlArticlesList(xml) {
	var html = '';
	html += '<table>';
	html += '<tbody>';

	if (!xml.getElementsByTagName) {
		var xml = (new DOMParser()).parseFromString(xml, "text/xml");
	}
	var newsList = xml.getElementsByTagName('item');
	for (var i = 0; i < newsList.length; i++) {
		var nodeList = newsList.item(i).childNodes;
		for (var j = 0; j < nodeList.length; j++) {
			var node = nodeList.item(j);
			if (node.nodeName == 'url') {
				var url = node.firstChild.nodeValue;
			}
			if (node.nodeName == 'title') {
				var title = node.firstChild.nodeValue;
			}
			if (node.nodeName == 'image') {
				var image = node.firstChild.nodeValue;
			}
			if (node.nodeName == 'summary') {
				var summary = node.firstChild.nodeValue;
			}
			if (node.nodeName == 'created') {
				var created = node.firstChild.nodeValue;
			}
		}
		var milliseconds = (created) * 1000;
		var date = new Date(milliseconds);
		var year = date.getFullYear();
		var month = date.getMonth() + 1;
		var day = date.getDate();
		month = month < 10 ? '0' + month : month;
		day = day < 10 ? '0' + day : day;
		dateTxt = year + '-' + month + '-' + day;

		html += '<tr>';
		html += '<td><a href="' + url + '" class="pn-wgt-news-image" target="_blank"><img src="' + image + '" width="60" height="40" alt="" /></a></td>';
		html += '<td><div class="pn-wgt-news-date">' + dateTxt + '</div><a href="' + url + '" title="' + title + '" target="_blank">' + title + '</a></td>';
		html += '</tr>';
	}

	html += '</tbody>';
	html += '</table>';
	htmlCache[getViewID('main')] = html;
	return html;
}

function toggleSettings() {
	if (tabActive == 'pn-tab-set') {
		switchTab('pn-tab-main');
		_gel('pn-set-btn').innerHTML = 'Settings';
		showMainTab();
	}
	else {
		switchTab('pn-tab-set');
		_gel('pn-set-btn').innerHTML = 'Back to list';
		showSettingsTab();
	}
	return false;
}

function switchTab(tabID) {
	if (tabID == tabActive) {
		return;
	}
	for (i in tabs) {
		_gel(tabs[i]).style.display = 'none';
	}
	tabActive = tabID;
	_gel(tabID).style.display = '';
}

function getSettings() {
	return new Array(
		prefs.getString('fld_rss_categories'),
		prefs.getInt('fld_rss_items_count')
	);
}

function getViewID(prefix) {
	var settings = getSettings();
	return prefix + settings.join('|');
}

function saveSettings(id) {
	if (id == 'fld_count') {
		var i = _gel(id).selectedIndex;
		prefs.set('fld_rss_items_count', _gel(id).options[i].value);
	}
	if (id.indexOf('cat') > 0) {
		var settings = getSettings();
		var selectedCategories = settings[0].split(',');
		var category = _gel(id).value;
		if (_gel(id).checked && !inArray(category, selectedCategories)) {
			selectedCategories.push(category);
		}
		else {
			selectedCategories = removeFromArray(category, selectedCategories);
		}
		prefs.set('fld_rss_categories', selectedCategories.join(','));
	}
}

function inArray(val, arr) {
	for (var j = 0; j < arr.length; j++) {
		if (arr[j] == val) {
			return true;
		}
	}
	return false;
}

function removeFromArray(val, arr) {
	var newArray = new Array();
	var counter = 0;
	for (var j = 0; j < arr.length; j++) {
		if (arr[j] == val) {
			continue;
		}
		counter++;
		newArray[counter] = arr[j]
	}
	return newArray;
}

</script>

]]>

</Content>
</Module>