﻿/* -----------------------------------------------
   Link Enhancer - v.1.3.1
   (c) 2007 www.haan.net
   contact: jeroen@haan.net
   You may use this script but please leave the credits on top intact.
   Please inform us of any improvements made.
   When usefull we will add your credits.
  ------------------------------------------------ */

// 1.2 added no className (small image) after an image...
// 1.3 added support for email links
// 1.3.1 only target=blank for outbound links (not the email link) & also icon for own domain emailadresses

// give the outbound links a blank target and own style
// and optional the inbound too or vise versa
// it will leave the mailto alone and skipp anchor tags without the href attribute
/*
example CSS
.link_ext {
	height: 20px;
	background: url(/images/link_ext.gif) no-repeat right 4px;
	padding: 0 13px 0 0;
}
.link_email {
	height: 20px;
	background: url(/images/icon_email.gif) no-repeat right 3px;
	padding: 0 21px 0 0;
}
you also need 1 or 2 little images, e.g. an arrow pointing to the right top
*/


// usage:
//
// <head>
// <script type="text/JavaScript" src="/js/link_enhancer.js"></script>
// <script type="text/javascript">
// window.onload = function()
// {
//	enhanceLinks();
// }
// </script>
// </head>
// <body>



function enhanceLinks()
{
	var links = document.getElementsByTagName("a");
	var thisDomain = document.domain.split('www.');
	var thisDomain = (thisDomain[1]) ? thisDomain[1] : document.domain ;
	for (var i = 0; i < links.length; i++)
	{
		if(links[i].href.indexOf('@') > 0)
		{
			links[i].className = 'link_email';
		}
		if(links[i].href.indexOf(thisDomain) == -1 && links[i].href != '')
		{
			if(links[i].firstChild.tagName == 'IMG')
			{
				continue;
			}
			if(links[i].href.indexOf('@') > 0)
			{
				links[i].className = 'link_email';
			}
			else
			{
				links[i].target = '_blank';
				links[i].className = 'link_ext';
			}
		}
		// or else do this too if you like
		// else 
		// {
		//	links[i].target = '_self';
		//	links[i].className = 'link_int';
		// }		
	}
}
