
(function($){
	$('html').removeClass('no-js');
	
	$('.to-top').click(function(e) {
		e.preventDefault();
		$('#container').animate({scrollTop: 0}, 1200 , function (){});
	});
	
	
	$('#Previous').click( function(e) {
		e.preventDefault();
		var prev = $('#Slider .active_0').prev('section');
		if ( undefined == prev.get(0) ) {
			prev = $('#Slider section').last();
		}

		$('#Slider .active_2').animate({left: '2000px'}, 800, function() {
			$(this).removeClass('active_2').css('left','-2000px');
		});
		$('#Slider .active_1').animate({left:'1000px',opacity:'0.4'},800, function() {
			$('.active_1 > img').css('display','none');
			$(this).removeClass('active_1').addClass('active_2');
		});
		$('#Slider .active_0').animate({left:'0px',opacity:'1'},800, function() {
			$(this).removeClass('active_0').addClass('active_1');
			$('.active_1 > img').slideToggle(300);
			prev.animate({left:'-1000px'},1, function() {
				prev.addClass('active_0');
			});
		});
	});

	$('#Next').click( function(e) {
		e.preventDefault();
		var next = $('#Slider .active_2').next('section');
		if ( undefined == next.get(0) ) {
			next = $('#Slider section').first();
		}
		//next.css('left','2000px');

		$('#Slider .active_0').animate({left:'-2000px',opacity:'0.4'},800, function() {
			$(this).removeClass('active_0');
		});
		$('#Slider .active_1').animate({left:'-1000px',opacity:'0.4'},800, function() {
			$('.active_1 > img').css('display','none');
			$(this).removeClass('active_1').addClass('active_0');
		});
		$('#Slider .active_2').animate({left: '0px',opacity:'1'}, 800, function() {
			$(this).removeClass('active_2').addClass('active_1');
			$('.active_1 > img').slideToggle(300);
			next.animate({left:'1000px'},1, function() {
				next.addClass('active_2');
			});
		});
	});
	
	
	var maxHeight = 0;
	if ( $('#Newsslider > div').length > 0 ) {
		$('#Newsslider > div:not(.inactive)').each( function() {
			if ( $(this).height() > maxHeight ) {
				maxHeight = $(this).height();
			}
		});
		$('#Newsslider, .salons .content').animate({height: (maxHeight + 20)+'px'}, 500);
	}

	$('.months li.year').click( function() {
		$(this).siblings().removeClass('active');
		$(this).addClass('active');
		var title = '".'+$(this).attr('title')+':first"';
		var position = $(title).position();
		$('#Newsslider').animate({left:'-'+position.left+'px'},1000,function(){
			$('#Newsslider > div').css('opacity','0.5').addClass('inactive');
			$(title).css('opacity','1').removeClass('inactive');
			$(title).next().css('opacity','1').removeClass('inactive');
			$(title).next().next().css('opacity','1').removeClass('inactive');
			$(title).next().next().next().css('opacity','1').removeClass('inactive');
			var maxHeight = $(title).height();
			$(title).siblings(':not(.inactive)').each( function() {
				if ( $(this).height() > maxHeight ) {
					maxHeight = $(this).height();
				}
			});
			$('#Newsslider, .salons .content').animate({height: (maxHeight + 20)+'px'}, 500);
		});
		
		
	});
	$('#Nextnews').click(function() {
		$('.months li.active').next().click();
	});
	$('#Previousnews').click(function() {
		$('.months li.active').prev().click();
	});
	$('#Previousday').click(function() {
		var current = $('#Newsslider > div:not(.inactive):first');
		var prev = current.prev();
		var classes = prev.attr('class').split(' ');
		var pos = prev.position()
		$('#Newsslider').animate({left:'-'+pos.left+'px'},200,function(){
			$('#Newsslider > div').css('opacity','0.5').addClass('inactive');
			prev.css('opacity','1').removeClass('inactive');
			prev.next().css('opacity','1').removeClass('inactive');
			prev.next().next().css('opacity','1').removeClass('inactive');
			prev.next().next().next().css('opacity','1').removeClass('inactive');

			var maxHeight = $(current).height();
			$(current).siblings(':not(.inactive)').each( function() {
				if ( $(this).height() > maxHeight ) {
					maxHeight = $(this).height();
				}
			});
			$('#Newsslider, .salons .content').animate({height: (maxHeight + 20)+'px'}, 500);
		});
		
		if($('.months li.active').attr('title') != classes[2]) {
			var act = $('.months li.active');
			act.removeClass('active');
			act.prev().addClass('active');
		}
	});
	$('#Nextday').click(function() {
		var current = $('#Newsslider > div:not(.inactive):first');
		var next = current.next();
		var classes = next.attr('class').split(' ');
		var pos = next.position()
		$('#Newsslider').animate({left:'-'+pos.left+'px'},200,function(){
			$('#Newsslider > div').css('opacity','0.5').addClass('inactive');
			next.css('opacity','1').removeClass('inactive');
			next.next().css('opacity','1').removeClass('inactive');
			next.next().next().css('opacity','1').removeClass('inactive');
			next.next().next().next().css('opacity','1').removeClass('inactive');

			var maxHeight = $(current).height();
			$(current).siblings(':not(.inactive)').each( function() {
				if ( $(this).height() > maxHeight ) {
					maxHeight = $(this).height();
				}
			});
			$('#Newsslider, .salons .content').animate({height: (maxHeight + 20)+'px'}, 500);
		});
		if($('.months li.active').attr('title') != classes[2]) {
			var act = $('.months li.active');
			act.removeClass('active');
			act.next().addClass('active');
		}
	});



	var $Overlay = '<div id="Overlay" style="position:absolute;top:0;left:0;right:0;bottom:0;background:#333;opacity:0.85;z-index:100;"></div>';
	var $OverlayBeauty = '<div id="Overlay2" style="position:absolute;top:100px;left:50%;margin-left:-340px;width:680px;z-index:100;vertical-align:top;"><img src="img/karte-beauty-gross.jpg" style="vertical-align:top;" />&nbsp;<a class="close" href="" style="vertical-align:top;"><img src="img/close.jpg" /></a></div>';
	var $OverlayLifestyle = '<div id="Overlay2" style="position:absolute;top:100px;left:50%;margin-left:-340px;width:680px;z-index:100;vertical-align:top;"><img src="img/karte-lifestyle-gross.jpg" style="vertical-align:top;" />&nbsp;<a class="close" href="" style="vertical-align:top;"><img src="img/close.jpg" /></a></div>';
	var $OverlayFamily = '<div id="Overlay2" style="position:absolute;top:100px;left:50%;margin-left:-340px;width:680px;z-index:100;vertical-align:top;"><img src="img/karte-family-gross.jpg" style="vertical-align:top;" />&nbsp;<a class="close" href="" style="vertical-align:top;"><img src="img/close.jpg" /></a></div>';
	
	$('.karte-beauty').click(function(e) {
		e.preventDefault();
		$('body').append($Overlay);
		$('body').append($OverlayBeauty);
	});
	$('.karte-lifestyle').click(function(e) {
		e.preventDefault();
		$('body').append($Overlay);
		$('body').append($OverlayLifestyle);
	});
	$('.karte-family').click(function(e) {
		e.preventDefault();
		$('body').append($Overlay);
		$('body').append($OverlayFamily);
	});
	$('.close').live('click', function(e) {
		e.preventDefault();
		$('#Overlay').remove();
		$('#Overlay2').remove();
	});
	$('#Overlay').live('click', function(e) {
		e.preventDefault();
		$('#Overlay').remove();
		$('#Overlay2').remove();
	});
})(window.jQuery);


// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  if(this.console) {
    arguments.callee = arguments.callee.caller;
    var newarr = [].slice.call(arguments);
    (typeof console.log === 'object' ? log.apply.call(console.log, console, newarr) : console.log.apply(console, newarr));
  }
};

// make it safe to use console.log always
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,timeStamp,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try
{console.log();return window.console;}catch(err){return window.console={};}})());


// place any jQuery/helper plugins in here, instead of separate, slower script files.


