

/* querystring fuer aktuelle news abfragen */
function querySt(arg) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == arg) {
			return ft[1];
		}
	}
}

var newsid = querySt("newsid");


$(document).ready(function(){
  var expander = $('#expanderModule ul li');
  var teaser = expander.children('.teaser_box'); 
  var images = expander.children('.image_box');
  var contents = expander.children('.content_box_ohne');
  
  var expanderHeight = Array();
  var imagesHeight = Array();
  var teaserHeight = Array();
  var contentsHeight = Array();
  
  $('.image_box img:first').css('margin-top', 0);
    
  expander.each(function(i,e){
    expanderHeight[i] = $(this).innerHeight();
  });
  teaser.each(function(i,e){
    teaserHeight[i] = $(this).height();
  }); 
  images.each(function(i,e){
    imagesHeight[i] = $(this).height();
  });
  contents.each(function(i,e){
    contentsHeight[i] = $(this).innerHeight();
  });
  
  contents.hide();
    
					
  expander.css('cursor', 'pointer').click(function(){  
      
    var ii = $(this).index();
      
    if(images.length != 0){
      images.not(':eq('+ii+')').stop().slideUp().css('border-bottom', '1px solid #aeaeae');
      images.eq(ii).stop().slideDown().css('border-bottom', '1px solid #aeaeae');
    }
    contents.not(':eq('+ii+')').stop().slideUp();
 		
		if(contents.eq(ii).hasClass('on')){
			contents.eq(ii).stop().slideUp();
			if ($('#expanderModule').hasClass('zwei_zeilen_teaser')) {
				teaser.not(':eq('+ii+')').stop().animate({ height: 74 });
			} else {
				teaser.not(':eq('+ii+')').stop().animate({ height: 67 });
			}
			if(images.length != 0){
				images.not(':eq('+ii+')').stop().slideDown().css('border-bottom', '1px solid #aeaeae');
			}
			contents.eq(ii).removeClass('on');
			
		} else {
			contents.eq(ii).stop().slideDown();
			contents.eq(ii).addClass('on');
			teaser.not(':eq('+ii+')').stop().animate({ height: 30 });
			contents.not(':eq('+ii+')').removeClass('on');
		}		
    
    teaser.eq(ii).stop().animate({ height: teaserHeight[ii] });
  });
	
	
	// News ausgeklappt anzeigen, wenn von Newsletter QueryString newsid=1 fuer 1. News, newsid=2 fuer 2. News etc uebergeben.
	if (typeof newsid=="string") {
		var intNewsid = parseInt(newsid);
		intNewsid = intNewsid - 1;
		if(images.length != 0){
      images.not(':eq('+intNewsid+')').stop().slideUp().css('border-bottom', '1px solid #aeaeae');
      images.eq(intNewsid).stop().slideDown().css('border-bottom', '1px solid #aeaeae');
    }
    contents.not(':eq('+intNewsid+')').stop().slideUp();
    contents.eq(intNewsid).stop().slideDown();
		contents.eq(intNewsid).addClass("on");
    
    teaser.not(':eq('+intNewsid+')').stop().animate({ height: 30 });
    teaser.eq(intNewsid).stop().animate({ height: teaserHeight[intNewsid] });		
	}
	
});
