$(function(){
	$(".open").mouseenter(function() {
		var subnavi = $(this).parent().find(".subnavi");
		$(".subnavi").not(subnavi).slideUp("fast");
		$(this).parent().find(".subnavi").slideDown("fast");
	});
	
	$(".subnavi").mouseleave(function() {
		$(this).slideUp("fast");
	});
	
	if ( $("span.mailme").length ) {
	  // variables, which will be replaced
	  var at = / AT /;
	  var dot = / DOT /g;

	  // function, which replaces pre-made class
	  $('span.mailme').each(function () {
		var addr = $(this).text().replace(at, '@').replace(dot, '.');
		$(this).after('<a href="mailto:' + addr + '">' + addr + '</a>');
		$(this).remove();
	  });
	}
	
	
	$(".rollingbannerlong").css('width',($(".rollingbanner .banner").size()*960)+'px');
	$(".rollingbannerlong").css('left','0px');
	bannercount = $(".rollingbanner .banner").size();
	currentbanner = 1;
	banneranimating = false;
	
	
	if (bannercount<2) {
		$(".rollingbanner .leftarrow").css('visibility','hidden');
		$(".rollingbanner .rightarrow").css('visibility','hidden');
	} else {
	
	goNext = function() {
	
			if (!banneranimating) {
		
			banneranimating=true;
			currentbanner++;
			if (currentbanner>bannercount) {
				currentbanner=1;
			}
		
			var newLeft = (currentbanner-1)*960*-1;
			
			$(".rollingbannerlong").animate({"left" : newLeft},function() {
				banneranimating = false;
			});
			
		
		}
	
	}
	
	someInterval = setInterval(goNext,8000);
		
	}
	
	$(".rollingbanner .leftarrow").click(function() {
		clearInterval(someInterval);
		if (!banneranimating) {
		
			banneranimating=true;
			currentbanner--;
			if (currentbanner==0) {
				currentbanner=bannercount;
			}
		
			var newLeft = (currentbanner-1)*960*-1;
			
			$(".rollingbannerlong").animate({"left" : newLeft},function() {
				banneranimating = false;
			});
		
		}
	});
	$(".rollingbanner .rightarrow").click(function() {
		clearInterval(someInterval);
		if (!banneranimating) {
		
			banneranimating=true;
			currentbanner++;
			if (currentbanner>bannercount) {
				currentbanner=1;
			}
		
			var newLeft = (currentbanner-1)*960*-1;
			
			$(".rollingbannerlong").animate({"left" : newLeft},function() {
				banneranimating = false;
			});
			
		
		}
	});

	$("a.leto-top").click(function() {
	
		$(this).parent().find(".leto-bottom").slideToggle();
	
	});
	
	$(".newsbig img").each(function() {
		
		if ($(this).attr('align')=="right") {
			$(this).css('margin-left',$(this).attr('hspace')+'px');
		}
		
		if ($(this).attr('align')=="left") {
			$(this).css('margin-right',$(this).attr('hspace')+'px');
		}		
	
	});
	
});
