$(document).ready(function() {
	
	$(".newsheader").next(".newstext").hide();
	$(".newsheader_odd").next(".newstext").hide();
	
	$(".newsheader_first .newstoggle").toggle(
		function() {
			$(this).parent().next(".newstext").hide();
			$(this).parent().css("height", "38px");
			$(this).attr("src", "/gfx/news_aufklappen.png");
		},
		function() {
			$(this).parent().next(".newstext").show();
			$(this).parent().css("height", "52px");
			$(this).attr("src", "/gfx/news_zuklappen.png");
		}
		
	);
	
	$(".newsheader .newstoggle").toggle(
		function() {
			$(this).parent().next(".newstext").show();
			$(this).parent().css("height", "32px");
			$(this).parent().css("background-image", "url(/gfx/news_schmaler_bg_1.jpg)");
			$(this).attr("src", "/gfx/news_zuklappen.png");
		},
		function() {
			$(this).parent().next(".newstext").hide();
			$(this).parent().css("height", "18px");
			$(this).parent().css("background-image", "url(/gfx/news_schmaler_bg_1_zu.jpg)");
			$(this).attr("src", "/gfx/news_aufklappen.png");
		}
	);
	
	$(".newsheader_odd .newstoggle").toggle(
		function() {
			$(this).parent().next(".newstext").show();
			$(this).parent().css("height", "32px");
			$(this).parent().css("background-image", "url(/gfx/news_schmaler_bg_2.jpg)");
			$(this).attr("src", "/gfx/news_zuklappen.png");
		},
		function() {
			$(this).parent().next(".newstext").hide();
			$(this).parent().css("height", "18px");
			$(this).parent().css("background-image", "url(/gfx/news_schmaler_bg_2_zu.jpg)");
			$(this).attr("src", "/gfx/news_aufklappen.png");
		}
	);
	
	// featured
	var $featured_area = $('#featured');
	var $featured_item = $('#featured .featitems .featitem');
	var $slider_control = $('#featured .featitems');
	var $image_container = $('#featured .featimg');
	var ordernum;
	var pause_scroll = false;
			
	$image_container.css("background-color","#000000");
		


	$featured_area.mouseover(function(){
		pause_scroll = true;
	}).mouseout(function(){
		pause_scroll = false;
	});

	function gonext(this_element){
		$slider_control.find(".featitem.active").removeClass('active');
		this_element.addClass('active');
		ordernum = this_element.find("span.order").html();
		$('.featimg').cycle(ordernum - 1);
	} 
		
	$featured_item.click(function() {
		clearInterval(interval);
		gonext($(this)); 
		
	});
		
	var auto_number;
	var interval;
	
	$featured_item.bind('autonext', function autonext(){
		if (!(pause_scroll)) gonext($(this)); 
		return false;
	});
	
	interval = setInterval(function () {
			auto_number = $slider_control.find("div.featitem.active span.order").html();
			if (auto_number == $featured_item.length) auto_number = 0;
			$featured_item.eq(auto_number).trigger('autonext');
		}, 4000);
	
	$('.featimg').cycle({
		timeout: 0,
		speed: 400,
		fx: 'fade'
	});
	
});