﻿/* -----------------------------------------------
   Link Enhancer - v.1.5
   (c) 2007 www.haan.net
   contact: info@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
// 1.4 added support for links to downloads
// 1.5 added support for active links

// 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_active {
	color: #f00;
}
.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/link_email.gif) no-repeat right 3px;
	padding: 0 21px 0 0;
}
.link_download {
	height: 20px;
	background: url(/images/link_download.gif) no-repeat right 4px;
	padding: 0 13px 0 0;
}
you also need some 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';
		}
		else if(links[i].href.indexOf("pdf") > 1 || links[i].href.indexOf("jpg") > 1)
		{
			links[i].target = '_blank';
			links[i].className = 'link_download';
		}
		else 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';
			}
		}
		else 
		{
			if(links[i].href == window.location)
			links[i].className = "link_active";
		}		
	}
}
