/*
 * jquery email antispam
 * Written 2007 by sunfish
 */
 
 function create_icon(icon)
 {
	return '<img src="fileadmin/kulturlandplan/layout/img/'+icon+'.gif" class="link-icon" />';
 }
 
 
$(document).ready(function(){
						   
	if($('.showhidecontent').length)
	{		
		$('.showhidecontent').each( function () {
											  
			var moreLink = ' <a href="#" class="showhideLink more" title="mehr Text anzeigen" >[+] mehr...</a>';
			var lessLink = ' <a href="#" class="showhideLink less" title="Text verbergen" >[-] weniger...</a>';

			// copy and remove the first paragraph
			var firstParagraph = $(this).find('p').first().clone();
			$(this).find('p').first().remove();
			firstParagraph.append(moreLink);
			// $(this).find('p').first().;
			$(this).wrapInner('<div class="showHide"></div>');
			$(this).prepend(firstParagraph);		
		});
	}
	
	$('.showHide').hide();
	
	$('.showhideLink').click( function() {
		if ( $(this).hasClass('more') )
		{
			$(this).parents('p').next('div').slideDown(1000);
			$(this).removeClass('more').addClass('less').attr('title','Text verbergen').text('[-] weniger...');
			return false;	
		} else {			
			$(this).parents('p').next('div').slideUp(1000);
			$(this).removeClass('less').addClass('more').attr('title','mehr Text anzeigen').text('[+] mehr...');
			return false;			
		}							
	});
						   
		
		
	if( $('h1').parent('div:not(:has("p"))').length )
	{
		//$('#content h3, #content h2').css({'color':'#FFCC00'});
		// if first container has only h1 and no <p>, 
		// than h2 or h3 in the next conmtainer shold have no margin-top
		$('#content > div:eq(1)').find('h2,h3').addClass('jquery-firstheader');
	}
	
	if($('#submenu').length)
	{
		$('#content').css({'padding-top':'20px'});
	}

		// open external links with target _blank	
	$("#content a[href$=.pdf], #content a[href^=http]").click(function(){ 																		 
		this.target = "_blank";
	});
	
	
		$("a:has(img)").addClass('img');
		$('#footer p a').addClass('no-icon');		
		// 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("[class='img']").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));	
	});	
	
	
								
});
