jQuery.noConflict();
(function($) {
	
		var aktivStartAnim = null;
		var aktivTeaserAnim = null;
		var aktivMagTeaserAnim = null;
		
		
	$(window).load(function(){
		
		/**** Layoutverfeinerung ***********/
		$('* > .col').each(function(){$(this).height($(this).parent().height())});
		$('#main-nav li:last-child').addClass('last');
		
		
		$('.boxcontent a.weiter').each(function(){
			$(this).parent().find('p:last').append($(this));
		});
		
		$('.zebralist .listentry:odd').addClass('odd');
		
		/***** SPEZIAL FUER SHOP-INCLUDE ****/
		$('body.cat_33 #main-nav li#navli2').addClass('active');
		
		
		/**** STARTSEITE *****/
		
		$('.storerbox .closeBtn').click(function(){$(this).parent().parent().hide();});
		
		$('#startshop .boxcontent').height($('#bigteaser .boxcontent').height());
		
		
		for(var i= 0; i < $('#bigteaser .slideshow .items .item').length; i++){
			var teasertitel = $('#bigteaser .slideshow .items .item:eq('+i+') h3').text();
			$('#bigteaser .slidenav ul li:eq('+i+') a').text(teasertitel);
			$('#bigteaser .slidenav ul li:eq('+i+') a').attr('title', teasertitel);
		}
		
		for(var i= 0; i < $('#smallteaser .slideshow .items .item').length; i++){
			var teasertitel = $('#smallteaser .slideshow .items .item:eq('+i+') h3').text();
			$('#smallteaser .slidenav ul li:eq('+i+') a span.hide').text(teasertitel);
			$('#smallteaser .slidenav ul li:eq('+i+') a').attr('title', teasertitel);
		}
		
		$('#bigteaser .slidenav ul a').click(function(){
			var $container = $('#bigteaser .slideshow .items');
			var itemPosi = $container.children('.item').eq($(this).parent().index()).position();
			$container.animate({"left": "-"+itemPosi.left+"px"}, "slow");
			$(this).parent().parent().find('a.active').removeClass('active');
			$(this).addClass('active');
			clearInterval(aktivStartAnim);
			return false;
		});
		
		$('#bigteaser .item.link').click(function(){
			var url = $(this).find('a.weiter').attr('href');
			window.location = url; // redirect

		});
		
		$('#smallteaser .slidenav ul a').click(function(){
			var $container = $('#smallteaser .slideshow .items');
			var itemPosi = $container.children('.item').eq($(this).parent().index()).position();
			$container.animate({"left": "-"+itemPosi.left+"px"}, "slow");
			$(this).parent().parent().find('a.active').removeClass('active');
			$(this).addClass('active');
			clearInterval(aktivTeaserAnim);
			return false;
		});
		
		if($('#bigteaser .slideshow .items .item').length > 1)
			aktivStartAnim = initAutoSlide($('#bigteaser .slideshow .items'), $('#bigteaser .slidenav ul'));
		
		if($('#smallteaser .slideshow .items .item').length > 1)
			aktivTeaserAnim = initAutoSlide($('#smallteaser .slideshow .items'), $('#smallteaser .slidenav ul'));
		
		
		/**** MAGAZIN STARTSEITE *****/
		
		if($('.page_6').children().length > 0){
			var leftTop = $('.page_6 .leftcol.sameheight .boxcontent:first').offset().top;
			var mainTop = $('.page_6 .maincol.sameheight .boxcontent:first').offset().top;
			$('.page_6 .leftcol.sameheight .boxcontent:first').height($('.page_6 .maincol.sameheight .boxcontent:first').height()-(leftTop-mainTop));
		}
		
		$('#slideteaserwrap .slidenav').width($('#slideteaserwrap .slidenav .dotnav').children().length * 14);
		
		$('#slideteaserwrap .slidenav ul a').click(function(){
			var $container = $('#slideteaserwrap .slideshow .items');
			var itemPosi = $container.children('.item').eq($(this).parent().index()).position();
			$container.animate({"left": "-"+itemPosi.left+"px"}, "slow");
			$(this).parent().parent().find('a.active').removeClass('active');
			$(this).addClass('active');
			clearInterval(aktivMagTeaserAnim);
			return false;
		});
		
		if($('#slideteaserwrap .slideshow .items .item').length > 1)
			aktivMagTeaserAnim = initAutoSlide($('#slideteaserwrap .slideshow .items'), $('#slideteaserwrap .slidenav ul'));
		
		
		
		/**** IMG SELECTOR ******/
		
		$('.slidegalerieplussbc .slideshow .head').click(function(){
			//Weill Header aus Layoutgruenden über Bild liegt, muss Event weitergereicht werden
			$(this).parent().find('.items .item.active a.colorboxbtn').trigger('click');
		});
		
		$('.slidegalerieplussbc .slidenav ul a').click(function(){
			var $container = $('.slidegalerieplussbc .slideshow .items');
			var $activeItem = $container.children('.item').eq($(this).parent().index());
			var itemPosi = $activeItem.position();
			$container.animate({"left": "-"+itemPosi.left+"px"}, "slow");
			$(this).parent().parent().find('a.active').removeClass('active');
			$(this).addClass('active');
			
			$container.children('.item.active').removeClass('active');
			$activeItem.addClass('active');
			
			$('.slidegalerieplussbc .scdboxcontent .changecontent').empty();
			$activeItem.find('a.download').clone().appendTo('.slidegalerieplussbc .scdboxcontent .changecontent');
			
			return false;
		});
		
		
		
		/**** GALERIE Definitionen ******/
		$('.slidegalerie .slideshow .items .item:first').addClass('active');
		setSlideImgInfo($('.slidegalerie .slideshow + .scdboxcontent.imginfo'), $('.slidegalerie .slideshow .items .item.active'));
		
		$('.slidegalerie .slideshow .slidenav .prev').click(function(){
			var $pressedBtn = $(this);
			$(this).parent().parent().find('.items').animate({left:'+=620px'}, 500, function(){
				var $newActive = $(this).find('.item.active').prev();
				$(this).find('.item.active').removeClass('active');
				$newActive.addClass('active');
				
				if($(this).find('.item.active').is(':first-child')){
					$pressedBtn.hide();
				} else {
					if($pressedBtn.parent().find('.next').is(':hidden'))
						$pressedBtn.parent().find('.next').show();
				}
				
				setSlideImgInfo($(this).parent().next('.scdboxcontent.imginfo'), $(this).find('.item.active'));
			});
			return false;
		});
		
		$('.slidegalerie .slideshow .slidenav .next').click(function(){
			var $pressedBtn = $(this);
			$(this).parent().parent().find('.items').animate({left:'-=620px'}, 500, function(){
				var $newActive = $(this).find('.item.active').next();
				$(this).find('.item.active').removeClass('active');
				$newActive.addClass('active');
				
				if($(this).find('.item.active').is(':last-child')){
					$pressedBtn.hide();
				} else {
					if($pressedBtn.parent().find('.prev').is(':hidden'))
						$pressedBtn.parent().find('.prev').show();
				}
				
				setSlideImgInfo($(this).parent().next('.scdboxcontent.imginfo'), $(this).find('.item.active'));
			});
			return false;
		});
		
		/** LISTENDEFINITIONEN **/
		
		$( ".accordion").accordion({
			header: '.acchead',
			active: false,
			collapsible: true,
			autoHeight: false,
			clearStyle: true,
			icons: false
			});
		
		$('.listitem .slidebtn').click(function(){
			$(this).parent().find('.slidecontent').slideToggle();
			$(this).toggleClass('active');
		});
		
		
	});

	/*** GALERIE Funktion ******/
	function setSlideImgInfo(imgInfoObj, itemObj){
		var $imgInfoObj = imgInfoObj;
		var $itemObj = itemObj;
		
		$imgInfoObj.find('.col.col355').html($itemObj.find('.infos .description').html());
		$imgInfoObj.find('.right').html($itemObj.find('.infos .service').html());
	}
	
	/**** AUTOSLIDE UNIVERSAL ***/
	function initAutoSlide(obj, navobj){
		var $itemObj = $(obj);
		var $navObj = $(navobj);
		var stepSize = $itemObj.children('.item:first').width();
		var stepCount = $itemObj.children('.item').length;
		$itemObj.children('.item:first').clone().appendTo($itemObj);
		var slide = setInterval(function(){
				$itemObj.animate({"left": "-="+stepSize+"px"}, "slow", function(){
					var $oldActive = $navObj.find('.active');
					$oldActive.removeClass('active');
					
					if(stepCount == 1){
						$itemObj.css("left", "0px");
						$navObj.find('li:first a').addClass('active');
						stepCount = $itemObj.children('.item').length - 1;
					} else {
						$oldActive.parent().next().children('a').addClass('active');
						stepCount--;
					}
				});
				
				//clearInterval(slide);
			}, 8000);
		return slide;
	}
	
})(jQuery);



