/*
   Link Icons v0.1
   http://shantalya.de
   
   Copyright 2010, Nils Ruesch
   
   Date: Sun, 07 Mar 2010 11:57:55 +0100
*/

var ExternalLinks_IgnoreURL = "shantalya.de";

function AddIcon(link, image)
{
	var img = document.createElement('img');
	img.src = "http://my.shantalya.de/images/icons/" + image;
	if (image == "bullet_world.png")
	{
		img.alt = "Mit diesem Link verlaesst du diese Webseite.";
		img.title = "Mit diesem Link verlaesst du diese Webseite.";
	
		link.title = "Mit diesem Link verlaesst du diese Webseite.";
	}
	else
	{
		img.alt = image;
	}
	img.align = "top";
	img.style.padding = "0px";
	img.style.margin = "0px";
	img.style.marginLeft = "2px";
	img.style.border = "none";
	
	link.parentNode.insertBefore(img, link.nextSibling);
}

function AddLinkIcons()
{
	var links = document.getElementsByTagName("a");
	for (i=0; i<links.length; i++)
	{
		var link = links[i];
		var image = link.getElementsByTagName("img");
		if (image.length == 0 && !link.rel.match("^(noicon)$"))
		{
			var href = link.href.toLowerCase();
			
			if (href.match(".jpg") || href.match(".jpeg") || href.match(".jpe") || href.match(".gif") || href.match(".png") || href.match(".bmp") || href.match(".tga"))
			{
				AddIcon(link, "picture.png");
			}
			else if (href.match(".zip") || href.match(".gzip") || href.match(".rar") || href.match(".exe") || href.match(".msi") || href.match(".cab"))
			{
				AddIcon(link, "compress.png");
			}
			else if (href.match(".txt") || href.match(".text") || href.match(".doc") || href.match(".odt"))
			{
				AddIcon(link, "page_white_word.png");
			}
			
			if (href.match("mailto:"))
			{
				AddIcon(link, "email.png");
			}
			//else if (href.match(/(http(s?)|ftp):/i) && !href.match(ExternalLinks_IgnoreURL))
			else if (!href.match("javascript:") && !href.match(ExternalLinks_IgnoreURL))
			{
				AddIcon(link, "bullet_world.png");
			}
		}
	}
}
