// JavaScript Document
// <![CDATA[
/************************************************
	New window link
	by Marko Dugonjic, http://www.maratz.com/
*************************************************/

// Set paramethers:
var path_to_icon 		= 'icon.gif';
var link_alt_text 		= 'open link in new window';
var link_title_text 	= 'Open this link in new window!';

function new_window_link() 
{
	if (!document.getElementById || !document.createTextNode || !document.domain) return;
	var l = document.getElementsByTagName('a');
	for (var i = 0; i < l.length; i++) 
	{
		liText=l[i].href
		if (liText=='' || liText.indexOf('#')>=0 || liText.indexOf('mailto')>=0 || liText.indexOf('javascript')>=0)
		{
		}
		// just for off-site links
		// only if http://www. else opens in same window as its an on site link
		else if (l[i].href.split('/')[2].replace(/www\./, '') != document.domain.replace(/www\./, '')
			&& !l[i].getAttribute('target')
			&& !l[i].parentNode.id.match(/^copy/)) 
		{
			// create new elements
			var nwl = document.createElement('a');
			var nwl_image = document.createElement('img');
			var space = document.createTextNode(' ');

			// setup image attributes
			nwl_image.setAttribute('src', path_to_icon);
			nwl_image.setAttribute('alt', link_alt_text);
			nwl_image.setAttribute('title', link_title_text);

			// set link attributes
			nwl.setAttribute('href', l[i].getAttribute('href'));
			nwl.setAttribute('target', '_blank');
			nwl.setAttribute('title', link_title_text);
			nwl.className = 'new_window_link';

			// append new elements
			nwl.appendChild(nwl_image);
			l[i].parentNode.insertBefore(space, l[i].nextSibling);
			l[i].parentNode.insertBefore(nwl, l[i].nextSibling.nextSibling);
		}
	}
}
onload = new_window_link;
// ]]>
