jQuery(document).ready(function () 
{ 
	$(".nav_scroll").html('<a href="#" class="nav_scroll_up"><span>Hoch</span></a><a href="#" class="nav_scroll_down"><span>Runter</span></a>');
	
	$("#news_box .news_list").find(".news_item").eq(0).addClass("active_item");
  if ($("#news_box .news_list").find(".news_item").size()>2)
  {
    $("#news_box .news_list").scrollTo( 0 );	
    $("#news_box a.nav_scroll_up").click(function(){
      scrollInList("#news_box .news_list",-1);
      return false;
    });
    $("#news_box a.nav_scroll_down").click(function(){
      scrollInList("#news_box .news_list",1);
      return false;
    });
  }
	
	$("#termin_box .news_list").find(".news_item").eq(0).addClass("active_item");
  if ($("#termin_box .news_list").find(".news_item").size()>2)
  {
    $("#termin_box .news_list").scrollTo( 0 );
    $("#termin_box a.nav_scroll_up").click(function(){
      scrollInList("#termin_box .news_list",-1);
      return false;
    });
    $("#termin_box a.nav_scroll_down").click(function(){
      scrollInList("#termin_box .news_list",1);
      return false;
    });
	}
  
	$("#news_full .news_list").find(".news_item").eq(1).addClass("active_item");
  if ($("#news_full .news_list").find(".news_item").size()>2)
  {
  /*
    $("#news_full .news_list_container").scrollTo($("#news_full .news_list .active_item"),{
        offset:-270
      });
      */
    $("#news_full a.nav_scroll_up").click(function(){
      scrollInHorizontalList("#news_full .news_list_container",-1);
      return false;
    });
    $("#news_full a.nav_scroll_down").click(function(){
      scrollInHorizontalList("#news_full .news_list_container",1);
      return false;
    });
  }
  
	$(function() {
		$('#index #news_box .news_item').each(function() {
			var image_height = $('.image_box', this).outerHeight();
			var text_height = $('.text_box .text', this).outerHeight();
			if (image_height > text_height) 
			{
				var real_height = image_height - 5;
				$('.text_box .text', this).css('min-height', real_height);
			}
		});
		return true;
	});
	
});

function scrollInList(elem,direction) {
	var newElem;
	
	var activeElem = $(elem+" .active_item");
	if(direction==1) {
		newElem = activeElem.nextAll(".news_item").slice(0,-1);
	} else {
		newElem = activeElem.prevAll(".news_item");
	}
	if(newElem.length>0) {
		newElem = newElem.eq(0);
		activeElem.removeClass("active_item");
		newElem.addClass("active_item");
		$(elem).scrollTo($(elem+" .active_item"),{
			duration:1200
		});
	}
}
function scrollInHorizontalList(elem,direction) {
	var newElem;
	
	var activeElem = $(elem+" .active_item");
	if(direction==1) {
		newElem = activeElem.nextAll(".news_item");
	} else {
		newElem = activeElem.prevAll(".news_item");
	}
	if(newElem.length>0) {
		newElem = newElem.eq(0);
		activeElem.removeClass("active_item");
		newElem.addClass("active_item");
		$(elem).scrollTo($(elem+" .active_item"),{
			duration:1200,
			offset:-270
		});
	}
}

