// ==UserScript==
// @name Snipe-Hunt news fix
// @author FyberOptic
// @email fyberoptic@gmail.com
// @namespace http://www.fybertech.com
// @version 0.1
// @description Fixes some layout problems and adds SVG rounded corners to the Snipe-Hunt news page
// @include http://snipehuntmedia.com/*
// @include http://www.snipehuntmedia.com/*
// @ujs:category site: fixes
// @ujs:published 2009-03-21 15:20
// @ujs:modified 2009-03-21 16:10
// @ujs:download http://www.fybertech.com/userjs/snipefix.js
// ==/UserScript==


window.opera.addEventListener('AfterEvent.DOMContentLoaded', function(e) 
{	
	// Only want HTML documents
	if (!(e.event.target instanceof Document)) return;
	
	// Only replace the main news page for now
	if (document.location.href.match(/snipehuntmedia\.com\/(?:index.*?)?$/i))
	{	
		var head = document.getElementsByTagName('head')[0];
			
		var styletext = " \
			.ContentBox { overflow: hidden; } \
			.news * { position: static; } \
			.news_studio_title, .news_page, .news_link { position: absolute; } \
			.news_date { margin-right:5px; } \
			body { overflow: hidden; } \
		";

		// Add a new stylesheet that fixes some rendering issues
		var newstyle = document.createElement('style');
		newstyle.setAttribute('type','text/css');
		newstyle.appendChild(document.createTextNode(styletext));	
		head.appendChild(newstyle);

	
		// SVG for rounded corners of content frame
		var svgdoc = "\
<?xml version=\"1.0\" standalone=\"no\"?> \
<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \
\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"> \
<svg width=\"100%\" height=\"100%\" version=\"1.1\" \
xmlns=\"http://www.w3.org/2000/svg\"> \
<rect fill=\"white\"  x=\"0\" y=\"0\" width=\"100%\" height=\"100%\" rx=\"1em\" /> \
<rect fill=\"black\"  x=\"0.3%\" y=\"0.5%\" width=\"99.4%\" height=\"99%\" rx=\"1em\" /> \
</svg> \
";

		// SVG for rounded corners of news entries
		var svgdoc2 = "\
<?xml version=\"1.0\" standalone=\"no\"?> \
<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \
\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"> \
<svg width=\"100%\" height=\"100%\" version=\"1.1\" \
xmlns=\"http://www.w3.org/2000/svg\"> \
<rect fill=\"white\"  x=\"0\" y=\"0\" width=\"100%\" height=\"100%\" rx=\"0.5em\" /> \
<rect fill=\"#252525\"  x=\"0.3%\" y=\"1%\" width=\"99.4%\" height=\"98%\" rx=\"0.5em\" /> \
</svg> \
";
	
		// Add rounded corners to main content frame using SVG image 1
		var contentbox = document.getElementsByClassName('ContentBox')[0];
		contentbox.style.border = "0px";
		contentbox.style.backgroundImage = "URL(data:image/svg+xml," + escape(svgdoc) + ")";		
		
				
		var newsboxes = contentbox.getElementsByClassName('news');		
		
		var urlstring = "URL(data:image/svg+xml," + escape(svgdoc2) + ")";
		
		// Add rounded corners to all news boxes using SVG image 2
		for (var n = 0, row; row = newsboxes[n]; n++)
		{			
			row.style.border = "0px";
			row.style.backgroundImage = urlstring;
		}
		
		// Minor workaround to make Opera redraw the news panel to display all the new SVG backgrounds immediately
		setTimeout("var newsleft = document.getElementsByClassName('news_left')[0]; newsleft.scrollTop = 999999; newsleft.scrollTop = 0; ",100);
		
	}
	
}
,false);


