function parse_url (str, component) {
	// Parse a URL and return its components, version: 905.3122
	var  o   = {
		strictMode: false,
		key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
		q: {
			name: "queryKey",
			parser: /(?:^|&)([^&=]*)=?([^&]*)/g
		},
		parser: {
			strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
			loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // Added one optional slash to post-protocol to catch file:/// (should restrict this)
		}
	};
	
	var m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i = 14;
	while (i--) {uri[o.key[i]] = m[i] || "";}
	// Uncomment the following to use the original more detailed (non-PHP) script
	/*
	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
	if ($1) uri[o.q.name][$1] = $2;
	});
	return uri;
	*/
	
	switch (component) {
		case 'PHP_URL_SCHEME':
			return uri.protocol;
		case 'PHP_URL_HOST':
			return uri.host;
		case 'PHP_URL_PORT':
			return uri.port;
		case 'PHP_URL_USER':
			return uri.user;
		case 'PHP_URL_PASS':
			return uri.password;
		case 'PHP_URL_PATH':
			return uri.path;
		case 'PHP_URL_QUERY':
			return uri.query;
		case 'PHP_URL_FRAGMENT':
			return uri.anchor;
		default:
			var retArr = {};
			if (uri.protocol !== '') {retArr.scheme=uri.protocol;}
			if (uri.host !== '') {retArr.host=uri.host;}
			if (uri.port !== '') {retArr.port=uri.port;}
			if (uri.user !== '') {retArr.user=uri.user;}
			if (uri.password !== '') {retArr.pass=uri.password;}
			if (uri.path !== '') {retArr.path=uri.path;}
			if (uri.query !== '') {retArr.query=uri.query;}
			if (uri.anchor !== '') {retArr.fragment=uri.anchor;}
			return retArr;
	}
}


function strpos( haystack, needle, offset){
	var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
	return i === -1 ? false : i;
}

function openExternalNews() {
	if (strpos(document.location.href, '/Presse/Nachrichten/items/')>0) {
		var gotoUrl = jQuery("#blockContent div.elementLink a").attr('href');
		window.open(gotoUrl);
	}
}

function strrev( string ){
	var ret = '', i = 0;
	string += '';
	for ( i = string.length-1; i >= 0; i-- ){
		ret += string.charAt(i);
	}
	return ret;
}

function substr( f_string, f_start, f_length ) {
	f_string += '';
	if(f_start < 0) {
		f_start += f_string.length;
	}
	
	if(f_length === undefined) {
		f_length = f_string.length;
	} else if(f_length < 0){
		f_length += f_string.length;
	} else {
		f_length += f_start;
	}
	
	if(f_length < f_start) {
		f_length = f_start;
	}
	return f_string.substring(f_start, f_length);
}

function str_replace(search, replace, subject, count) {
/**
	var r;
	var s = subject;
	var ra = r instanceof Array, sa = s instanceof Array;
	var f = [].concat(search);
	r = [].concat(replace);
	var i = (s = [].concat(s)).length;
	var j = 0;
	while (j = 0, i--) {
		if (s[i]) {
			while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
		}
	}
	return sa ? s : s[0];
**/
	// version: 908.406
	var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }

    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];

}

function utf8_decode ( str_data ) {
	var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0;
	str_data += '';
	while ( i < str_data.length ) {
		c1 = str_data.charCodeAt(i);
		if (c1 < 128) {
			tmp_arr[ac++] = String.fromCharCode(c1);
			i++;
		} else if ((c1 > 191) && (c1 < 224)) {
			c2 = str_data.charCodeAt(i+1);
			tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
			i += 2;
		} else {
			c2 = str_data.charCodeAt(i+1);
			c3 = str_data.charCodeAt(i+2);
			tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
			i += 3;
		}
	}
	return tmp_arr.join('');
}

//////////////////// scroll ////////////////////////////////////////////////////////////////////////////
jQuery.getPos = function (e)
{
	var l = 0;
	var t  = 0;
	var w = jQuery.intval(jQuery.css(e,'width'));
	var h = jQuery.intval(jQuery.css(e,'height'));
	var wb = e.offsetWidth;
	var hb = e.offsetHeight;
	while (e.offsetParent){
		l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
		t += e.offsetTop  + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
		e = e.offsetParent;
	}
	l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
	t  += e.offsetTop  + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
	return {x:l, y:t, w:w, h:h, wb:wb, hb:hb};
};
jQuery.getClient = function(e)
{
	if (e) {
		w = e.clientWidth;
		h = e.clientHeight;
	} else {
		w = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;
		h = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
	}
	return {w:w,h:h};
};
jQuery.getScroll = function (e) 
{
	if (e) {
		t = e.scrollTop;
		l = e.scrollLeft;
		w = e.scrollWidth;
		h = e.scrollHeight;
	} else  {
		if (document.documentElement && document.documentElement.scrollTop) {
			t = document.documentElement.scrollTop;
			l = document.documentElement.scrollLeft;
			w = document.documentElement.scrollWidth;
			h = document.documentElement.scrollHeight;
		} else if (document.body) {
			t = document.body.scrollTop;
			l = document.body.scrollLeft;
			w = document.body.scrollWidth;
			h = document.body.scrollHeight;
		}
	}
	return { t: t, l: l, w: w, h: h };
};

jQuery.intval = function (v)
{
	v = parseInt(v);
	return isNaN(v) ? 0 : v;
};

jQuery.fn.ScrollTo = function(s) {
	o = jQuery.speed(s);
	return this.each(function(){
		new jQuery.fx.ScrollTo(this, o);
	});
};

jQuery.fx.ScrollTo = function (e, o)
{
	var z = this;
	z.o = o;
	z.e = e;
	z.p = jQuery.getPos(e);
	z.s = jQuery.getScroll();
	z.clear = function(){clearInterval(z.timer);z.timer=null};
	z.t=(new Date).getTime();
	z.step = function(){
		var t = (new Date).getTime();
		var p = (t - z.t) / z.o.duration;
		if (t >= z.o.duration+z.t) {
			z.clear();
			setTimeout(function(){z.scroll(z.p.y, z.p.x)},13);
		} else {
			st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.y-z.s.t) + z.s.t;
			sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.x-z.s.l) + z.s.l;
			z.scroll(st, sl);
		}
	};
	z.scroll = function (t, l){window.scrollTo(l, t)};
	z.timer=setInterval(function(){z.step();},13);
};

// hoverintent
(function(jQuery) {
	jQuery.fn.hoverIntent = function(f,g) {
		// default configuration options
		var cfg = {
			sensitivity: 7,
			interval: 100,
			timeout: 0
		};
		// override configuration options with user supplied object
		cfg = jQuery.extend(cfg, g ? { over: f, out: g }: f );

		// instantiate variables
		// cX, cY = current X and Y position of mouse, updated by mousemove event
		// pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
		var cX, cY, pX, pY;

		// A private function for getting mouse position
		var track = function(ev) {
			cX = ev.pageX;
			cY = ev.pageY;
		};

		// A private function for comparing current and previous mouse position
		var compare = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			// compare mouse positions to see if they've crossed the threshold
			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
				jQuery(ob).unbind("mousemove",track);
				// set hoverIntent state to true (so mouseOut can be called)
				ob.hoverIntent_s = 1;
				return cfg.over.apply(ob,[ev]);
			}else {
				// set previous coordinates for next time
				pX = cX; pY = cY;
				// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
				ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);},cfg.interval);
			}
		};

		// A private function for delaying the mouseOut function
		var delay = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			ob.hoverIntent_s = 0;
			return cfg.out.apply(ob,[ev]);
		};

		// A private function for handling mouse 'hovering'
		var handleHover = function(e) {
			// next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
			if (e !== 'undefined') {
				var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
				while (p && p!=this){try{p=p.parentNode; }catch(e){ p = this; }}
				if ( p == this ) { return false; }
			}

			// copy objects to be passed into t (required for event object to be passed in IE)
			var ev = jQuery.extend({},e);
			var ob = this;

			// cancel hoverIntent timer if it exists
			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }

			// else e.type == "onmouseover"
			if (e.type == "mouseover") {
				// set "previous" X and Y position based on initial entry point
				pX = ev.pageX; pY = ev.pageY;
				// update "current" X and Y position based on mousemove
				jQuery(ob).bind("mousemove",track);
				// start polling interval (self-calling timeout) to compare mouse coordinates over time
				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);}, cfg.interval );}

			// else e.type == "onmouseout"
			}else {
				// unbind expensive mousemove event
				jQuery(ob).unbind("mousemove",track);
				// if hoverIntent state is true, then call the mouseOut function after the specified delay
				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);}, cfg.timeout );}
			}
		};

		// bind the function to the two event listeners
		return this.mouseover(handleHover).mouseout(handleHover);
	};
})(jQuery);

function activeState() {
	$activelinks = jQuery("ul.menulist a[href='" + location.pathname + "']").addClass('selected');
}

/* experimental */
function inlineImages() {
	if (!strpos('weblication',window.location)) {
		jQuery("#blockContent img").each(function(){
			var pxwidth = jQuery(this).width();
			if (pxwidth > 620) {
				var factor = 620 / pxwidth;
				var newht = jQuery.intval(factor * jQuery(this).height());
				jQuery(this).attr({width:620});
				jQuery(this).attr({height:newht});
			}
		});
	}
}

function imageCaptions() {
	// alert('IEsucks');
	$captions = jQuery("div.elementPicture");
	// only if there are images with captions
	if ($captions.length > 0 && !strpos(window.location,'weblication')) {
		// alert(captions.length);
		$captions.each(function(){
			jQuery(this).find('a').attr({rel:'gallery'});
			the_image = jQuery(this).find("img");
			// alert(the_image);
			the_image.load(function(){
				var the_width = the_image.width();
				var the_height = the_image.height();
				//alert('the_width: '+the_width);
				//alert('the_height: '+the_width);
				jQuery(this).attr({
					width:the_width
				}).parents("div:eq(0)").find('div.title').css({
					// width:the_width+'px'
				});
				jQuery(this).parents("div.elementPicture").css({
					width:the_width+'px'
				});
			});
		});
	}
}


function filterPath(string) {
	return string
	.replace(/^\//,'')
	.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
	.replace(/\/$/,'');
}

function smoothScroll() {
	var locationPath = filterPath(location.pathname);
	
	jQuery('a[href*="#"]').each(function() {
		var thisPath = filterPath(this.pathname) || locationPath;
		if ( locationPath == thisPath && (location.hostname == this.hostname || !this.hostname) && this.hash.replace(/#/,'') ) {
			var $target = jQuery(this.hash), target = this.hash;
			if (target) {
				var targetOffset = $target.offset().top;
				jQuery(this).click(function(event) {
					event.preventDefault();
					jQuery('html, body').animate({scrollTop: targetOffset}, 400, function() {
						location.hash = target;
					});
				});
			}
		}
	});
}

/**function smoothScroll() {
	jQuery('a[@href*="#"]:not(a[@href="#"])').click(function() {
		var parts = this.href.split('#');
		var scrolltarget = '#' + parts[1];
		jQuery(scrolltarget).ScrollTo(500);
		return false;
	});
} **/

/* jQury AlphaNumeric Addon */
(function(jQuery){jQuery.fn.alphanumeric = function(p) { 
		p = jQuery.extend({ichars: "!@#$%^&*()+=[]\\\';,/{}|\":<>?~`.- ",nchars: "",allow: ""}, p);
		return this.each(function(){
			if (p.nocaps) { p.nchars += "AÄBCDEFGHIJKLMNOÖPQRSTUÜVWXYZß"; }
			if (p.allcaps) { p.nchars += "aäbcdefghijklmnoöpqrstuüvwxyzß"; }
			s = p.allow.split('');
			for ( i=0;i<s.length;i++) {
				if (p.ichars.indexOf(s[i]) != -1) {
					s[i] = "\\" + s[i];
				}
			}
			p.allow = s.join('|');
			var reg = new RegExp(p.allow,'gi');
			var ch = p.ichars + p.nchars;
			ch = ch.replace(reg,'');
			jQuery(this).keypress (function (e) {
				if (!e.charCode) { k = String.fromCharCode(e.which); }
					else { k = String.fromCharCode(e.charCode); }
				if (ch.indexOf(k) != -1) { e.preventDefault(); }
				if (e.ctrlKey&&k=='v') { e.preventDefault(); }
			});
			jQuery(this).bind('contextmenu',function () {return false});});
	};
	jQuery.fn.numeric = function(p) {
		var az = "aäbcdefghijklmnoöpqrstuüvwxyzß";
		az += az.toUpperCase();
		p = jQuery.extend({ nchars: az }, p);
		return this.each (function() { jQuery(this).alphanumeric(p); } );
	};
	jQuery.fn.alpha = function(p) {
		var nm = "1234567890";
		p = jQuery.extend({ nchars: nm }, p);
		return this.each (function() { jQuery(this).alphanumeric(p); });
	};
})(jQuery);

// fix for common dequeue error caused by old interface.js syntax.
/**( function( jQuery ) { 
	jQuery.dequeue = function( a , b ) { return jQuery(a).dequeue(b); };
})( jQuery ); **/

function contactForm(id) {
	// limit user input to something that makes sense (numbers for the captha, alphabet for a name)
	$f = jQuery(id);
	$f.find('li.C input').numeric().attr("maxlength","4");
	$f.find('input[name="Ihr_Name"]').alpha({allow:"- "});
	$f.find('textarea').focus(function(){
		if (jQuery.trim(this.innerHTML) === '') { this.innerHTML = ''; }
	});
}

function cropText(string,length) {
	if (string.length > length) {
		var tmp_str = substr(string,0,length);
		tmp_str = strrev(tmp_str);
		var blankpos = strpos(tmp_str,' ');
		tmp_str = substr(tmp_str,blankpos+1);
		return strrev(tmp_str)+'...';
	} else {
		return string;
	}
}

function sidebarInit() {
	jQuery("p.nav").removeClass('nojs');
	jQuery("#news div.item:lt(1)").show();
	jQuery("#events div.item:gt(0)").hide();
	jQuery("#news h4 a").each(function(){
		var tmptxt = jQuery(this).text();
		jQuery(this).text(cropText(tmptxt,55));
	});
	jQuery("#news p:not('p.nav,p.date')").each(function(){
		var tmptxt = jQuery(this).html();
		jQuery(this).html(cropText(tmptxt,80));
	});
	var defhl = jQuery("#news div.item:eq(0)").find("h4").html();
	var defcopy = jQuery("#news div.item:eq(0)").find("p:not('p.nav,p.date')").html();
	var deflink = jQuery("#news div.item:eq(0)").find("a.goto-article").attr('href');
	var defdate = jQuery("#news div.item:eq(0)").find("p.date").text();
	
	var nonews = jQuery('#news div.item').length;
	var isnum;
	jQuery("#news a.next").click(function(){
			$item = jQuery(this).parents("div.item");
			if (typeof($item.attr('rel')) === 'undefined') {
				isnum = 0;
				$item.attr('rel',isnum);
			} else {
				isnum = Number($item.attr('rel'));
			}
			if (isnum>=(nonews-2)) {
				jQuery("#news a.next").css('opacity','0.3');
				return false;
			} else {
				var nextitem = isnum + 1;
				var nexthl = jQuery("#news div.item:eq("+nextitem+")").find("h4").html();
				var nextcopy = jQuery("#news div.item:eq("+nextitem+")").find("p:not('p.nav,p.date')").text();
				var nextlink = jQuery("#news div.item:eq("+nextitem+")").find("a").attr("href");
				var nextdate = jQuery("#news div.item:eq("+nextitem+")").find("p.date").text();
				$item.attr("rel",nextitem);
				
				$item.find("h4").html(nexthl);
				$item.find("p:not('p.nav,p.date')").text(nextcopy);
				$item.find("p.date").text(nextdate);
				$item.find("a.goto-article").attr("href", nextlink);
				var inextern = parse_url(nextlink,'PHP_URL_HOST');
				inextern = str_replace("www.","",inextern);
				if (substr(inextern,0,1) == '/' || inextern === '') { inextern = 'kernenergie.de'; }
				if (substr($item.find("a.goto-article").attr("href"),-3,3) == 'pdf' || inextern !== 'kernenergie.de') {
					$item.find("a.goto-article").attr("target", "_blank");
					$item.find("h4 a").attr("target", "_blank");
				} else {
					$item.find("a.goto-article").removeAttr("target");
					$item.find("h4 a").removeAttr("target");
				}
			}
			if (isnum+1>0) {
				jQuery("#news a.prev").css('opacity','1');
			}
			return false;
		});
	
	jQuery("#news a.prev").css({opacity:'0.3'}).addClass('inactive');
	var inum;
	jQuery("#news a.prev").click(function(){
		$item = jQuery(this).parents("div.item");
		if ($item.attr('rel') == 'undefined') {
			inum = 0; $item.attr('rel',inum); } else { inum = Number($item.attr('rel')); }
		var previtem = inum-1;
		if (inum-2 < 0) { jQuery(this).css({opacity:'0.3'}); }
		if (inum-1 < 0) { return false; }
		if (previtem === 0) { 
			var prevhl = defhl;
			var prevcopy = defcopy;
			var prevlink = deflink;
			var prevdate = defdate;
		} else {
			var prevhl = jQuery("#news div.item:eq("+previtem+")").find("h4").html();
			var prevcopy = jQuery("#news div.item:eq("+previtem+")").find("p:not('p.nav,p.date')").text();
			var prevlink = jQuery("#news div.item:eq("+previtem+")").find("a.goto-article").attr("href");
			var prevdate = jQuery("#news div.item:eq("+previtem+")").find("p.date").text();
		}
		$item.attr("rel",previtem);
		$item.find("h4").html(prevhl);
		$item.find("p:not('p.nav')").text(prevcopy);
		$item.find("p.date").text(prevdate);
		$item.find("a.goto-article").attr("href", prevlink);
		var inextern = parse_url(prevlink,'PHP_URL_HOST');
		inextern = str_replace("www.","",inextern);
		if (substr(inextern,0,1) == '/' || inextern === '') { inextern = 'kernenergie.de'; }
		if (substr($item.find("a.goto-article").attr("href"),-3,3) == 'pdf' || inextern !== 'kernenergie.de') {
			$item.find("a.goto-article").attr("target", "_blank");
			$item.find("h4 a").attr("target", "_blank");
		} else {
			$item.find("a.goto-article").removeAttr("target");
			$item.find("h4 a").removeAttr("target");
		}
		if (inum<10) { jQuery(this).parents("div.item").find('a.next').css({opacity:1}).show(); }
		return false;
	});
	
	// Events
	var numevents = jQuery("#events div.item").length;
	jQuery("#events h4 a").each(function(){
		var tmptxt = jQuery(this).html();
		jQuery(this).html(cropText(tmptxt,55));
	});
	jQuery("#events p:not('p.nav,p.date')").each(function(){
		var tmptxt = jQuery(this).html();
		jQuery(this).html(cropText(tmptxt,80));
	});
	var defevdate = jQuery("#events div.item:eq(0)").find("p.date").text();
	var defevtitle = jQuery("#events div.item:eq(0)").find("h4").html();
	var defevplace = jQuery("#events div.item:eq(0)").find("p:not('p.nav,p.date')").html();
	var defevlink = jQuery("#events div.item:eq(0)").find("a.goto-article").attr('href');
	// next events button
	var i = 0;
	jQuery("#events a.next").click(function(){
		if (typeof(jQuery(this).parents("div.item").attr('rel')) === 'undefined') {
			i = 0;
			jQuery(this).parents("div.item").attr('rel',i);
		} else {
			i = Number(jQuery(this).parents("div.item").attr('rel'));
		}
		if (i>=(numevents-2)) {
			jQuery(this).css({opacity:'0.3'}).addClass('inactive');
			return false;
		} else {
			var nextitem = i + 1;
			var nexthl = jQuery("#events div.item:eq("+nextitem+")").find("h4").html();
			var nextdate = jQuery("#events div.item:eq("+nextitem+")").find("p.date").text();
			var nextlink = jQuery("#events div.item:eq("+nextitem+")").find("a.goto-article").attr('href');
			var nextplace = jQuery("#events div.item:eq("+nextitem+")").find("p:not('p.date,p.nav')").text();
			// alert(jQuery("#events div.item:eq("+nextitem+") h4").text());
			jQuery(this).parents("div.item").attr("rel",nextitem);
			jQuery(this).parents("div.item").find("h4").html(nexthl);
			jQuery(this).parents("div.item").find("p:not('p.nav, p.date')").text(nextplace);
			jQuery(this).parents("div.item").find("p.date").text(nextdate);
			jQuery(this).parents("div.item").find("a.goto-article").attr({href:nextlink});
		}
		if (i+1>0) { jQuery("#events a.prev").css({opacity:'1'},250).removeClass('inactive'); }
		return false;
	});

	// previous events button
	jQuery("#events a.prev").css({opacity:'0.3'}).addClass('inactive');
	jQuery("#events a.prev").click(function(){
		if (jQuery(this).parents("div.item").attr('rel') == 'undefined') {
			var i = 0;
			jQuery(this).parents("div.item").attr('rel',i);
		} else {
			var i = Number(jQuery(this).parents("div.item").attr('rel'));
		}
		var previtem = i-1;
		if (i-2 < 0) {
			jQuery(this).css({opacity:'0.3'}).addClass('inactive');
		}
		if (i-1 < 0) {
			return false;
		}

		if (previtem === 0) { 
			var prevhl = defevtitle;
			var prevcopy = defevplace;
			var prevlink = defevlink;
			var prevdate = defevdate;
		} else {
			var prevhl = jQuery("#events div.item:eq("+previtem+")").find("h4").html();
			var prevcopy = jQuery("#events div.item:eq("+previtem+")").find("p:not('p.nav,p.date')").text();
			var prevlink = jQuery("#events div.item:eq("+previtem+")").find("a.goto-article").attr("href");
			var prevdate = jQuery("#events div.item:eq("+previtem+")").find("p.date").text();
		}
		jQuery(this).parents("div.item").attr("rel",previtem);
		jQuery(this).parents("div.item").find("h4").html(prevhl);
		jQuery(this).parents("div.item").find("p:not('p.nav,p.date')").text(prevcopy);
		jQuery(this).parents("div.item").find("p.date").text(prevdate);
		jQuery(this).parents("div.item").find("a.goto-article").attr("href", prevlink);
		if (i<10) { jQuery(this).parents("div.item").find('a.next').css({opacity:1}).removeClass('inactive'); }
		return false;
	});
}


function fixSitemap() {
	if (strpos(window.location,'Inhaltsuebersicht')>0) {
		// lösche die Heading...
		jQuery('div.wglPortletHead').remove();
		jQuery("div.wSitemap ul li ul li:last-child").addClass("last");
	}
}

function fixIE7breadcrumb () {
	jQuery('#path').css({'z-index':'1000'});
	jQuery('#path div').hover(function() {
		jQuery(this).addClass('hover');
		jQuery(this).find('ul').css({'z-index':'1000',top:'30px'});
	}, function() {
		jQuery(this).removeClass('hover');
		jQuery(this).find('ul').css({'z-index':'0',top:'-9999px'});	
	});
	jQuery('#path').mouseout(function(){
		jQuery(this).find('div').removeClass('hover');
	});
}

function sendToPrinter() {
	jQuery("#toprinter").click(function(){
		var printlocation = document.location.href;
		printlocation = printlocation + "?viewmode=print";
		printlocation = str_replace("?langVersion=0","",printlocation);
		printlocation = str_replace("?langVersion=","",printlocation);
		window.open(printlocation,"Druckversion","width=740,height=700,menubar=yes,scrollbars=yes,resize= yes,toolbar=yes,location");
		return false;
	});
}

function recognizePrintVersion() {
	// oh this was intendend - and I thought something was broken ;)
	var printlocation = document.location.href;
	if(printlocation.indexOf("viewmode=print") != -1){
		window.print();
	}
}

// Zahl der Woche fancybox
function zdw() {
	var thispage = str_replace("index.php","",document.location);
	var thishost = parse_url(document.location,'PHP_URL_HOST');
	var thisprotocol = parse_url(document.location,'PHP_URL_SCHEME');
	// console.log(thispage);
	if (thispage == thisprotocol+'://'+thishost+'/kernenergie/') {
		jQuery("div.bigContentBlock a[@title='Zahl der Woche'] img").attr({src:"/kernenergie/img/zahl_der_woche/zdw.gif","class":"pictureZDW"});
		jQuery("img.pictureZDW").parents("a:eq(0)").attr({href:"/kernenergie/Zahl-der-Woche/index.php",title:""});
		jQuery("img.pictureZDW").parents("a:eq(0)").addClass('lightbox').fancybox({
			frameWidth:320,
			frameHeight:235,
			padding:20,
			hideOnContentClick:false // enabling clickable links inside a lightboxs' content
		});
	}
}

function mailtoLinks() {
	jQuery("a[href*='mailto:']").addClass('mailto');
}

function breadcrumbFix() {
	jQuery('#path ul:empty').remove(); // delete empty ul's (TODO fix in class.Navigation.php)
}

function fancyboxInit() {
	// initialize fancybox for content links with class lightbox
	$("a.lightbox").fancybox();
	// rewrite href of links pointing to .flv's to the videoplayer iframe
	$("a[href*='.flv']:not(a[href*='playvideo.php'])").each(function(){
		var flvfile = $(this).attr('href');
		// $(this).attr('href','/kernenergie/mediapool/de/playvideo.php?videofile='+flvfile+'&iframe');
		$(this).attr('href','/kernenergie/mediapool/de/playvideo.php?videofile='+flvfile);
	});
	// initialize fancybox for videos:
	$("a[href*='.flv']").fancybox({
		frameWidth:355,
		frameHeight:310
	});
}


function utf8_encode ( argString ) {
    // Encodes an ISO-8859-1 string to UTF-8  
    // 
    // version: 905.1217
    // discuss at: http://phpjs.org/functions/utf8_encode
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: sowberry
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman
    // +   improved by: Yves Sucaet
    // +   bugfixed by: Onno Marsman
    // *     example 1: utf8_encode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'
    var string = (argString+'').replace(/\r\n/g, "\n").replace(/\r/g, "\n");

    var utftext = "";
    var start, end;
    var stringl = 0;

    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;

        if (c1 < 128) {
            end++;
        } else if((c1 > 127) && (c1 < 2048)) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc !== null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }

    if (end > start) {
        utftext += string.substring(start, string.length);
    }

    return utftext;
}

function makeTablesZebra()
{
	$(document).ready(function(){

	
	jQuery(".altTable").find(".trAlt").each(function(){jQuery(this).removeClass("trAlt")});
	jQuery(".altTable").find("tr:odd").each(function(){jQuery(this).addClass("trAlt")});

	
	
	});

}


function warenkorb() {
	$order = jQuery('#KEProduktBasket table');
	var finalorderstring = '';
	$order.find('td').each(function(){
		finalorderstring = finalorderstring + jQuery(this).text() + String.fromCharCode(13);
	});
	// finalorderstring = utf8_encode(finalorderstring);
	finalorderstring = str_replace(":",": ",finalorderstring);
	finalorderstring = str_replace("€","Euro",finalorderstring);
	jQuery("textarea[name='order']").attr({value:finalorderstring}).parents('li').hide();
}

function fotostrecke() {
	$fotostrecken = jQuery('div.fotostrecke');
	$fotostrecken.each(function(){

		// do this for each and every Fotostrecke
		var height = jQuery(this).find('img:eq(0)').attr('height');
		jQuery(this).find('img').each(function(){
			if (jQuery(this).attr('height') > height) {
				 height = (jQuery(this).attr('height'));
			}
		});
		jQuery(this).find('ul').height(height);

		// add an item number to each link
		var zaehler = 0;
		jQuery(this).find('div a').each(function(zaehler){
			jQuery(this).addClass('bild'+zaehler);
			zaehler++;
		});

		// set the visibility for the chosen item
		jQuery(this).find('div a').click(function(){
			var showimg = str_replace('bild','',this.className);
			$aktuelle_galerie = jQuery(this).parents('div.fotostrecke');
			$aktuelle_galerie.find('ul li img').fadeOut(250);
			$aktuelle_galerie.find('ul li:eq('+showimg+')').find('img').fadeIn(500);
			return false;
		});
		
	});
}



function newWindow() {
	jQuery('a.newwindow').click(function(){
		this.target = "_blank";
	});
}
// last but not least: the onload event
jQuery(document).ready(function(){
	openExternalNews(); // redirect script
	fancyboxInit();
	// mainnavEffects();
	breadcrumbFix();
	inlineImages('620');
	smoothScroll();
	contactForm("#wFormular");
	sidebarInit();
	imageCaptions();
	sendToPrinter();
	recognizePrintVersion();
	fixSitemap();
//	fixIE7breadcrumb(); it seems to work without this!!!! but why????
	zdw();
	mailtoLinks();
	activeState();
	warenkorb();
	makeTablesZebra();
	fotostrecke();
	newWindow();
	jQuery('div.thirdContentBlock:last').addClass('last');
});