$(document).ready(function(){
	
	$(".cb_artikel_liste_home:even").each(function(){
		var headline_left = $(this).children(".cb_artikel_liste_headline");
		var headline_right = $(this).next(".cb_artikel_liste_home").children(".cb_artikel_liste_headline");
		if(!headline_right.height())return;
		if(headline_left.height() > headline_right.height()){
			headline_right.children("h1").html("<br />"+headline_right.children("h1").html()); 
		} else if(headline_left.height() > headline_right.height()){
			headline_left.children("h1").html("<br />"+headline_left.children("h1").html()); 
		}
	});

 $(".teaseritem").mouseenter(function(){
		$(this).delay(50).stop(true).animate({width:400},500, function(){
			$(this).children(".teasertyp1").animate({top:0},250);
			if($.browser.msie && $.browser.version < 9){
				$(this).children(".teasertext_bg").fadeTo(500,.60);
			}
			$(this).children(".teasertext").fadeTo(500,1);
		});
 		$(this).siblings().delay(250).stop(true).animate({width:89},500).children(".teasertext").fadeTo(500,0)
 		$(this).siblings().children(".teasertext_bg").fadeTo(500,0);
 		
 		$(this).siblings().children(".teasertyp1").animate({top:-30},250);
 		if($.browser.msie){
 			$(this).children(".teasertyp2").animate({left:-33},350);
 			$(this).siblings().children(".teasertyp2").animate({top:-20,left:-1},250);
 		} else {
 			$(this).children(".teasertyp2").animate({left:-145},250);
 			$(this).siblings().children(".teasertyp2").animate({top:95,left:-115},250);
 		}
	});
	
 $(".teaseritem").click(function(){
 		$(this).blur();
		if($(this).width() < 400)return false;
	});
	
	
 $(".teaseritem:last").mouseenter();

 $("#teaser_content").show(300);	
 

	$("#carousel").focus(function(){
		if($(this).data("hover") == false){
			//$("#carousel").roundabout_animateToNextChild();
		} else {
			//if($(this).data("direction")=="left")$("#carousel").roundabout_animateToPreviousChild($(this).data("speed"));
			//else $("#carousel").roundabout_animateToNextChild($(this).data("speed"));
		}
	}); 
	
	$("#carousel li").hover(function(){	
		if($(this).attr("current-scale") > 1.9 )$(this).find("img").stop(true).animate({height: "230px"},200); 
	},function(){
		$(this).find("img").stop(true).animate({height:"100%"},200); 
	});
	
	
	$("#carousel").mousemove(function(e){
		carouselE = e;
		if(carouselIntervalHover > 0)clearInterval(carouselIntervalHover);
		carouselIntervalHover = setInterval("hoverCarousel()",5);	
	});
	
	$("#carousel").hover(function(){
		$(this).data("hover",true);
	},function(){
		clearInterval(carouselIntervalHover);
		$(this).data("hover",false);
		//$(this).roundabout_animateToNextChild();
	});
		
	

 
 $("#carousel").roundabout({
 		tilt:-3,
 		minScale:.5,
 		maxScale:2,
		duration:3000,
		easing:"linear",
		clickToFocus:false
	});
		if(carouselInterval > 0)clearInterval(carouselInterval);
		carouselInterval = setInterval("moveCarousel()",40);	
});

var carouselInterval = 0;
var carouselIntervalHover = 0;
var carouselSpeed = .3;
var carouselDirection = 1;
var carouselE;
var carouselobj;

function hoverCarousel(){
		carouselSpeed = (carouselE.pageX - $("#carousel").offset().left - ($("#carousel").width() / 2)) / 10;
		if(carouselSpeed > 0)carouselDirection = -1;
		else carouselDirection=1;
		carouselSpeed = 50-Math.abs(carouselSpeed);
		if(carouselSpeed > 45)carouselDirection = 0;
		carouselSpeed = 50-carouselSpeed;
		carouselSpeed /= 20 ;
		if(carouselSpeed < .4)carouselSpeed = .4;
		if(carouselSpeed > 1.1)carouselSpeed = 1.1;
		carouselSpeed *= carouselDirection;
}

function moveCarousel(){
	  $("#carousel").roundabout_adjustBearing(carouselSpeed);
}


