 
 function create_icon(icon)
 {
	return '<img src="layout/img/'+icon+'.gif" class="link-icon" />';
 }

function showfaq(hash){
	var hashDiv = $(".faq:has("+hash+")");
	// element with anchor on this page?
	if(hashDiv[0]){
		hashDiv.find("div.faq-text").show();
		hashDiv.children("h3").addClass('show');
		var a = hashDiv.children("h3").children("a");
		a.children("img").attr("src","layout/img/minus.gif");
		a.attr("title","Text ausblenden");
	}	
}



jQuery.fn.defaultvalue = function() {				
	// thanks for the nice code from http://campbellsdigitalsoup.co.uk/about/default-value/
	
	// Scope
	var elements = this;
	
	return(
		elements.each(function() {				
			
			// Default values within scope
			var el = $(this);
			var def = el.attr('title');
			var defColor = '#838B83';
			
			// set defaultValue only if there is no earlier entry
			if(el.val() == '') {
				el.val(def);
				el.css('color', defColor);
			}
			
			el.focus(function() {
				if(el.val() == def) {
					el.val('');
					el.removeAttr('style');
				}
			});
			el.blur(function() {
				if(el.val() == '') {
					el.val(def);
					el.css('color', defColor);
				}
			});
			el.parents('form').submit(function() {
				if(el.val() == def) {
					el.val('');
				}					
			}); 
			
		}) //elements each
	); // return
}

	// animated forms
jQuery.fn.getMoreContainer = function() {	
		// get checkbox id
	var id = $(this).attr('id');
		// return 'child'-container object
	return $('#more-'+id);
}; 
 
 
 $(document).ready(function(){	
							
							
	 // remove default values onFocus
	$('input[title]').defaultvalue();
	
							
		// on page: anmeldung
	if($("body#b6").length == 0 ) {
		
			// checkboxes width class 'more' and 'child'-container named #more-+id of the parent checkbox
			// e.g. checkbox: #certrfle, 'child'-container: #more-certrfle
		$('input.more').each(function() {
			if(!this.checked) {				
				$(this).getMoreContainer().hide();
			}
		});			
			// all checkboxes width class more toggle their 'child'-containers
		$('.more').click(function(){				 
				$(this).getMoreContainer().slideToggle('normal');
		});

	}
							
					
	$("img[src$='tel.gif']").addClass("tel");
	$("a:has(img)").addClass("img");
	$("a[href^='javascript:linkTo_UnCryptMailto']").addClass("email");
	if($("body#b6").length == 0) // on search page do not display link icons 
	{
		// link icons: because of the IE multiline problem do not use css classes
		$("a[href$='.rtf']").not("[class='img']").append(create_icon('doc'));
		$("a[href$='.doc']").not("[class='img']").append(create_icon('doc'));
		$("a[href*='.pdf'], a[href*=':PDF']").not("[class='img']").append(create_icon('pdf'));			
		
		$("a[href$='.rtf']").attr('target','_blank');
		$("a[href$='.doc']").attr('target','_blank');
		$("a[href*='.pdf'], a[href*=':PDF']").attr('target','_blank');		
		
		$("#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("» ");
	}
	
	   // alert($("div#oekolinks").length);
	if($("div#oekolinks").length == 0 ) // in section oekolinks do not display link icons 
	{			
		$("a[href^='http']").not("[class='img']").not("[class='noicon']").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));	
	});	
	
	// alert($("a[href^='http']:not('GMP')").html());	
	
	// open external links with target _blank	
	$("a[href^='http']").attr('target','_blank');
	$(".search_result a[href^=http]").attr('target','_self');
	
	
	/*$("a:contains('(at)')").each(function(){
		// alert($(this).html());
		var filter = /<span> \(at\) <\/span>/ig;
		var at = "@";
		$(this).html($(this).html().replace(filter,at));	
	});	*/

	
	$(".box h3").text('Dokumente').each(function(){
		$(".box").addClass('documents');
	});
	
	
	    // Infodienst headline indent
	$("#infoservice h3").each(function(){
		// alert($(this).html());
		var filter = /(\w\))/i;
		var rep = "<span>$1</span>";
		$(this).html($(this).html().replace(filter,rep));	
	});	
 
	$("#infoservice h5").each(function(){
		// alert($(this).html());
		var filter = /(\w\.\w)/i;
		var rep = "<span>$1</span>";
		$(this).html($(this).html().replace(filter,rep));	
	});		
	
		//zebra table
	$("tr:odd").addClass("odd");
	// $("td:nth-child(1)").addClass("td1");	
	$("td:first-child").addClass("td1");		
	
    
		// FAQ clickable
	$(".faq-text").hide(); 
	
	var faqLinkStart = '<a class="info" title="Text anzeigen">';
	var faqLinkEnd = '&nbsp; <img src="layout/img/plus.gif" /></a>';

	$(".faq h3").each(function(){
			$(this).html(faqLinkStart + $(this).html() + faqLinkEnd);			  
	});		
	$(".faq h3 a").click(function(){
		$(this).parents("h3").next("div").toggle();		
		 if ($(this).attr("title") == 'Text anzeigen')
		 {
		   $(this).parents("h3").addClass('show');
		   $(this).attr("title","Text ausblenden");
		   $(this).children("img").attr("src","layout/img/minus.gif");
		 } 
	    else
		 {
		   $(this).attr("title","Text anzeigen");
		   $(this).children("img").attr("src","layout/img/plus.gif");
		  // $(this).parents("h3").removeAttr('style');
		   $(this).parents("h3").removeAttr('class');
		 }	    
	});
		// FAQ SHOW SPECIAL 
	// external call: show single .faq div with hash anchor
	if(location.hash) {
		showfaq(location.hash);
	}
	// internal call: show single .faq div with hash anchor
	//test $(".faq-text a[href*=#]").css({'border':'1px dotted blue'});
	$(".faq a[href*=#]").click(function(){					
		var hash = false;
		var thishref = $(this).attr("href");			
		// get pure hash from href, if href = /path/filename#hash	
		if(thishref.indexOf("#") > 0) {
			var hrefparts = thishref.split('#');
			var filepath = hrefparts[0];
			var thishash = '#'+hrefparts[1];
			
			// alert(filepath+' '+location.href.indexOf(filepath)+' '+thishash);

			// and check if /path/filename means the actual page
			if(location.href.indexOf(filepath) != -1) {
				hash = thishash;									
			}
		} else {
			hash = thishref;
		}
		if(hash) {
			showfaq(hash);
		}
	});

	
	
	$("div.rcbox").wrap(
		  '<div class="rc-wrap">'+ 
		  '<div class="rc-top">'+ 
		  '<div class="rc-left">'+ 
		  '</div>'+ 
		  '</div>'+ 
		  '</div>');
	$('div.rc-wrap').append(
		  '<div class="rc-footer">'+
		  '<div class="rc-left"></div>'+
		  '</div>');
	
	$('div.rc-wrap').after(
		  '<div class="clear"></div>');


	//$("p a img.link-icon").parents('p').css({'border':'1px solid blue'});
	
	/* http://gfrs.de/
	ABQIAAAA2Z8hEVGnLSnW-LvT-fDl7BQEGGRclOnz-AEVtcAFiuwkIaQChBTvJPr5A-SWymfa7q0jfu-P1N_aLg
	http://cms.gfrs.de/
	ABQIAAAA2Z8hEVGnLSnW-LvT-fDl7BQGl7P5bL2Tuf-fpZykQuhgPHL8cRQD2C1G8x1c6oVsUCSQCAgnVk-DWQ
	http://maps.google.de/maps?f=q&hl=de&geocode=&q=Prinzenstra%C3%9Fe+4,+G%C3%B6ttingen&sll=51.151786,10.415039&sspn=9.583414,19.248047&ie=UTF8&ll=51.534697,9.934065&spn=0.009277,0.018797&z=16
	*/
	if($("body#b44").length > 0) {
		if (GBrowserIsCompatible()) {
			// Die Landkarte auf der Webseite darstellen
			if($("#map-gfrs").length > 0) {
				var map = new GMap2(document.getElementById("map-gfrs"));
				// Mittelpunkt der Karte				
				var mapcenter = new GLatLng(51.5345907, 9.93146896);
				// Vergrösserungsfaktor
				var zoomLevel = 16;
				// Zentrum setzen
				map.setCenter(mapcenter, zoomLevel);
				// Bedienelemente für Zoom und Pan anzeigen map.addControl(new GSmallMapControl());
				
				map.addControl(new GLargeMapControl());
				map.addControl(new GMapTypeControl());
				map.addControl(new GScaleControl());
				
				var dbPoint = new GLatLng(51.53688642, 9.92681265);
				var dbIcon = new GIcon();				
				dbIcon.image = "http://cms.gfrs.de/fileadmin/pics/icons/db.png";
				dbIcon.iconSize = new GSize(30, 20);
				dbIcon.iconAnchor = new GPoint(15, 12);
				dbMarkerOptions = { icon:dbIcon };
				map.addOverlay(new GMarker(dbPoint, dbMarkerOptions));
				
				// Create our "tiny" marker icon
				var gfrsPoint = new GLatLng(51.53428370277219, 9.934086799621582);
				// var gfrsPoint = new GLatLng(51.53449059, 9.93415117);
				var gfrsIcon = new GIcon();				
				gfrsIcon.image = "http://cms.gfrs.de/fileadmin/pics/icons/gfrs_map.png";
				gfrsIcon.shadow = "http://cms.gfrs.de/fileadmin/pics/icons/gfrs_map_shadow.png";
				gfrsIcon.iconSize = new GSize(55, 64);
				gfrsIcon.shadowSize = new GSize(139, 68);
				gfrsIcon.iconAnchor = new GPoint(33, 64);
				gfrsIcon.infoWindowAnchor = new GPoint(33, 64);
				// Set up our GMarkerOptions object literal
				gfrsMarkerOptions = { icon:gfrsIcon };
				var gfrsMarker = new GMarker(gfrsPoint, gfrsMarkerOptions);
				GEvent.addListener(gfrsMarker, "click", function() {
   					 gfrsMarker.openInfoWindowHtml('<strong>GfRS mbH</strong><br />Prinzenstraße 4<br />37073 Göttingen<br />Tel.: +49-551-4887731', {maxWidth:230});
  				});
				
				// Markierung hineinpieksen
				map.addOverlay(gfrsMarker);
				
				if(map.isLoaded()) $("#map").removeClass('loading');
			}
		}
	}
	
});