/**
 * @author Christian Beckmann
 * @since 30.04.2009
 * @last changed 17.06.2009
 * @version 0.2
 */

var aktiv = null;

function setStartBild() {
jQuery(function($) {

	if (($('div.bigteaserBox') != null) && ($('div.bigteaserBox').length > 0)) {
		$('div.bigteaserBox').find('div.startbilder').each(function(event){
			if (!$(this).hasClass('hide')) {
				
				$(this).fadeOut('slow', function() {
					$(this).addClass('hide');
					$(this).css('display','block');

				if ($(this).next('div.startbilder').length > 0) {
					$(this).next('div.startbilder').css('display','none');
					$(this).next('div.startbilder').removeClass('hide');

					$(this).next('div.startbilder').fadeIn('slow');

					var nr = $('div.bigteaserBox').find('div.startbilder').index(this)+2;
					$('#startbild_navi .startbild_nr_down').html(nr);

					return false;
				}
				else {
					var el = $('div.bigteaserBox').find('div.hide')[0];
					$(el).css('display','none');
					$(el).removeClass('hide');
					$(el).fadeIn('slow');

					$('#startbild_navi .startbild_nr_down').html('1');
					return false;
				}

				});
			}
		});
	}

});

}

function prevStartBild() {
jQuery(function($) {
	
	if ($('div.bigteaserBox').length > 0) {
		$('div.bigteaserBox').find('div.startbilder').each(function(event){
			if (!$(this).hasClass('hide')) {
				if ($(this).prev("div.startbilder").length > 0) {
					$(this).fadeOut('slow', function() {
						$(this).addClass('hide');
						$(this).css('display','block');
						
						$(this).prev('div.startbilder').css('display','none');
						$(this).prev('div.startbilder').removeClass('hide');

					var nr = $('div.bigteaserBox').find('div.startbilder').index(this);
					$('#startbild_navi .startbild_nr_down').html(nr);
						
						$(this).prev('div.startbilder').fadeIn('slow')
						return false;
					});
				} else {
					$(this).fadeOut('slow', function() {
						$(this).css('display','block');
						$(this).addClass('hide');
						
						$('div.bigteaserBox div.startbilder:last').css('display','none');
						$('div.bigteaserBox div.startbilder:last').removeClass('hide');

					var nr = $('div.bigteaserBox').find('div.startbilder').index(this)+2;
					$('#startbild_navi .startbild_nr_down').html($('#startbild_navi .startbild_nr_up').html());
						
						$('div.bigteaserBox div.startbilder:last').fadeIn('slow');
						return false;
					});
				}
			}
		});
	}

});

}

function startBildWeiter() {
	//setStartBild();
	aktiv = window.setInterval("setStartBild()", 18000);
	/*if ($('#startbild_navi .startbild_nr_down').html() == $('#startbild_navi .startbild_nr_up').html()) {
		$('#startbild_navi .startbild_nr_down').html('1');		
	} else {
		$('#startbild_navi .startbild_nr_down').html(parseInt($('#startbild_navi .startbild_nr_down').text())+1);			
	}*/
}

var artikel_bildindex = 0;

jQuery(document).ready(function($){
	//$('.topnews').children('a.entry')
	if (($('div.bigteaserBox') != null) && ($('div.bigteaserBox').length > 0)) {
		//aktiv = window.setInterval("startBildWeiter()", 9000);
		startBildWeiter();
	}

  if ($('.start_next') != null){
  	$('.start_next').click(function(event) {
  		event.preventDefault();
  		//Zeitintervall vorübergehend stoppen beim Blättern
  		window.clearInterval(aktiv);
  		setStartBild();
  		//aktiv = window.setInterval("startBildWeiter()", 9000);
		startBildWeiter();
  		
  	});
	}
	
	if ($('.start_prev') != null){
  	$('.start_prev').click(function(event) {
  		event.preventDefault();
  		//Zeitintervall vorübergehend stoppen beim Blättern
  		window.clearInterval(aktiv);
		prevStartBild();
  		aktiv = window.setInterval("startBildWeiter()", 18000);
  		/*if ($('#startbild_navi .startbild_nr_down').html() == '1') {
  			$('#startbild_navi .startbild_nr_down').html($('#startbild_navi .startbild_nr_up').html());
  		} else {
  			$('#startbild_navi .startbild_nr_down').html(parseInt($('#startbild_navi .startbild_nr_down').text())-1);						
  		}*/
  	});
	}
	
	//Beim Aspielen des Videos soll der Intervall nicht weiterlaufen 
	$('.bt_play').click(function(event) {
		event.preventDefault();
		window.clearInterval(aktiv);
	});
	
	if ($('.bt_allthemes') != null){
  	$('.bt_allthemes').click(function(event) {
  		event.preventDefault();
  		$('#allethemen').css('z-index','11');
		window.clearInterval(aktiv);
  	});
  }
  
  if ($('#allethemen .zurueck') != null){
  	$('#allethemen .zurueck').click(function(event) {
  		event.preventDefault();
  		$('#allethemen').css('z-index','1');
		aktiv = window.setInterval("startBildWeiter()", 18000);
  	});
	}

	//Widget Aktuelle Nachrichten
	if ($('div.scrollable') != null){
	 $("div.scrollable").scrollable({vertical:true, size: 3,loop:false,interval:9000}); 
  
	 var api = $("div.scrollable").scrollable({vertical:true, size: 3,next: 'a.down', prev: 'a.up' });
	}
	
	if ($('.up') != null){
  	$('.up').click(function(event) {
  		$("div.scrollable").scrollable().prevPage(); 
  	});
  }
  if ($('.down') != null){
  	$('.down').click(function(event) {
  		$("div.scrollable").scrollable().nextPage(); 	
  	});
	}
  

  	$('#dv_wahlkreis').change(function() {
  		window.document.location.href=""+$(this).attr("value")+".html";
  	});

	
});

function newsbox(val) {
	if(val == 'aktuelles'){
		$("#termine_newsbox").addClass("hide");
		$("#aktuelles_newsbox").removeClass("hide");
		$(".tabnavi .aktuell").addClass("cur");
		$(".tabnavi .termine").removeClass("cur");
	} 
	if(val == 'termine'){
		$("#aktuelles_newsbox").addClass("hide");
		$("#termine_newsbox").removeClass("hide");
		$(".tabnavi .termine").addClass("cur");
		$(".tabnavi .aktuell").removeClass("cur");
	}
}