

// Hersteller-Animation


	function gettotalLogowidth(ahbkpath) {
		$("#hersteller").fadeIn();
		totalWidth = 0;	
		count = 0;
		$(".hersteller-inner a").each(
			function(i) {
				totalWidth = totalWidth+$(this).width();
			}
		);
		$(".hersteller-wrap").width(totalWidth*2);
		$(".hersteller-inner").width(totalWidth);
		
		if(totalWidth >= 950)
			animateLogos(totalWidth, totalWidth*50);

		$("#hersteller").prepend('<img src="'+ ahbkpath +'img/hersteller-left-gradient.png" class="leftgradient" />');
		$("#hersteller").prepend('<img src="'+ ahbkpath +'img/hersteller-right-gradient.png" class="rightgradient" />');
	};

	function animateLogos(destination, speed) {

		$(".hersteller-inner").clone(true).insertAfter(".hersteller-inner").removeClass("actual");
		$(".actual").animate({marginLeft: "-"+destination}, speed, "linear",
			function() {
				$(this).removeClass("actual");
					$(this).next().addClass("actual");
				$(this).remove();								
				animateLogos(destination, speed);
			}
		);
	}


// Fix Scroll-To for iPad
	var anchor = self.document.location.hash.substring(1);
						
	if ( /webkit.*mobile/i.test(navigator.userAgent)) {
	  (function($) {
	      $.fn.offsetOld = $.fn.offset;
	      $.fn.offset = function() {
	        var result = this.offsetOld();
	        result.top -= window.scrollY;
	        result.left -= window.scrollX;
	        return result;
	      };
	  })(jQuery);
	}



$(document).ready(function(){

// Klipp-Klapp für News

	$("h3.news-headline").each(
		function(){
			if(anchor){
				if($(this).attr("id") == anchor){
					open($(this));
					if(anchor){
						$.scrollTo("#"+anchor, 800);
						return false;
					}	
				}
			} else {
				open($(this));
				return false;
			}
		}
	);


	function open(elem) {
		var scroll_tar = elem.parent().prev().attr("id");
		h1 = elem.next("div").children("div.subtitle").height();
		h2 = elem.next("div").children("div.news-txt").height();

				
	 	elem.next("div").animate({height: h1+h2+20 + "px"}, 800,
			function(){
				if(!elem.hasClass("c_0"))
					$.scrollTo("#"+scroll_tar, 800);				
			}
		);

		elem.parent("div").addClass("open");
		
	}

	function close(elem) {

	 	elem.next("div").animate({height: "0px"}, 800);
		elem.parent("div").removeClass("open");
	}

	$("h3.news-headline").toggle(
		function(){
			if($(this).parent().hasClass("open"))
				close($(this));
			else
				open($(this));
		},
		function(){
			if(!$(this).parent().hasClass("open"))
				open($(this));
			else
				close($(this));
		}
	);


	if($("#sidebar").length) {
		sidebar_el = $("#sidebar");
		subnav_height = sidebar_el.prev().height();

		if(subnav_height != 0)
			if(subnav_height < 344)
				sidebar_el.css("margin-top", 373-subnav_height + "px");
			else
				sidebar_el.css("margin-top", 38 + "px");
		else
			sidebar_el.css("margin-top", 382 + "px");
	}



})
