var anim = false;

$(document).ready(function() {

	$('#thumbs').superbgimage().hide();
	$('.content-box-content, .msgbox-middle-content').jScrollPane({
		scrollbarWidth : 7,
		scrollbarMargin : 40,
		showArrows : false,
		arrowSize : 0
	});

	/*$(".google-order").click(function() {
		$("#order-book").animate({
			height : "200px"
		}, 160);
		$("#order-book-close").fadeIn(500);
	});
	$("#order-book-close").click(function() {
		$(this).fadeOut(120);
		$("#order-book").animate({
			height : "27px"
		}, 160);
	});*/
	$('.navigation').hover(function() {
		if(!anim)
			$(this).siblings().stop().fadeTo(250, 0.5);
	}, function() {
		if(!anim)
			$(this).siblings().stop().fadeTo(100, 1);

	});
	$(".mod1").css("height", $(document).height());
	$(".mod-contact").click(function() {
		$(".mod1").fadeIn(200);
		return false;
	});
	$(".modal-close").click(function() {
		$(".mod1").fadeOut(200);
		return false;
	});

	$(window).bind("resize", function() {
		$(".mod2").css("height", $(window).height());
	});
	$(".mod2").css("height", $(document).height());
	$(".mod-disclaimer").click(function() {
		$(".mod2").fadeIn(200);
		return false;
	});
	$(".modal-close").click(function() {
		$(".mod2").fadeOut(200);
		return false;
	});

	$(window).bind("resize", function() {
		$(".mod2").css("height", $(window).height());
	});
	$(".mod3").css("height", $(document).height());
	$(".mod-imprint").click(function() {
		$(".mod3").fadeIn(200);
		return false;
	});
	$(".modal-close").click(function() {
		$(".mod3").fadeOut(200);
		return false;
	});

	$(window).bind("resize", function() {
		$(".mod3").css("height", $(window).height());
	});
	// button clicked
	$('.navigation').click(function() {

		// alle buttons als inaktiv setzen (aufraeumen)
		$('.navigation').removeClass('active');
		$('.navigation').addClass('mini');

		// den geklickten button auf active setzen
		$(this).removeClass('mini');
		$(this).addClass('active');

		showContent();
		return false;
	});
	// content schliessen
	$('.content-box-close').click(function(e) {

		// alle buttons als inaktiv setzen (aufraeumen)
		$('.navigation').removeClass('active');
		$('.navigation').removeClass('mini');

		// inhaltsblock ausblenden
		$(this).parent().parent().each(function() {
			$(this).fadeOut('normal', function() {

				// inneres a-element auch animieren
				$('.navigation').each(function() {
					$(this).find('a:first').fadeIn().animate({
						'height' : '26px',
						'width' : '170px',
						'padding-top' : '26px',
						'padding-right' : '0px',
						'padding-bottom' : '0px',
						'padding-left' : '22px',
						'font-size' : '13px'

					}, 200);
				});
				$(this).css('visibility', 'hidden');

				showContent();
			});
		});

		e.stopPropagation();
		return false;
	});
});
function showContent() {
	anim = true;

	$('body').animate({
		'margin-top' : '0px'
	}, 500, function() {
		anim = false;
		$('.navigation').fadeTo(0, 1);
	});
	// durch alle buttons laufen und passende aktion durchfuehren
	$('.navigation').each(function() {

		// minimiere button
		if($(this).hasClass('mini')) {

			// MINI

			// inaktive navigationsbuttons kleiner machen
			$(this).animate({
				'height' : '32px',
				'width' : '124px',
				'margin-top' : '0px'
			}, 200, 'linear', function() {

				// inhaltsblock ausblenden
				$(this).find('.content-box').each(function() {
					$(this).css('visibility', 'hidden');
					$(this).fadeOut();
				});
			});
			// inneres a-element auch animieren
			$(this).find('a:first').fadeIn().animate({
				'height' : '20px',
				'width' : '114px',
				'padding-top' : '12px',
				'padding-right' : '0px',
				'padding-bottom' : '0px',
				'padding-left' : '10px',
				'font-size' : '10px'
			}, 200);

		} else if($(this).hasClass('active')) {

			// AKTIV

			// inneres a-element ausblende
			$(this).find('a:first').fadeOut(100);

			// aktiven button auf groesse des contents ziehen
			$(this).animate({
				'height' : '464px',
				'width' : '464px',
				'margin-top' : '-20px'
			}, 500, 'linear', function() {

				// inhaltsblock einblenden
				$(this).find('.content-box').each(function() {
					$(this).css('visibility', 'visible');
					$(this).fadeIn('normal');
				});
			});
		} else {

			// NORMAL

			// aktiven button auf groesse des contents ziehen
			$(this).animate({
				'height' : '52px',
				'width' : '192px',
				'margin-top' : '0px'
			}, 200);

		}
	});
}
