if( ! pokernews ) {
	var pokernews = {};
}

if( ! pokernews.widget ) {
	pokernews.widget = {};
}

pokernews.widget.news = {
	settings : {
		category: "0",
		imageVisible: true,
		dateVisible: true,
		linkTargetBlank: true,
		width: "260",
		height: "226",
		linkColor: "#12478D",
		textColor: "#666666",
		borderColor: "#12478C",
		backgroundColor: "#FFFFFF"
	},

	recommendedSettings : {
		minWidth: "226",
		minHeight: "226"
	},

	customSettings : {},

	getHTML : function() {
		var _self = pokernews.widget.news;
		var html = "<table class=\"pn-wgt-widget\"{fixed-width}>"+"<tr>"+"<td class=\"pn-wgt-bg\" valign=\"top\">"+"<div class=\"pn-wgt-widget\">"+"<div class=\"pn-wgt-top\">"+"<img src=\"http:\/\/www.pokernews.com\/img\/widget\/s.gif\" width=\"105\" height=\"17\" style=\"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader( enabled=true, src='http:\/\/pokernews.com\/img\/widget\/pokernews.png'); margin-right: 5px\" alt=\"Pokernews.com\" \/>"+"<a href=\"http:\/\/www.pokernews.com\/poker-tools\/\" title=\"\">get this widget<\/a>"+"<\/div>"+"<div class=\"pn-wgt-wrap\">"+"<a href=\"http:\/\/www.pokernews.com\/news\/online-poker\/\"><b>Online Poker<\/b><\/a>"+"<div class=\"scroll\">"+"<table>"+"<tr>"+"<td><a href=\"http:\/\/www.pokernews.com\/news\/2009\/11\/the-online-railbird-report-isildur1-takes-on-ivey-sahamies-a-7567.htm\" class=\"pn-wgt-news-image\" target=\"_blank\"><img src=\"http:\/\/www.pokernews.com\/files_en\/cnt\/thumb_4b06aec64e020.jpg\" width=\"60\" height=\"40\" alt=\"\" \/><\/a><\/td>"+"<td>"+"<div class=\"pn-wgt-news-date\">November 20, 2009<\/div>"+"<a href=\"http:\/\/www.pokernews.com\/news\/2009\/11\/the-online-railbird-report-isildur1-takes-on-ivey-sahamies-a-7567.htm\" title=\"The Online Railbird Report: Isildur1 Takes on Ivey, Sahamies and Dwan\" target=\"_blank\">The Online Railbird Report: Isildur1 Takes on Ivey, Sahamies and Dwan<\/a>"+"<\/td>"+"<\/tr><tr>"+"<td><a href=\"http:\/\/www.pokernews.com\/news\/2009\/11\/the-online-railbird-report-special-edition-antonius-wins-2-7-7557.htm\" class=\"pn-wgt-news-image\" target=\"_blank\"><img src=\"http:\/\/www.pokernews.com\/files_en\/cnt\/thumb_4b03eb210ee5d.jpg\" width=\"60\" height=\"40\" alt=\"Patrik Antonius\" \/><\/a><\/td>"+"<td>"+"<div class=\"pn-wgt-news-date\">November 18, 2009<\/div>"+"<a href=\"http:\/\/www.pokernews.com\/news\/2009\/11\/the-online-railbird-report-special-edition-antonius-wins-2-7-7557.htm\" title=\"The Online Railbird Report Special Edition: Antonius Wins $2.9 Million from Isildur1 in Battle Royale\" target=\"_blank\">The Online Railbird Report Special Edition: Antonius Wins $2.9 Million from Isildur1 in Battle Royale<\/a>"+"<\/td>"+"<\/tr><tr>"+"<td><a href=\"http:\/\/www.pokernews.com\/news\/2009\/11\/online-poker-spotlight-matt-mlagoo-lagarde-7552.htm\" class=\"pn-wgt-news-image\" target=\"_blank\"><img src=\"http:\/\/www.pokernews.com\/files_en\/cnt\/thumb_4b02c9c99eda7.jpg\" width=\"60\" height=\"40\" alt=\"Matt LaGarde\" \/><\/a><\/td>"+"<td>"+"<div class=\"pn-wgt-news-date\">November 17, 2009<\/div>"+"<a href=\"http:\/\/www.pokernews.com\/news\/2009\/11\/online-poker-spotlight-matt-mlagoo-lagarde-7552.htm\" title=\"Online Poker Spotlight: Matt \"mlagoo\" LaGarde\" target=\"_blank\">Online Poker Spotlight: Matt \"mlagoo\" LaGarde<\/a>"+"<\/td>"+"<\/tr><tr>"+"<td><a href=\"http:\/\/www.pokernews.com\/news\/2009\/11\/patrik-antonius-wins-largest-pot-in-online-poker-history-7551.htm\" class=\"pn-wgt-news-image\" target=\"_blank\"><img src=\"http:\/\/www.pokernews.com\/files_en\/cnt\/thumb_4b02317b9c3b6.jpg\" width=\"60\" height=\"40\" alt=\"\" \/><\/a><\/td>"+"<td>"+"<div class=\"pn-wgt-news-date\">November 17, 2009<\/div>"+"<a href=\"http:\/\/www.pokernews.com\/news\/2009\/11\/patrik-antonius-wins-largest-pot-in-online-poker-history-7551.htm\" title=\"Patrik Antonius Wins Largest Pot In Online Poker History\" target=\"_blank\">Patrik Antonius Wins Largest Pot In Online Poker History<\/a>"+"<\/td>"+"<\/tr><tr>"+"<td><a href=\"http:\/\/www.pokernews.com\/news\/2009\/11\/the-sunday-briefing-huge-paydays-at-both-full-tilt-poker-and-7548.htm\" class=\"pn-wgt-news-image\" target=\"_blank\"><img src=\"http:\/\/www.pokernews.com\/files_en\/cnt\/thumb_4b0179193b33a.jpg\" width=\"60\" height=\"40\" alt=\"\" \/><\/a><\/td>"+"<td>"+"<div class=\"pn-wgt-news-date\">November 16, 2009<\/div>"+"<a href=\"http:\/\/www.pokernews.com\/news\/2009\/11\/the-sunday-briefing-huge-paydays-at-both-full-tilt-poker-and-7548.htm\" title=\"The Sunday Briefing: Huge Paydays on Both Full Tilt Poker and PokerStars\" target=\"_blank\">The Sunday Briefing: Huge Paydays on Both Full Tilt Poker and PokerStars<\/a>"+"<\/td>"+"<\/tr><tr>"+"<td><a href=\"http:\/\/www.pokernews.com\/news\/2009\/11\/the-online-railbird-report-dwan-drops-3-million-to-isildur1-7542.htm\" class=\"pn-wgt-news-image\" target=\"_blank\"><img src=\"http:\/\/www.pokernews.com\/files_en\/cnt\/thumb_4afe0aa1a588f.jpg\" width=\"60\" height=\"40\" alt=\"\" \/><\/a><\/td>"+"<td>"+"<div class=\"pn-wgt-news-date\">November 14, 2009<\/div>"+"<a href=\"http:\/\/www.pokernews.com\/news\/2009\/11\/the-online-railbird-report-dwan-drops-3-million-to-isildur1-7542.htm\" title=\"Online Railbird Report: Dwan Drops $3 Million to “Isildur1” In Four-Day Heads-Up Duel\" target=\"_blank\">Online Railbird Report: Dwan Drops $3 Million to “Isildur1” In Four-Day Heads-Up Duel<\/a>"+"<\/td>"+"<\/tr><tr>"+"<td><a href=\"http:\/\/www.pokernews.com\/news\/2009\/11\/online-poker-ftops-xiv-in-full-swing-7536.htm\" class=\"pn-wgt-news-image\" target=\"_blank\"><img src=\"http:\/\/www.pokernews.com\/files_en\/cnt\/thumb_4afc79f76847a.png\" width=\"60\" height=\"40\" alt=\"\" \/><\/a><\/td>"+"<td>"+"<div class=\"pn-wgt-news-date\">November 13, 2009<\/div>"+"<a href=\"http:\/\/www.pokernews.com\/news\/2009\/11\/online-poker-ftops-xiv-in-full-swing-7536.htm\" title=\"Online Poker: Full Tilt XIV in Full Swing\" target=\"_blank\">Online Poker: Full Tilt XIV in Full Swing<\/a>"+"<\/td>"+"<\/tr><tr>"+"<td><a href=\"http:\/\/www.pokernews.com\/news\/2009\/11\/pokernews-exclusive-tom-dwan-introduced-as-team-full-tilt-pr-7521.htm\" class=\"pn-wgt-news-image\" target=\"_blank\"><img src=\"http:\/\/www.pokernews.com\/files_en\/cnt\/thumb_4af9066418b37.jpg\" width=\"60\" height=\"40\" alt=\"\" \/><\/a><\/td>"+"<td>"+"<div class=\"pn-wgt-news-date\">November 09, 2009<\/div>"+"<a href=\"http:\/\/www.pokernews.com\/news\/2009\/11\/pokernews-exclusive-tom-dwan-introduced-as-team-full-tilt-pr-7521.htm\" title=\"PokerNews Exclusive: Tom Dwan Introduced as Team Full Tilt Pro\" target=\"_blank\">PokerNews Exclusive: Tom Dwan Introduced as Team Full Tilt Pro<\/a>"+"<\/td>"+"<\/tr><tr>"+"<td><a href=\"http:\/\/www.pokernews.com\/news\/2009\/11\/the-sunday-briefing-ftops-xiv-rules-the-weekend-7516.htm\" class=\"pn-wgt-news-image\" target=\"_blank\"><img src=\"http:\/\/www.pokernews.com\/files_en\/cnt\/thumb_4af83f4f98a6c.png\" width=\"60\" height=\"40\" alt=\"\" \/><\/a><\/td>"+"<td>"+"<div class=\"pn-wgt-news-date\">November 09, 2009<\/div>"+"<a href=\"http:\/\/www.pokernews.com\/news\/2009\/11\/the-sunday-briefing-ftops-xiv-rules-the-weekend-7516.htm\" title=\"The Sunday Briefing: FTOPS XIV Rules the Weekend\" target=\"_blank\">The Sunday Briefing: FTOPS XIV Rules the Weekend<\/a>"+"<\/td>"+"<\/tr><tr>"+"<td><a href=\"http:\/\/www.pokernews.com\/news\/2009\/11\/full-tilt-poker-signs-tom-durrrr-dwan-to-team-full-tilt-7509.htm\" class=\"pn-wgt-news-image\" target=\"_blank\"><img src=\"http:\/\/www.pokernews.com\/files_en\/cnt\/thumb_4af76607e978c.jpg\" width=\"60\" height=\"40\" alt=\"Tom Dwan\" \/><\/a><\/td>"+"<td>"+"<div class=\"pn-wgt-news-date\">November 08, 2009<\/div>"+"<a href=\"http:\/\/www.pokernews.com\/news\/2009\/11\/full-tilt-poker-signs-tom-durrrr-dwan-to-team-full-tilt-7509.htm\" title=\"Full Tilt Poker Adds Tom \"durrrr\" Dwan to Team Full Tilt\" target=\"_blank\">Full Tilt Poker Adds Tom \"durrrr\" Dwan to Team Full Tilt<\/a>"+"<\/td>"+"<\/tr>"+"<\/table>"+"<\/div>"+"<div class=\"bottom-text\"><\/div>"+"<\/div>"+"<\/div>"+"<\/td>"+"<\/tr>"+"<\/table>";
		var css = "<style type=\"text\/css\">"+".pn-wgt-widget {"+"width:{width};"+"border-collapse:collapse;"+"margin:0 auto;"+"padding:0;"+"}"+".pn-wgt-bg {"+"border:1px solid {borderColor};"+"background:{backgroundColor};"+"border-collapse:collapse;"+"margin:0;"+"padding:0;"+"text-align:left;"+"width:{width};"+"\/*height:{height};*\/"+"}"+".pn-wgt-wrap .scroll {"+"padding:0 5px;"+"height:{heightUL}px;"+"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:{borderColor};"+"text-align:right;"+"padding:0 5px 6px 5px;"+"line-height:110%;"+"}"+".pn-wgt-top img {"+"display:block;"+"float:left;"+"border:0 none;"+"margin:1px 0 0 0;"+"background:url(http:\/\/pokernews.com\/img\/widget\/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:{textColor};"+"line-height:130%;"+"}"+".pn-wgt-wrap a {"+"font-size:11px;"+"font-family:Tahoma, Arial;"+"color:{linkColor};"+"}"+".pn-wgt-wrap a b {"+"display:block;"+"font-size:12px !important;"+"font-family:Verdana, Arial, Helvetica, sans-serif !important;"+"font-weight:bold;"+"color:{linkColor} !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:9px;"+"font-family:Tahoma, Arial;"+"border-bottom:1px dotted #B7C7DD;"+"}"+"<\/style>";

		for (var i in _self.settings) {
			var property = _self.settings[i];
			if (_self.customSettings[i] !== undefined) {
				property = _self.customSettings[i];
			}
			if (i == "height") {
				css = css.replace(/\{heightUL\}/gi, parseInt(property) - 86);
			}
			if (i == "width" || i == "height") {
				if (property.indexOf('%') < 0 && property.indexOf('px') < 0) {
					property += 'px';
				}
			}
			if (i == "width" && property.indexOf('%') > 0) {
				property = parseInt(property);
				var re = new RegExp("{fixed-width}", "gi");
				var reReplace = '';
				if (property < 100) {
					reReplace = ' style="width: ' + property + '%"';
				}
				property = '100%';
				html = html.replace(re, reReplace);
			}
			if (i == "dateVisible") {
				if (!property) {
					css = css.replace(/<\/style>/gi, ' .pn-wgt-news-date {display:none;}</style>');
				}
			}
			if (i == "imageVisible") {
				if (!property) {
					css = css.replace(/<\/style>/gi, ' .pn-wgt-news-image {display:none;}</style>');
				}
			}
			if (i == "linkTargetBlank") {
				if (!property) {
					html = html.replace(/ target="_blank"/gi, '');
				}
			}

			var re = new RegExp("{" + i + "}", "gi");
			css = css.replace(re, property);
			html = html.replace(re, property);
		}

		return {
			html: html,
			css: css
		};
	},

	getElementsByClass : function(searchClass, node, tag) {
		var classElements = new Array();
		if ( node == null )
			node = document;
		if ( tag == null )
			tag = '*';
		var els = node.getElementsByTagName(tag);
		var elsLen = els.length;
		var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");
		for (i = 0, j = 0; i < elsLen; i++) {
			if ( pattern.test(els[i].className) ) {
				classElements[j] = els[i];
				j++;
			}
		}
		return classElements;
	},

	output : function(hash) {
		var container = document.getElementById(hash);
		var containerInnerHTML = container.innerHTML;
		if (container) {
			var _self = pokernews.widget.news;
			_self.hash = hash;
			var code = _self.getHTML();
			document.write(code.css);
			container.innerHTML = code.html;
			var footerElements = _self.getElementsByClass('bottom-text', null, 'div');
			for (var i in footerElements) {
				footerElements[i].innerHTML = containerInnerHTML;
			}
		}
	}
}