Cufon.replace('.article h1, .article h2[class!=topic][class!=name], fieldset h2[class!=name], .overlay h2');
// Clone the currently selected secondary navigation section into the #wrapper, so it appears
// on top of the main content
jQuery(document).ready(function($) {
	var top_slides = $('.top_slide');
	if (top_slides.length && top_slides.length > 1) {
		var ipause = false;
		$('#top_slides_container').mouseenter(function() {
			ipause = true;
		}).mouseleave(function() {
			ipause = false;
		});

		var itimeout = 5;
		var iprev = null;
		var icurr = 1;
		var ilength = top_slides.length;
		var ival = itimeout;
		setInterval(function() {
			if (!ipause && !--ival) {
				ival = itimeout;
				iprev = icurr;
				if (++icurr > ilength) {
					icurr = 1;
				}

				//$('#top_slide_' + icurr).fadeIn(500);
				//$('#top_slide_' + iprev).fadeOut(500);
				$('#top_slides_movable').animate({
					left: -876
				}, 366, function() {
					$('#top_slides_movable .top_slide:first').clone().appendTo('#top_slides_movable');
					$('#top_slides_movable .top_slide:first').remove();
					$('#top_slides_movable').css('left', 0);
				});
			}
		}, 1000);
	}

	$('#secondary_navigation .selected a')
		.clone()
		.prependTo('#body')
		.addClass('secondary_navigation_clone')
		.attr('id', $('#secondary_navigation .selected').attr('id')+'_clone');

	// If we ever decide to stop supporting IE6, remove this. It combines multiple class selectors
	// into one single class names, so that IE6 will actually recognize them.
	// Ex.: class="first article" becomes class="first article first-article article-first"
	$('body *[class]').each(function(i, el) {
		if(( /\w+\s+\w+/ ).test(el.className)) {
			el.className += ' '+(el.className.replace(/\s+/, '-'))+' '+el.className.split(' ').reverse().join('-');
		}
	});

	$('.share_button').mouseover(function(e) {
		$('.addthis_button').trigger('mouseover');
	}).mouseout(function() {
		$('.addthis_button').trigger('mouseout');
	}).click(function() {
		$('.addthis_button').trigger('click');
	});

	var ie6 = /MSIE 6/.test(navigator.userAgent);

	if (ie6) {
		var found = false,
			cookies = document.cookie.split( ';' ),
			temp,
			xx = cookies.length,
			x = 0;

		// search ie6x cookie
		for (; x < xx; ++x) {
			temp = cookies[x].split('=');
			temp = temp[0].replace(/^\s+|\s+$/g, '');
			if (temp == 'ie6x') {
				found = true;
				break;
			}
		}

		// if no ie6 cookie, do some stuff
		if (!found) {
			// set ie6x cookie
			var date = new Date();
			date.setTime(date.getTime() + 24*60*60*1000);	// set cookie for 1 day
			document.cookie = 'ie6x=1; expires=' + date.toGMTString() + '; path=/';

			// show mask
			Mask.show_mask(2);

			// set html and show it
			$('#ie6x').html(('<a href="javascript:;" class="close" onclick="ie6x_close()">Schlie&szlig;en X</a>'
							+'<h2>Hinweis</h2>'
							+'<p>Sie benutzen einen unzeitgem&auml;&szlig;en Browser, der mindestens 8 Jahre alt ist. Bitte installieren sie eine aktuelle Browserversion um die Seite mit allen Features und Neuheiten genie&szlig;en zu k&ouml;nnen.</p>'
							+'<ul>'
							+'	<li><a class="more" href="http://www.microsoft.com/windows/internet-explorer/default.aspx"><img src="@@/images/browsers/msie.gif" />Internet Explorer updaten</a></li>'
							+'	<li><a class="more" href="http://www.mozilla.com/firefox/"><img src="@@/images/browsers/firefox.gif" />Mozilla Firefox installieren</a></li>'
							+'	<li><a class="more" href="http://www.google.com/chrome/"><img src="@@/images/browsers/chrome.gif" />Google Chrome installieren</a></li>'
							+'	<li><a class="more" href="http://www.apple.com/safari/"><img src="@@/images/browsers/safari.gif" />Safari installieren</a></li>'
							+'</ul>').replace(/@@/g, _BASE_DOMAIN_URL + 'public'))
					  .css({
					  	left: '50%',
					  	top: '100px',
						zIndex: 5
					  }).show();
		}
	}

	// move all overlays in body - crap..
	$(document.body).append($('.overlay'));

	// set all overlays z-index
	$('.overlay').css({
		zIndex: 5
	});

	// attach the show handlers
	$('a[class*=overlay_trigger][rel]').click(function() {
		var overlay;
		if (this.rel && (overlay = $('#' + this.rel))) {
			if (parseInt(overlay.css('top'))) {
				if (ie6)
				$('select').css({
					visibility: 'hidden'
				});

				Mask.show_mask(2);

				overlay.first().css({
					top: parseInt($(window).scrollTop() + ($(window).height() - overlay.height()) / 2 - 50) + 'px'
				});
			} else {
				overlay.first().css({
					top: '-10000px'
				});

				Mask.show_mask();

				if (ie6)
				$('select').css({
					visibility: 'visible'
				});
			}
		}
	});

	// attach the close handler
	$('.overlay a.close').click(function() {
		$(this).parent('.overlay').first().css({
			top: '-10000px'
		});

		Mask.show_mask();

		if (ie6)
		$('select').css({
			visibility: 'visible'
		});
	});
});

function ie6x_close() {
	$('#ie6x').css('display', 'none');
	Mask.show_mask();
}
