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",
		tableProperties: ""
	},

	recommendedSettings : {
		minWidth: "226",
		minHeight: "226"
	},

	customSettings : {},

	getHTML : function() {
		var _self = pokernews.widget.news;
		var html = "<table class=\"pn-wgt-widget\"{tableProperties}>"+"<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\">"+"<div class=\"scroll\">"+"<table>"+"<tr>"+"<td><a href=\"http:\/\/www.pokernews.com\/news\/2010\/02\/the-durrrr-challenge-dwan-expands-lead-by-315-000-7898.htm\" class=\"pn-wgt-news-image\" target=\"_blank\"><img src=\"http:\/\/www.pokernews.com\/files_en\/cnt\/thumb_4b71c53c4e0f1.jpg\" width=\"60\" height=\"40\" alt=\"\" \/><\/a><\/td>"+"<td>"+"<div class=\"pn-wgt-news-date\">February 09, 2010<\/div>"+"<a href=\"http:\/\/www.pokernews.com\/news\/2010\/02\/the-durrrr-challenge-dwan-expands-lead-by-315-000-7898.htm\" title=\"The \"durrrr\" Challenge: Dwan Expands Lead by $315,000\" target=\"_blank\">The \"durrrr\" Challenge: Dwan Expands Lead by $315,000<\/a>"+"<\/td>"+"<\/tr><tr>"+"<td><a href=\"http:\/\/www.pokernews.com\/news\/2010\/02\/top-5-performers-in-ftops-history-7895.htm\" class=\"pn-wgt-news-image\" target=\"_blank\"><img src=\"http:\/\/www.pokernews.com\/files_en\/cnt\/thumb_4b71849ac5db9.jpg\" width=\"60\" height=\"40\" alt=\"Adam Geyer\" \/><\/a><\/td>"+"<td>"+"<div class=\"pn-wgt-news-date\">February 09, 2010<\/div>"+"<a href=\"http:\/\/www.pokernews.com\/news\/2010\/02\/top-5-performers-in-ftops-history-7895.htm\" title=\"Top 5 Performers in FTOPS History\" target=\"_blank\">Top 5 Performers in FTOPS History<\/a>"+"<\/td>"+"<\/tr><tr>"+"<td><a href=\"http:\/\/www.pokernews.com\/news\/2010\/02\/party-poker-premier-league-iv-set-to-heat-up-vegas-7894.htm\" class=\"pn-wgt-news-image\" target=\"_blank\"><img src=\"http:\/\/www.pokernews.com\/files_en\/cnt\/thumb_4b717da0158ae.jpg\" width=\"60\" height=\"40\" alt=\"\" \/><\/a><\/td>"+"<td>"+"<div class=\"pn-wgt-news-date\">February 09, 2010<\/div>"+"<a href=\"http:\/\/www.pokernews.com\/news\/2010\/02\/party-poker-premier-league-iv-set-to-heat-up-vegas-7894.htm\" title=\"PartyPoker Premier League IV Set to Heat Up Vegas\" target=\"_blank\">PartyPoker Premier League IV Set to Heat Up Vegas<\/a>"+"<\/td>"+"<\/tr><tr>"+"<td><a href=\"http:\/\/www.pokernews.com\/news\/2010\/02\/online-poker-in-california-7893.htm\" class=\"pn-wgt-news-image\" target=\"_blank\"><img src=\"http:\/\/www.pokernews.com\/files_en\/cnt\/thumb_4b7083db59235.jpg\" width=\"60\" height=\"40\" alt=\"\" \/><\/a><\/td>"+"<td>"+"<div class=\"pn-wgt-news-date\">February 09, 2010<\/div>"+"<a href=\"http:\/\/www.pokernews.com\/news\/2010\/02\/online-poker-in-california-7893.htm\" title=\"California Senate Committee Holds Intrastate Poker Hearing\" target=\"_blank\">California Senate Committee Holds Intrastate Poker Hearing<\/a>"+"<\/td>"+"<\/tr><tr>"+"<td><a href=\"http:\/\/www.pokernews.com\/news\/2010\/02\/the-wsop-on-espn-the-poker-brat-the-godfather-the-magician-a-7892.htm\" class=\"pn-wgt-news-image\" target=\"_blank\"><img src=\"http:\/\/www.pokernews.com\/files_en\/cnt\/thumb_4b706b1c956e9.jpg\" width=\"60\" height=\"40\" alt=\"\" \/><\/a><\/td>"+"<td>"+"<div class=\"pn-wgt-news-date\">February 08, 2010<\/div>"+"<a href=\"http:\/\/www.pokernews.com\/news\/2010\/02\/the-wsop-on-espn-the-poker-brat-the-godfather-the-magician-a-7892.htm\" title=\"The WSOP on ESPN: The Poker Brat, the Godfather, the Magician, and the Mystery Swede\" target=\"_blank\">The WSOP on ESPN: The Poker Brat, the Godfather, the Magician, and the Mystery Swede<\/a>"+"<\/td>"+"<\/tr><tr>"+"<td><a href=\"http:\/\/www.pokernews.com\/news\/2010\/02\/the-pokernews-jet-set-the-m-resort-las-vegas-7887.htm\" class=\"pn-wgt-news-image\" target=\"_blank\"><img src=\"http:\/\/www.pokernews.com\/files_en\/cnt\/thumb_4b703110dc3a2.jpg\" width=\"60\" height=\"40\" alt=\"\" \/><\/a><\/td>"+"<td>"+"<div class=\"pn-wgt-news-date\">February 08, 2010<\/div>"+"<a href=\"http:\/\/www.pokernews.com\/news\/2010\/02\/the-pokernews-jet-set-the-m-resort-las-vegas-7887.htm\" title=\"The PokerNews Jet Set: The M Resort, Las Vegas\" target=\"_blank\">The PokerNews Jet Set: The M Resort, Las Vegas<\/a>"+"<\/td>"+"<\/tr><tr>"+"<td><a href=\"http:\/\/www.pokernews.com\/news\/2010\/02\/the-sunday-briefing-palurdo-banks-a-sunday-million-win-on-su-7890.htm\" class=\"pn-wgt-news-image\" target=\"_blank\"><img src=\"http:\/\/www.pokernews.com\/files_en\/cnt\/thumb_4b7021b9958e5.jpg\" width=\"60\" height=\"40\" alt=\"\" \/><\/a><\/td>"+"<td>"+"<div class=\"pn-wgt-news-date\">February 08, 2010<\/div>"+"<a href=\"http:\/\/www.pokernews.com\/news\/2010\/02\/the-sunday-briefing-palurdo-banks-a-sunday-million-win-on-su-7890.htm\" title=\"The Sunday Briefing: \"palurdo\" Banks a Sunday Million Win on Super Bowl Sunday\" target=\"_blank\">The Sunday Briefing: \"palurdo\" Banks a Sunday Million Win on Super Bowl Sunday<\/a>"+"<\/td>"+"<\/tr><tr>"+"<td><a href=\"http:\/\/www.pokernews.com\/news\/2010\/02\/betfred-s-2-000-cash-freeroll-starting-soon-7867.htm\" class=\"pn-wgt-news-image\" target=\"_blank\"><img src=\"http:\/\/www.pokernews.com\/files_en\/cnt\/thumb_4b661ef7e6d2d.jpg\" width=\"60\" height=\"40\" alt=\"Betfred Poker\" \/><\/a><\/td>"+"<td>"+"<div class=\"pn-wgt-news-date\">February 07, 2010<\/div>"+"<a href=\"http:\/\/www.pokernews.com\/news\/2010\/02\/betfred-s-2-000-cash-freeroll-starting-soon-7867.htm\" title=\"Betfred's $2,000 Cash Freeroll Starting Soon\" target=\"_blank\">Betfred's $2,000 Cash Freeroll Starting Soon<\/a>"+"<\/td>"+"<\/tr><tr>"+"<td><a href=\"http:\/\/www.pokernews.com\/news\/2010\/02\/2010-borgata-winter-poker-open-madsen-riding-a-heater-takes-7888.htm\" class=\"pn-wgt-news-image\" target=\"_blank\"><img src=\"http:\/\/www.pokernews.com\/files_en\/cnt\/thumb_4b6d1d3368415.jpg\" width=\"60\" height=\"40\" alt=\"\" \/><\/a><\/td>"+"<td>"+"<div class=\"pn-wgt-news-date\">February 06, 2010<\/div>"+"<a href=\"http:\/\/www.pokernews.com\/news\/2010\/02\/2010-borgata-winter-poker-open-madsen-riding-a-heater-takes-7888.htm\" title=\"2010 Borgata Winter Poker Open: Madsen Riding a Heater, Takes the Trophy\" target=\"_blank\">2010 Borgata Winter Poker Open: Madsen Riding a Heater, Takes the Trophy<\/a>"+"<\/td>"+"<\/tr><tr>"+"<td><a href=\"http:\/\/www.pokernews.com\/news\/2010\/02\/2010-borgata-winter-poker-open-day-4-jamshidi-madsen-headlin-7885.htm\" class=\"pn-wgt-news-image\" target=\"_blank\"><img src=\"http:\/\/www.pokernews.com\/files_en\/cnt\/thumb_4b6c409a0162d.jpg\" width=\"60\" height=\"40\" alt=\"\" \/><\/a><\/td>"+"<td>"+"<div class=\"pn-wgt-news-date\">February 05, 2010<\/div>"+"<a href=\"http:\/\/www.pokernews.com\/news\/2010\/02\/2010-borgata-winter-poker-open-day-4-jamshidi-madsen-headlin-7885.htm\" title=\"2010 Borgata Winter Poker Open: Jamshidi, Madsen Headline Final Table\" target=\"_blank\">2010 Borgata Winter Poker Open: Jamshidi, Madsen Headline Final Table<\/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("{tableProperties}", "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);
		}

        for (var i in _self.settings) {
            var re = new RegExp("{" + i + "}", "gi");
			css = css.replace(re, '');
			html = html.replace(re, '');
		}

		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;
			}
		}
	}
}