$(document).ready(function() {
	
	$("a.single_image").fancybox();
	
	$("a#inline").fancybox({
		'hideOnContentClick': true
	});
	
	$("a.group").fancybox({
		'hideOnContentClick': true,
		'padding'			: 0,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'              : 'image',
			'changeFade'        : 'fast'
	});
	
	$("#gallery").click(function() {
		$.fancybox([
			'images/galerie/historie/bild1.jpg',
			'images/galerie/historie/bild2.jpg',
			'images/galerie/historie/bild3.jpg',
			'images/galerie/historie/bild4.jpg',
			'images/galerie/historie/bild5.jpg',
			'images/galerie/historie/bild6.jpg',
			'images/galerie/historie/bild7.jpg',
		], {
			'padding'			: 0,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'              : 'image',
			'changeFade'        : 'fast'
		});
	});
	
	$("#gallery_logistikpark").click(function() {
		$.fancybox([
			'images/galerie/logistikpark/bild1.jpg',
			'images/galerie/logistikpark/bild6.jpg',
			'images/galerie/logistikpark/bild10.jpg',
			'images/galerie/logistikpark/bild11.jpg',
			'images/galerie/logistikpark/bild14.jpg',
			'images/galerie/logistikpark/bild16.jpg',
			'images/galerie/logistikpark/bild17.jpg',
			'images/galerie/logistikpark/bild22.jpg',
			'images/galerie/logistikpark/bild25.jpg',
			'images/galerie/logistikpark/bild26.jpg',
			'images/galerie/logistikpark/bild31.jpg',
			'images/galerie/logistikpark/bild32.jpg',
			'images/galerie/logistikpark/bild33.jpg',
		], {
			'padding'			: 0,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'              : 'image',
			'changeFade'        : 'fast'
		});
	});
	
	$("#gallery_sudhaus").click(function() {
		$.fancybox([
			'images/galerie/sudhaus/bild1.jpg',
			'images/galerie/sudhaus/bild2.jpg',
			'images/galerie/sudhaus/bild3.jpg',
			'images/galerie/sudhaus/bild4.jpg',
			'images/galerie/sudhaus/bild5.jpg',
			'images/galerie/sudhaus/bild6.jpg',
			'images/galerie/sudhaus/bild7.jpg'
		], {
			'padding'			: 0,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'              : 'image',
			'changeFade'        : 'fast'
		});
	});
	
	  var currentPosition = 0;
	  var slideWidth = 430;
	  var slides = $('.slide');
	  var numberOfSlides = slides.length;
	
	  // Remove scrollbar in JS
	  $('#slidesContainer').css('overflow', 'hidden');
	
	  // Wrap all .slides with #slideInner div
	  slides
		.wrapAll('<div id="slideInner"></div>')
		// Float left to display horizontally, readjust .slides width
		.css({
		  'float' : 'left',
		  'width' : slideWidth
		});
	
	  // Set #slideInner width equal to total width of all slides
	  $('#slideInner').css('width', slideWidth * numberOfSlides);
	
	  // Insert controls in the DOM
	  $('#slideshow')
		.prepend('<span class="control" id="leftControl">Clicking moves left</span>')
		.append('<span class="control" id="rightControl">Clicking moves right</span>');
	
	  // Hide left arrow control on first load
	  manageControls(currentPosition);
	
	  // Create event listeners for .controls clicks
	  $('.control')
		.bind('click', function(){
		// Determine new position
		currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;
		
		// Hide / show controls
		manageControls(currentPosition);
		// Move slideInner using margin-left
		$('#slideInner').animate({
		  'marginLeft' : slideWidth*(-currentPosition)
		});
	  });
	
	  // manageControls: Hides and Shows controls depending on currentPosition
	  function manageControls(position){
		// Hide left arrow if position is first slide
		if(position==0){ $('#leftControl').hide() } else{ $('#leftControl').show() }
		// Hide right arrow if position is last slide
		if(position==numberOfSlides-1){ $('#rightControl').hide() } else{ $('#rightControl').show() }
	  }
	  
});

	
	var allSubs = ['sub1', 'sub2', 'sub3', 'sub4', 'sub5', 'sub6'];
	var allTabs = ['tab1', 'tab2', 'tab3', 'tab4', 'tab5', 'tab6'];

	function setDisplay(submenue, display) {
		document.getElementById(submenue).style.display = display;
	}
	
	function hideAll(defaultTab) {
		subCount = allSubs.length;
		for (i = 0; i < subCount; i++) {
			if (defaultTab === true) {
				if (document.getElementById(allTabs[i]+'over')) {
					document.getElementById(allSubs[i]).style.display = 'block';
				} else {
					document.getElementById(allSubs[i]).style.display = 'none';
				}
			} else {
				document.getElementById(allSubs[i]).style.display = 'none';
			}
		}	
	}
	
	
	// MIETER-KARTE
	
	var lastID;
	
	$('area.mieterplan').hover(function() {
		
		var id = $(this).attr('id');
		$('#karte_mieter').attr('src', 'images/lageplan/'+id+'.png');
		
		$(this).click(function() {
			
			$('area.mieterplan').removeClass('selected');
			$(this).addClass('selected');
			
			if (lastID != id) {
				$.ajax({
					url    : "./includes/area.php",
					type   : 'post',
					data   : ({
						area : id
					}),
					success: function(msg){                                    
						$("#textinhalt").html(msg);
					}
				});
			}
			
			lastID = id;
				 
		});
		
	}, function() {
		
		if ($('area[class="mieterplan selected"]').length) {
			$('#karte_mieter').attr('src', 'images/lageplan/'+$('area[class="mieterplan selected"]').attr('id')+'.png');
		} else {
			$('#karte_mieter').attr('src', 'images/lageplan/area_x.png');
		}
		
	});
	
	

