$(function() { 

	$('#newswahl .newsf_leftf:first').hide();

	$.getScript('js_bkm/colorbox.js', function() { 
		$('a.layer, a:has(img.zoom)').colorbox({
			close: '<small>schlie&szlig;en</small>',
			opacity: 0.6,
			current: "<small>Bild {current} von {total}</small>",
			previous: "<big><strong>&laquo;</strong></big>",
			next: "<big><strong>&raquo;</strong></big>",
			slideshowStart: "Slideshow starten",
			slideshowStop: "Slideshow anhalten",
			slideshow: true,
			slideshowAuto: false,
			slideshowSpeed: 3500
		});
		$('a:has(img.zoom)').attr({ rel: 'galerie' });
	});

	// ToggleBox
	$('.togglebox').each(function() { 
		$(this)
			.find('h2')
			.nextUntil('h2')
			.wrap('<div class="hidecontent"></div>');
		$(this)
			.find('h2')
			.click(function() { 
				$(this)
					.toggleClass('auf')
					.nextUntil('h2')
					.slideToggle(400);
			});
	});
	
	// TagCloud
	var i = 100;
	$('ul.tagcloud li').each(function() { 
		$(this).val(i--);
	});	
	$("ul.tagcloud").tagcloud({ 
		sizemin: 11, 
		sizemax: 18,
		colormax: '222222',
		colormin: '9a9a9a',
		height: 140
	});
	
	// Navigation
	if($('div.suchliste').length) { 
		$('#nav li').removeClass('aktiv');
	};
	$('#nav').removeClass('nojs');
	$('#nav li:not(.aktiv) ul').hide();
	$('#nav ul li:last-child').addClass('nobg');
	$('#nav li').hover(function() { 
		$('#nav li ul').hide();
		$(this).addClass('hover');
	}, function() { 
		$(this).removeClass('hover');
		if($('#nav li.hover').length == 0) { 
			$('#nav li.aktiv ul').show();
		};
	});
	
	// News in Box
	$('.box h2.newstitel a').click(function() { 
	  if($(this).not('.toggleauf').length != 0) { 
		$(this)
			.parent()
			.parent()
			.find('h2.newstitel a')
			.removeClass('toggleauf')
			.parent()
			.next()
			.slideUp(400)
			.next()
			.find('a')
			.slideUp(400);
		};

		$(this)
			.toggleClass('toggleauf')
			.parent()
			.next()
			.slideToggle(400)
			.next()
			.find('a')
			.slideToggle(400);
		return false;
	});
		
		
	// rechte Spalte toggle	
	$('#rechte_spalte div.togglelinks p').hide(); 
	$('#rechte_spalte div.togglelinks h3').each(function() { 
		$(this)
			.show()
			.addClass('h3toggle')
			.click(function() { 
				$('#rechte_spalte div.togglelinks p').slideUp(400);
				$('#rechte_spalte div.togglelinks h3').removeClass('auf');
				$(this)
					.toggleClass('auf')
					.next()
					.slideToggle(400);
			});	
	});
	
	
	$(".box.slide div.eintrag h4").textOverflow('&hellip;', true);
	startSlides();
	
});

/* Captcha-Bild aktualisieren */
function newCaptcha() {
	document.getElementById('captcha').src = 'func/modul_captcha/securimage/securimage_show.php?sid=' + Math.random(); 
	return false;
}

// Slidebox auf Startseite
function startSlides() {
	var i = 0;
	var limit = $(".box.slide div.eintrag").size();
	var myInterval = window.setInterval(function() {
		var element = $(".box.slide div.eintrag:first");
 		$(element).slideUp(800, function() { 
			$(element).appendTo('.box.slide').fadeIn(800);
		});

		i++;
		if(i==limit){
			window.setTimeout(function() {
				clearInterval(myInterval);
				startSlides();
			});
		}
	}, 5000);
}


/*
 * jQuery Text Overflow v0.7
 *
 * Licensed under the new BSD License.
 * Copyright 2009-2010, Bram Stein
 * All rights reserved.
 */
(function(c){var b=document.documentElement.style,d=("textOverflow" in b||"OTextOverflow" in b),a=function(f,i){var h=0,e=[],g=function(j){var l=0,k;if(h>i){return}for(l=0;l<j.length;l+=1){if(j[l].nodeType===1){k=j[l].cloneNode(false);e[e.length-1].appendChild(k);e.push(k);g(j[l].childNodes);e.pop()}else{if(j[l].nodeType===3){if(h+j[l].length<i){e[e.length-1].appendChild(j[l].cloneNode(false))}else{k=j[l].cloneNode(false);k.textContent=c.trim(k.textContent.substring(0,i-h));e[e.length-1].appendChild(k)}h+=j[l].length}else{e.appendChild(j[l].cloneNode(false))}}}};e.push(f.cloneNode(false));g(f.childNodes);return c(e.pop().childNodes)};c.extend(c.fn,{textOverflow:function(g,e){var f=g||"&#x2026;";if(!d){return this.each(function(){var l=c(this),m=l.clone(),p=l.clone(),k=l.text(),h=l.width(),n=0,o=0,j=k.length,i=function(){if(h!==l.width()){l.replaceWith(p);l=p;p=l.clone();l.textOverflow(g,false);h=l.width()}};l.after(m.hide().css({position:"absolute",width:"auto",overflow:"visible","max-width":"inherit"}));if(m.width()>h){while(n<j){o=Math.floor(n+((j-n)/2));m.empty().append(a(p.get(0),o)).append(f);if(m.width()<h){n=o+1}else{j=o}}if(n<k.length){l.empty().append(a(p.get(0),n-1)).append(f)}}m.remove();if(e){setInterval(i,200)}})}else{return this}}})})(jQuery);
