// JavaScript Document

$(document).ready(function(){
	
	/* wenn ein supersizedWrapper vorhanden - supersizen... */
	if ($("#supersizedWrapper").length > 0){
		supersize();
	}
	
	/* ******************** Startseite - Mouseover ******************** */	
	if ($("#navigationHome").length > 0){
		naviBalken = $('#naviOverBalken');
		wrapperPos = thisPos = $('#navigationHome').position().top;
		
		$('#navigationHome ul li').mouseover(function(){			
			thisPos = $(this).offset().top;		
			newPos = thisPos ;		
			naviBalken.css('top',newPos);
			naviBalken.show();			
		});
		
		$('#navigationHome ul li').mouseout(function(){			
			naviBalken.hide();			
		});
	}
	
	/* ******************** Blog - Archiv Tree******************** */	
	$('a.blogYear, a.blogMonth').click(function(){
		
		/* Einträge im Blog Archiv Tree ausblenden */
		/* andere monate zuklappen */
		$(this).parent().siblings().children('ul').removeClass('visible');
		/* andere jahre zuklappen */
		$(this).parent().parent().siblings().children('li').children('ul').removeClass('visible');
		
		/* pfeil nach unten.... */
		$(this).parent('li').addClass('active');
		
		/* pfeil wieder gerade bei monaten*/
		$(this).parent().siblings().removeClass('active');
		/* pfeil wieder gerade bei jahren */
		$(this).parent().parent().siblings().children('li').removeClass('active');
		
		/* Einträge im Blog Archiv Tree einblenden */
		$(this).parent().children('ul').addClass('visible');
		
		return false;
		
	});
	
	
	/* ******************** Projektseite - Blättern ******************** */
	
	/* ist es eine Projektseite */
	if ($("div#projektImages").length > 0){
		
		/* Bilder vorladen */
		$('#projektImages table').find('img').batchImageLoad({
			/* wenn alle Bilder geladen, scripts bereitstellen */
			loadingCompleteCallback: function() {
				
				/* wenn alle Bilder geladen sind, Blaetter Buttons anzeigen*/
				$('#blaetterWrapper').removeClass('inactive');
				
				/* variabeln setzten */
				goLeftButton = $('#goLeft');
				goRightButton = $('#goRight');				
				imagesWrapper = $('div#projektImages table');
				imagesWrapperWidth = imagesWrapper.width();					
				bodyWidth = $('body').width();
				moveWidth = bodyWidth * 0.75;				
				lockButtons = 0;
				
				/* funktion "nach links blättern" */
				goLeftButton.click(function(){
					

					/* aktuelle position auslesen */
					imagesWrapperMarginLeft = parseInt(imagesWrapper.css('marginLeft').replace('px',''));	
					/* neue Position berechnen */
					var newMarginLeft = imagesWrapperMarginLeft + moveWidth;
					/* wenn noch nicht wieder am Anfang, und nicht gesperrt (weil die letzte animation noch läuft) -> animieren */
					if(imagesWrapperMarginLeft < 0 && lockButtons == 0) {
						lockButtons = 1;
						imagesWrapper.animate({marginLeft:newMarginLeft},function(){
							/* wenn animation durch ist - wieder freigeben */
							lockButtons = 0;
						});
					}		
					
					return false;
				});
				
				/* funktion "nach rechts blättern" */
				goRightButton.click(function(){
					
					/* aktuelle position auslesen */
					imagesWrapperMarginLeft = parseInt(imagesWrapper.css('marginLeft').replace('px',''));	
					/* neue Position berechnen */
					var newMarginLeft = imagesWrapperMarginLeft + moveWidth * -1;
					
					/* wenn noch nicht am Ende, und nicht gesperrt (weil die letzte animation noch läuft) -> animieren */
					if(imagesWrapperWidth > ((newMarginLeft * -1)) && lockButtons == 0) {
						lockButtons = 1;
						imagesWrapper.animate({marginLeft:newMarginLeft},function(){
							/* wenn animation durch ist - wieder freigeben */
							lockButtons = 0;
						});					
					}	
					return false;
				});
				
				/* navigation mit cursor */
				$(document).keydown(function(e) {
					if (e.keyCode == '37') {
						goLeftButton.trigger('click');
					}
					if (e.keyCode == '39') {
						goRightButton.trigger('click');
					}					   
				});
			
			}
			
		});
		
	}
	
	/* ******************** END Projektseite - Blättern ******************** */
	
	/* ******************** Projektseite - Links auf Bildern ******************** */
	
	$('.projectImageLink').click(function(){
		
		aktMarginLeft = parseInt($('div#projektImages table').css('marginLeft').replace('px',''));	
		
		thisHref = $(this).attr('href');
		
		newHref = thisHref + '&backto=' + aktMarginLeft;
		
		window.location.href = newHref;
		
		return false;

	})
	
	$('#infoBoxShow').click(function(){
		
		var infoBoxStatus = $('#infoBox').is(':visible');
		
		if(!infoBoxStatus)  {
			$('#infoBox').fadeIn();	
			$('#info').addClass('active')
		} else {
			$('#infoBox').fadeOut();	
			$('#info').removeClass('active')
		}
		
									 
	});
		
});


