/*
 * jquery email antispam
 * Written 2007 by sunfish
 */
 
 function create_icon(icon)
 {
	return '<img src="layout/img/'+icon+'.gif" class="link-icon" />';
 }
 
 function mail(a,b) {
	 parent.location = 'mailto:'+a+'@'+b;
	 return false;
 }
 
$(document).ready(function(){		

		// email adress antispam - needs jquery
		// eg. write in html info<span> |at| </span>naturkooperation.org
	$("p:contains('(at)'),td:contains('(at)')").each(function(){
		// alert($(this).html());
		var filter = /([a-zA-Z0-9_\.\-]+)(<span> \(at\) <\/span>)([a-zA-Z0-9_\-\.]+\.[a-zA-Z]{2,3})/ig;
		var newLink = "<a onclick=\"mail('$1','$3')\" class=\"email\">$1<span> (at) </span>$3</a>";
		$(this).html($(this).html().replace(filter, newLink));	
	});
	
	
		// open external links with target _blank	
	$("#content a[href$=.pdf], #content a[href^=http]").click(function(){ 																		 
		this.target = "_blank";
	});
	
	
		$("a:has(img)").addClass('img');
		// link icons: because of the IE multiline problem do not use css classes
		$("a[href$='.rtf']").append(create_icon('doc'));
		$("a[href$='.doc']").append(create_icon('doc'));
		$("a[href*='.pdf'], a[href*=':PDF']").append(create_icon('pdf'));		
		
		$("#content a:not([href^=http])").not("[href^=index.php?eID]").not("[href^=#]").not("[class='email']").not("[href$='.pdf']").not("[href$='.doc']").not("[id^='c']").not("[class='thickbox']").prepend("» ");
	
	
		$("a[href^='http']").not("[class='img']").not("[class='no-icon']").not("[href*='.pdf'], [href*=':PDF']").each(function(){	
			// external link with » at the begining looks like an internal link.				
			if($(this).html().indexOf('»') == -1){
				 $(this).append(create_icon('link_extern'));		   
			}
		});
	
	// if ther follows a , or a . or a ) the link, img will get class link-icon2
    // IE has it's own html() 
	$("p a img.link-icon").parents('p').each(function(){
		// alert($(this).html());
        var expr = /link-icon([^>]*)><\/a>([,\.\)]{1})/gi;
		var repl = 'link-icon2$1></a>$2';
		$(this).html($(this).html().replace(expr,repl));	
	});	
	
	
								
});
